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

Thread: How to use the other i2c ports on Teensy 4.0?

  1. #1

    How to use the other i2c ports on Teensy 4.0?

    Hi PJRC forums,

    I have two i2c devices hooked up to i2c-0 and i2c-1 on a Teensy 4.0.

    I can talk to the i2c-0 device just fine using Wire because they are the default pins. However, I do not know the most efficient way to talk to a second i2c device that is connected to i2c-1.

    I would like to avoid rewiring anything if at all possible.

    Should I be modifying the Wire library or using some other method?

    Any advice to assist would be welcomed. Thank you.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,504
    As connected Wire uses the pins 18,19
    Use Wire1 for pins 17,16 and SDA1, SCL1

    Missing details on the " two i2c devices"? Are they two of the same - or two different devices with different driver libraries in use?

    Some libraries allow specifying Wire or Wire1 in the .begin() - some it is hard coded in the library and would need to be modified perhaps as simple as: #define Wire Wire1 in the code - but that wouldn't work if both use the same library.

  3. #3
    Quote Originally Posted by defragster View Post
    As connected Wire uses the pins 18,19
    Use Wire1 for pins 17,16 and SDA1, SCL1

    Missing details on the " two i2c devices"? Are they two of the same - or two different devices with different driver libraries in use?

    Some libraries allow specifying Wire or Wire1 in the .begin() - some it is hard coded in the library and would need to be modified perhaps as simple as: #define Wire Wire1 in the code - but that wouldn't work if both use the same library.
    Oh right! One is a 128x64 OLED and the other is an MPU6050 IMU. So they use different libraries.

    So it's as simple as including Wire1.h?

  4. #4
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    949
    You could use them both on the same I2C bus.

  5. #5
    Quote Originally Posted by BriComp View Post
    You could use them both on the same I2C bus.
    Changing it to Wire1 works perfectly. For anyone else using an OLED, you can also use the u8g2 library which allows you to choose the pins.

Posting Permissions

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