I2C - Slave Receive Data from Arduino UNO
There are two roles in the operation of I2C, one is “master”, the other is “slave”. Only one master is allowed and can be connected to many slaves. Each slave has its unique address, which is used in the communication between master and the slave. I2C uses two pins, one is for data transmission (SDA), the other is for the clock (SCL). Master uses the SCL to inform slave of the upcoming data transmission, and the data is transmitted through SDA. The I2C example was named “Wire” in the Arduino example.
In the previous example “I2C – Send Data to Arduino UNO” , Ameba, the I2C master, transmits data to the Arduino UNO, the I2C slave. As to this example, Ameba is the I2C slave, and receives data from the Arduino UNO, which is the I2C master.
- Setting up Arduino Uno to be I2C Master
First, select Arduino in the Arduino IDE in “Tools” -> “Board” -> “Arduino Uno”:
Open “Examples” -> “Wire” -> “master_writer”
Then click “Sketch” -> “Upload” to compile and upload the example to Arduino Uno.
- Setting up Ameba to be I2C Slave
Next, open another window of Arduino IDE, making sure to choose your Ameba development board in the IDE: “Tools” -> “Board”
Open “File” -> “Examples” -> “AmebaWire” -> “SlaveReader”
The Arduino example uses A4 as the I2C SDA and A5 as the I2C SCL.
Another important thing to note is that the GND pins of Arduino and Ameba should be connected to each other.
AMB21 / AMB22 wiring diagram:
AMB23 wiring diagram:
BW16 wiring diagram:
BW16 type C wiring diagram:
AW-CU488 Thing Plus wiring diagram:
AMB25 wiring diagram:
Open the Arduino IDE of the Arduino Uno and open the serial monitor (“Tools” -> “Serial Monitor”).
In the Serial Monitor, you can see the messages printed from Arduino Uno.
Next, press the reset button on Arduino Uno. Now the Arduino Uno is waiting for the connection from I2C Master.
We press the reset button on Ameba to start to send messages. Then observe the serial monitor, you can see the messages show up every half second.