-2

Good afternoon; I am a bit new to the world of I2C bus. I'm trying to implement a project that have Arduino MEGA as a master and Arduino nano as slave. I have some I2C sensors that i want the slave (Arduino nano) to read. Please how can i implement this.

  • Am I understanding correctly, that your I2C slave Nano should also be a master for the I2C sensors? – chrisl Jul 25 at 6:49
  • 1
    A uC having only one hardware i2c interface can only be master OR slave, not both at the same time. – Sim Son Jul 25 at 7:56
  • Thank you for your response, I understand now. I'm thinking the best approach will be to use other pins of the Arduino Nano to interface the I2C sensors. But because these sensors are I2C sensors, i believe they will not just work directly with other pins except the dedicated I2C pins. Do you know how i can enable other pins of the Arduino Nano to be used for the I2C sensors? – Gbouna Jul 26 at 8:57
0

An Arduino can be both a master and a slave. Nick Gammon's page on I2C describes how to do it. http://www.gammon.com.au/i2c

Communicating with other devices

So all this I2C stuff is great, you can use just two wires (plus ground) to talk to up to 119 devices. But what if you have a device (like a keypad) that doesn't support I2C? Well, the simple answer is that you can use something that does as an interface. For example, a second Arduino. My examples above do just that, using one as the master and second one to display text on LEDs.

In fact, the "master" can also act as a slave, since you can have multiple masters on one wire. The example below shows how you can send data from one Arduino to another, whilst waiting for information to be sent from the second back to the first.

See the link for code examples.

  • Does the Wire now support bus arbitration, so that multi master can be done without locking the bus? – chrisl Jul 25 at 13:23
  • No idea, I've rarely used I2C, preferring instead the much faster SPI. – CrossRoads Jul 25 at 14:04
  • Thank you for your response, I have seen what he did and it was great. However because my sensors are I2C sensors, it may not work well as he did. I'm thinking the best approach will be to use other pins of the Arduino Nano to interface the I2C sensors. But because these sensors are I2C sensors, i believe they will not just work directly with other pins except the dedicated I2C pins. Do you know how i can enable other pins of the Arduino Nano to be used for the I2C sensors? – Gbouna Jul 26 at 9:00
  • What are your sensors? Part numbers? – CrossRoads Jul 26 at 11:45
  • Proximity sensor, VCNL4040, Time of Flight Sensor VL6180 – Gbouna Jul 29 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.