| What to do: |
Background
To get an idea about what I2C is, please read this part of the Programming Interactivity book.
Initial set up
- Connect two Arduinos to two neighboring machines in the lab (or to two USB ports on
the same machine)
- Using the wires that came with your Arduino Kit, connect Analog IN pin 4 on one of
the Arduinos to Analog IN pin 4 on the other. Do the same for Analog pin 5.
- Now you can use the Wire library in your sketches.
Simple I2C Test
- Choose one of yor Arduinos to be used as the "Master", and the other as the "Slave".
It doesn't matter which one you choose as the Master or Slave, as long as you remember
which is which.
- Use this the Master-Sender code to create a new
sketch on the Master.
- Use this the Slave-Receiver code to create a new
sketch on the Slave.
- Open the Serial Moniter on both the Master and Slave machines. You should see a
marching stream of output on the Slave. This is data sent from the Master.
Something More Interesting
- Create two new sketches: One on the Master called "i2c_Master_Blinker", and one
one the Slave called "i2c_Slave_Blinker".
- Write code on the Master to read an integer from the serial port, and send it to the
Slave.
- Write code on the Slave to read an integer from the Master, and blink an LED
that number of times.
- The Slave should then send the integer, incremented by one, back to the Master,
which should then blink an LED that number of times. You might want to include
adequate delays between blinks so you can count them easily.
More Info:
A Wire reference page can be found here: http://arduino.cc/en/Reference/Wire
A set of Wire examples is available also.
Many off-the-shelf devices use I2C, so this code should come in handy.
|