i2cscan.c 541 B

12345678910111213141516171819202122232425262728293031
  1. // I2C scanner utility
  2. void scan() {
  3. byte error, address;
  4. int nDevices;
  5. nDevices = 0;
  6. for (address = 1; address < 127; address++ )
  7. {
  8. error = !i2c_start((address<<1)|I2C_WRITE);
  9. i2c_stop();
  10. if (!error)
  11. {
  12. if (address < 127) {
  13. softSerial.print(" ++");
  14. nDevices++;
  15. }
  16. } else {
  17. softSerial.print(" --");
  18. }
  19. softSerial.print(address, HEX);
  20. }
  21. softSerial.println("");
  22. if (nDevices == 0) {
  23. softSerial.println(":(");
  24. }
  25. else
  26. {
  27. softSerial.println(":)");
  28. }
  29. }