Two arduinos and a sensor connected with i2c

hello everyone!

ato working with an Arduino Mega2560 rev3 board and an Arduino Uno WiFi rev2 board.

The two boards need to exchange data via I2C (chosen for design reasons). An MPU6050 sensor is connected to the Mega board.
This sensor connects to the Mega board via I2C.

My problem is that I cannot manage the two I2C connections at the same time, i.e. only one at a time works: either I read the data from the MPU6050 or I manage the data exchange between the two boards.

Is there a way to manage the same I2C bus in a shared manner? If so, can you give me directions for the physical connection of the hardware?

Many thanks in advance to everyone.
marco.

The Arduino Uno WiFi Rev2 has a ATmega4809 microcontroller. I assume it can be a I2C Slave. The Mega can be a I2C Slave.

Both Arduino boards are 5V boards (with a 5V I2C bus), but the MPU-6050 is a 3.3V sensor (with a 3.3V I2C bus). The Mega board has 10k pullup resistors to 5V for SDA and SCL.
Your MPU-6050 might be fake, and the module might be designed in the wrong way.

If you want to continue, then assign one board that is always the Master. The other Arduino board should be in Slave mode all the time. Use a I2C level shifter for the MPU-6050. The I2C bus can not be long. Don't put SDA next to SCL. Connect all the GNDs. The I2C bus has three wires: SDA, SCL and GND, and the most important is the GND.

Can you tell what your project is ?
Can you do your project with a single Arduino board ?
Can you buy new things ? For example a modern 3.3V board with a genuine sensor.

1 Like

Since I2C is a rather problematic choice for MCU-MCU communications, can you explain the design reasons?

That requires what is known as a "multi master bus". Basically it is software. However, it is problematic to implement requiring, looking before you send anything, and backing off for a random time if you find the bus is busy. And then clashing detection to cope with when the other device(s) start in the short time between looking and starting.

Ever multi master bus I have been forced to work on, especially those implemented on an FPGA haves been problematic. You are much better off using simple serial to communicate between two devices.

The operation that you are doing is "sequential operation". This kind of operation should be alright if your data acquisition/presnetation is not time constraint.

If you want "concurrent execution (not true parallelism)", you may avail the ESP32 architecture that supports the said operation with the help of FreeRTOS.

With multiple hardware serial ports available on both boards, I would think that serial would be a better choice than i2c for inter board communications.

Can you explain more about your design choice?

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