I am using an Arduino Mega 2560 for a project involving multiple I2C devices. My project involves a custom PCB which attaches to the Arduino and provides multiple I2C ports from the SDA1/SCL1 pins. The custom board has pullup resistors because the Mega doesn't provide them for those pins. I am having an issue with software libraries (Wire.h) for I2C since they all assume SDA (20) and SCL (21). For context, I am working with the I2C Scanner provided in the Arduino examples and the Adafruit_VL53L0X library example.
I have seen this solution which involves rewriting the Wire.h library and twi.c files which is not a maintainable solution for my project. Does anyone have any suggestions for working with SDA1 and SCL1 pins on the Arduino Mega?
The ATmega2560 has only one I2C bus, just one.
The pins for the I2C bus are fixed. They are the Arduino pins 20 and 21.
There is nothing else.
Can you tell more about the I2C devices ? Do they share I2C addresses ?
When a I2C sensor can not alter its I2C address and multiple of those sensors are used, then the common solution is a I2C multiplexer: https://www.adafruit.com/product/2717
Thanks for your reply. Please take a look at the diagram of the Mega 2650 R3 below that shows two sets of SDA/SCL pins. On the physical mega, this second set on the top is labeled SDA1/SCL1.
I am having trouble getting even one I2C device working on this second set of pins (SDA1/SCL1). The device works fine on the 20/21 I2C pins, but because of the constraints I listed I want to get SDA1/SCL1 to work.
If you look at the pin labels you will see that they are the same pins. The ones at the top are the same on the UNO, which uses different actual pins. This gives a consistent location for the signals even tho the actual pins are different on the two processors.