You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
735B

  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(8, 6); // request 6 bytes from slave device #8
  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. }