Master Reader/Slave Sender

In some situations, it can be helpful to set up two (or more!) Arduino boards to share information with each other. In this example, two boards are programmed to communicate with one another in a Master Reader/Slave Sender configuration via the I2C synchronous serial protocol. Several functions of Arduino's Wire Library are used to accomplish this. Arduino 1, the Master, is programmed to request, and then read, 6 bytes of data sent from the uniquely addressed Slave Arduino. Once that message is received, it can then be viewed in the Arduino Software (IDE) serial monitor window.

The I2C protocol involves using two lines to send and receive data: a serial clock pin (SCL) that the Arduino Master board pulses at a regular interval, and a serial data pin (SDA) over which data is sent between the two devices. As the clock line changes from low to high (known as the rising edge of the clock pulse), a single bit of information - that will form in sequence the address of a specific device and a a command or data - is transferred from the board to the I2C device over the SDA line. When this information is sent - bit after bit -, the called upon device executes the request and transmits it's data back - if required - to the board over the same line using the clock signal still generated by the Master on SCL as timing.

Because the I2C protocol allows for each enabled device to have it's own unique address, and as both master and slave devices to take turns communicating over a single line, it is possible for your Arduino board to communicate (in turn) with many devices, or other boards, while using just two pins of your microcontroller.

Hardware Required

  • 2 Arduino Boards

  • hook-up wires

Circuit

Connect pin A4 (the data, or SDA, pin) and pin A5 (the clock, or SCL, pin) on the master board to their counterparts on the slave board. Make sure that both boards share a common ground. In order to enable serial communication, the master board must be connected to your computer via USB.

If powering the boards independently is an issue, you can power the Slave from the Master board. With a 5 V Slave, this would be done by connecting the 5V output of the Master to the 5V pin on the slave.

Master Sender bb

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

Master Sender sch

Code

See Also

Last revision 20210507 by DC