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.
This answer is completely wrong for the Arduino Mega2560 R3. There are 2 separate I2C busses on this board. They do not connect each other. The pins are clearly labeled SDA1 & SCL1 for the 2nd I2C bus (Wire1) on the board. The SDA & SCL on the other bus are on pins 20 & 21.
and note that the highlighted 2-wire Serial Interface does not state that there are multiple instances of it. Further perusal of the data sheet confirms that there is indeed a single 2-wire interface.
The diagram may show that. However Release 3 of the Mega2560 clearly labels the pins as SCL1 and SDA1. I agree the features list does not state there are 2 busses.
I will concede to that. I stand corrected. However, it doesn't explain why no I2C device is recognized when plugged into SDA1 and SCL1 pins but they work fine when plugged into pins 19 & 20 on the device
All of the above is taken directly from Arduino's official documentation of the Mega 2560 R3. There is no mention of any SDA1/SCL1 in the official documentation for the Mega 2560 R3. None. You are welcome to check out the links yourself if you believe I am making it up.
The Arduino Mega 2560 R3 has one I2C port, not two. I'm done here. QED