How do I transfer data between two Arduinos?

How do I transfer data between two Arduinos?

Follow these steps to connect two Arduino UNOs using I2C:

  1. Connect pins A4 and A5 on one Arduino to the same pins on the other one.
  2. The GND line has to be common for both Arduinos. Connect it with a jumper.

What is I2C and how it works?

I2C is a serial communication protocol, so data is transferred bit by bit along a single wire (the SDA line). Like SPI, I2C is synchronous, so the output of bits is synchronized to the sampling of bits by a clock signal shared between the master and the slave. The clock signal is always controlled by the master.

What kind of data can be transferred via I2C?

Basically we convert any value, string, number, text, float, you name it, and turn into a variable char, which can be transferred via I2C. Once transferred, you can convert back to a number although in my case below, I just wanted to display the data from the slave. Here is the code.

How does a slave device start an I2C transaction?

At any time a master device can start a transaction by pulling SDA low while SCL is high (a unique specific condition that other I2C devices recognise as the start of a master transmission). The slave device listens to the next 7 serial bits of the address to see if it matches its own address (each I2C must have a unique address).

Which is the correct sequence for I2C read and write?

A basic Master to slave read or write sequence for I2C follows the following order: 1. Send the START bit (S). 2. Send the slave address (ADDR). 3. Send the Read(R)-1 / Write(W)-0 bit. 4. Wait for/Send an acknowledge bit (A).

How to send and receive data via I2C in Arduino?

There are implementations for serial, I2C, and VirtualWire and the examples provided are pretty self-explanatory. The handling is very easy. After including the library, you create an EasyTransfer object, define a data structure that basically represents a “container” of your data and this can consist of different variables.