Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Multiple I2c Teensy 3.5

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    2

    Multiple I2c Teensy 3.5

    Can anyone share with me about using scl2 sda2 using? I cannot use this bus to read data from sensors

  2. #2
    Junior Member
    Join Date
    May 2019
    Posts
    1
    I have same problem. Please help us !!

  3. #3
    Junior Member
    Join Date
    May 2017
    Posts
    16
    If I understand correctly, you want read sensors connected to pins 37 (SCL1) & 38 (SDA1)?

    All you need to do is replace instances of "Wire" with "Wire1": (sample code shamelessly stolen from examples)

    Code:
    #include <Wire.h>
    
    void setup()
    {
      Wire1.begin();
    }
    
    byte val = 0;
    
    void loop()
    {
      Wire1.beginTransmission(44); // transmit to device #44 (0x2c)
                                  // device address is specified in datasheet
      Wire1.write(byte(0x00));            // sends instruction byte  
      Wire1.write(val);             // sends potentiometer value byte  
      Wire1.endTransmission();     // stop transmitting
    
      val++;        // increment value
      if(val == 64) // if reached 64th position (max)
      {
        val = 0;    // start over from lowest value
      }
      delay(500);
    }
    Marc

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Yes, exactly, just replace every "Wire" with "Wire1".

    But if you're using a library which as "Wire" written deep inside its code, you would need to replace every "Wire" with "Wire1" inside that lib's code too.

  5. #5
    Junior Member
    Join Date
    May 2019
    Posts
    2
    I want to use scl2/sda2(3-4) and scl0 sda0 at the same time. i have a lot of sensors on board. Some of them are connected to scl0 sda0 . the others are connected to scl2 sda2. i cannot read data from scl2/sda2 but i can read from scl0/sda0. i also should read from scl2 sda2 to.
    Last edited by mhmd.altnts; 05-17-2019 at 04:28 PM.

  6. #6
    Member
    Join Date
    Mar 2014
    Location
    New Ulm, Mn
    Posts
    29
    When a hardware specific library calls the Wire library from within you might find it useful to make a copy of the library, renaming it.

    This creates a little extra work, made easier with a program like notepad++ where you may use a "find and replace" tool to sniff out references to the library and references to "Wire". Change them all - the references to Wire, and the references to the specific library everywhere they exist, even in file names.

    You can then use them side by side in the same project.

    This applies to SPI bus devices as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •