master_reader.ino 734 B

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