Hide minor edits - Show changes to markup
Connect pin 4 (the clock, or SCL, pin) and pin 5 (the data, or SDA, pin) on the
Connect pin 5 (the clock, or SCL, pin) and pin 4 (the data, or SDA, pin) on the
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/master_writer/master_writer.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/master_writer/master_writer.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/slave_receiver/slave_receiver.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/slave_receiver/slave_receiver.ino lang=arduino tabwidth=4:)
Because the 12C 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 to communicate (in turn) with many devices, or other Arduinos, while using just two pins of your microcontroller.
Each Slave device to have its own unique address and both master and slave devices to take turns communicating over a the same data line line. In this way, it's possible for your Arduino to communicate with many device or other Arduinos using just two pins of your microcontroller, using each device's unique address.
The I2C protocol involves using two wires to send and receive data: a serial clock pin (SCL) that the Arduino pulses at a regular interval, and a serial data pin (SDA) over which data is sent between the two devices. As the clock pulse changes from low to high (known as the rising edge of the clock), a bit of information containing the address of a specific device and a request for data, is transferred from the Arduino to the I2C devices over the SDA line. When the clock pin changes from high to low (the falling edge of the clock), the called upon device transmits it's data back to the Arduino over the same line.
The I2C protocol involves using two wires to send and receive data: a serial clock pin (SCL) that the Arduino pulses at a regular interval, and a serial data pin (SDA) over which data is sent between the two devices. As the clock pulse changes from low to high (known as the rising edge of the clock), a bit of information is transferred from the Arduino to the I2C devices over the SDA line. When the clock pin changes from high to low (the falling edge of the clock), the called upon device transmits a bit of data back to the Arduino over the same line. The initial eight bits (i.e. eight clock pulses) from the Master to Slaves contain the address of the device the Master wants data from. The bits after that contain the memory address on the Slave that the Master wants to read data from or write data to, and the data to be written, if any.
Master Writer Code - Arduino 1
Master Writer Code - Program for Arduino 1
Slave Receiver Code - Arduino 2
Slave Receiver Code - Program for Arduino 2
Master Receiver Code - Arduino 2
Slave Receiver Code - Arduino 2
Description
Sometimes, the folks in charge just don't know when to shut up! 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 Arduinos are programmed to communicate with one another in a Master Writer/Slave Receiver 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 send 6 bytes of data every half second to a uniquely addressed Slave Arduino. Once that message is received, it can then be viewed in the Slave Arduino's serial window.
The I2C protocol involves using two wires to send and receive data: a serial clock pin (SCL) that the Arduino pulses at a regular interval, and a serial data pin (SDA) over which data is sent between the two devices. As the clock pulse changes from low to high (known as the rising edge of the clock), a bit of information containing the address of a specific device and a request for data, is transferred from the Arduino to the I2C devices over the SDA line. When the clock pin changes from high to low (the falling edge of the clock), the called upon device transmits it's data back to the Arduino over the same line.
Because the 12C 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 to communicate (in turn) with many devices, or other Arduinos, while using just two pins of your microcontroller.
master Arduino to their counterparts on the slave board. Make sure that both boards share a common ground.
master Arduino to their counterparts on the slave board. Make sure that both boards share a common ground. In order to enable serial communication, the slave Arduino must be connected to your computer via USB.
If powered the Arduinos independently is an issue, the 5V output of the Master Arduino to the VIN pin on the slave.
If powering the Arduinos independently is an issue, connect the 5V output of the Master Arduino to the VIN pin on the slave.
Connect pin 4 (the clock, or SCL, pin) and pin 5 (the data, or SDA, pin) on the master Arduino to their counterparts on the slave board. Make sure that both boards share a common ground.
If powered the Arduinos independently is an issue, the 5V output of the Master Arduino to the VIN pin on the slave.
Master Writer Code
Master Writer Code - Arduino 1
Master Receiver Code
Master Receiver Code - Arduino 2
Wire.begin()]]
Describe what's going on here
Master Writer Code
Master Receiver Code
Wire.begin()]]
Wire.beginTransmission()
Wire.endTransmission()
Wire.send()
Wire.RequestFrom()
Wire.receive()
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/slave_receiver/slave_receiver.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/master_writer/master_writer.pde language=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/master_writer/master_writer.pde lang=arduino tabwidth=4:)
Examples > Wire Library
Description
(:div class=BOM :)
(:divend:)
(:div class=circuit :)
image developed using Fritzing. For more circuit examples, see the Fritzing project page
(:divend:)
(:div class=circuit :)
(:divend:)
Describe what's going on here
(:div class=code :) (:source http://github.com/arduino/Arduino/raw/master/libraries/Wire/examples/master_writer/master_writer.pde language=arduino tabwidth=4:) (:divend:)