2 devices using i2c in mega2560

Hi all

Can someone propose to study a sketch using i2c with 2 devices(with different address). I tried to do tricks like in pic microcontrollers but no result. I can easy make the one device work but i don't know how you call each device separately.

Thanks

I think this is a regular Arduino, but the 'address' field is needed.

This like has code that might work on your hardware, it's simple and clear. You could read all the i2c devices on the bus.

How do you know they have different addresses?

https://create.arduino.cc/projecthub/abdularbi17/how-to-scan-i2c-address-in-arduino-eaadda

Good luck

:smiley_cat:

It is an rtc and a bmp280. Thanks for the link i will check

1 Like

I was not clear i think in my question sory about that. What i want to know is how you call device one to extract data and then how to call device 2 to extract data. For example in pic micro there is a write function like i2c_Write(address1) and then you read what you want and you close the i2c like i2c_Stop. After you go to second device liike i2c_Write(address2) and ends like i2c_stop. You put that in a loop(); and you read the devices. I am looking how you doing it in arduino coding.

thanks

Documentation is here:

Use a library for both and let the library deal with the I2C bus.
I hope there is a I2C level shifter between the Arduino Mega and the BMP280.

why BMP needs shifter? It is bmp280 modul @3.3v. Am i right?

Thanks

The Arduino Mega has 10k pullup resistors on the board for SDA and SCL to 5V. So there can leak current from the 5V via the 10k resistor into the SDA and SCL pin of the BMP280.
The ATmega microcontrollers need 3.5V at SDA and SCL to see it as a high level.

Can you give a link to your BMP280 module ? (a link to where you bought it).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.