Advertisement
RuiViana

Teste_LCD_I2C_ESP8266

Mar 23rd, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <Wire.h>
  2.  
  3.  
  4. void setup()
  5. {
  6.   Wire.begin();
  7.  
  8.   Serial.begin(9600);
  9.   Serial.println("\nI2C Scanner");
  10. }
  11.  
  12.  
  13. void loop()
  14. {
  15.   byte error, address;
  16.   int nDevices;
  17.  
  18.   Serial.println("Scanning...");
  19.  
  20.   nDevices = 0;
  21.   for(address = 1; address < 127; address++ )
  22.   {
  23.  
  24.     Wire.beginTransmission(address);
  25.     error = Wire.endTransmission();
  26.  
  27.     if (error == 0)
  28.     {
  29.       Serial.print("I2C device found at address 0x");
  30.       if (address<16)
  31.         Serial.print("0");
  32.       Serial.print(address,HEX);
  33.       Serial.println("  !");
  34.  
  35.       nDevices++;
  36.     }
  37.     else if (error==4)
  38.     {
  39.       Serial.print("Unknow error at address 0x");
  40.       if (address<16)
  41.         Serial.print("0");
  42.       Serial.println(address,HEX);
  43.     }    
  44.   }
  45.   if (nDevices == 0)
  46.     Serial.println("No I2C devices found\n");
  47.   else
  48.     Serial.println("done\n");
  49.  
  50.   delay(5000);           // wait 5 seconds for next scan
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement