| 1 |
// Wire Master Reader |
| 2 |
// by Nicholas Zambetti <http://www.zambetti.com> |
| 3 |
|
| 4 |
// Demonstrates use of the Wire library |
| 5 |
// Reads data from an I2C/TWI slave device |
| 6 |
// Refer to the "Wire Slave Sender" example for use with this |
| 7 |
|
| 8 |
// Created 29 March 2006 |
| 9 |
|
| 10 |
// This example code is in the public domain. |
| 11 |
|
| 12 |
|
| 13 |
#include <Wire.h> |
| 14 |
|
| 15 |
void setup() { |
| 16 |
Wire.begin(); // join I2C bus (address optional for master) |
| 17 |
Serial.begin(9600); // start serial for output |
| 18 |
} |
| 19 |
|
| 20 |
void loop() { |
| 21 |
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 |
| 22 |
|
| 23 |
while (Wire.available()) { // slave may send less than requested |
| 24 |
char c = Wire.read(); // receive a byte as character |
| 25 |
Serial.print(c); // print the character |
| 26 |
} |
| 27 |
|
| 28 |
delay(500); |
| 29 |
} |