Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <Wire.h>
  2.  
  3. void setup()
  4. {
  5.   Wire.begin();
  6.  
  7.   Serial.begin(9600);
  8.   Serial.println("www.santy.cz - zdroj arduino.cc");
  9.   Serial.println("Scanner I2C sbernice");
  10. }
  11.  
  12. void loop()
  13. {
  14.   byte error, address;
  15.   int nDevices;
  16.  
  17.   Serial.println("Skenuji...");
  18.  
  19.   nDevices = 0;
  20.   for(address = 1; address < 127; address++ )
  21.   {
  22.     // The i2c_scanner uses the return value of
  23.     // the Write.endTransmisstion to see if
  24.     // a device did acknowledge to the address.
  25.     Wire.beginTransmission(address);
  26.     error = Wire.endTransmission();
  27.  
  28.     if (error == 0)
  29.     {
  30.       Serial.print("I2C zarizeni nalezeno na adrese 0x");
  31.       if (address<16)
  32.         Serial.print("0");
  33.       Serial.print(address,HEX);
  34.       Serial.println("  !");
  35.  
  36.       nDevices++;
  37.     }
  38.     else if (error==4)
  39.     {
  40.       Serial.print("Neznama chyba na adrese 0x");
  41.       if (address<16)
  42.         Serial.print("0");
  43.       Serial.println(address,HEX);
  44.     }    
  45.   }
  46.   if (nDevices == 0)
  47.     Serial.println("Zadne zarizeni nenalezeno\n");
  48.   else
  49.     Serial.println("Hotovo. (Dalsi sken za 5 sec...)\n");
  50.  
  51.   delay(5000);           // wait 5 seconds for next scan
  52. }