Using SDA1/SCL1 on Arduino Mega

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

It is possible to use a software implementation of the I2C bus. Then any pin can be used for a software I2C bus. Here are 30 software I2C buses: https://wokwi.com/projects/307886580731740737?dark=1

1 Like

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.

You can try the wire1 library instead.

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.

@mcriasia

Please look at the schematic and at the ATmega2560 datasheet.

Please provide the proof.

That turns out not to be the case. Observe:

Note please that SCL and SDA appear in two places. Not SCL/SDA and SCL1/SDA1. And the pin numbers (and names) are the same in both places.

And if we turn to the datasheet for the ATmega2560, we find the following

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.

1 Like

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.

On the R3 published PCB files, the two SCLs are connected together and the two SDAs are connected together. So one I2C bus.

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

Sigh.

Observe the tech specs directly from Arduino's Mega 2560 R3 page:

One I2C peripheral.

Observe the Mega 2560 R3 pinout from the official documentation page referenced above:

SDA/SCL in two places. No SDA1/SCL1.

And finally, the Mega 2560 R3 schematic from the official documentation page referenced above, with the 2 instances of SDA/SCL highlighted:

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

1 Like