Advertisement
RedstonerNor

Arduino lcd I2C address

Sep 2nd, 2020
1,816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. void setup() {
  3.   Wire.begin();
  4.   Serial.begin(9600);
  5.   while (!Serial);
  6.   Serial.println("\nI2C Scanner");
  7. }
  8. void loop() {
  9.   byte error, address;
  10.   int nDevices;
  11.   Serial.println("Scanning...");
  12.   nDevices = 0;
  13.   for (address = 1; address < 127; address++ ) {
  14.     Wire.beginTransmission(address);
  15.     error = Wire.endTransmission();
  16.     if (error == 0) {
  17.       Serial.print("I2C device found at address 0x");
  18.       if (address < 16)
  19.         Serial.print("0");
  20.       Serial.print(address, HEX);
  21.       Serial.println("  !");
  22.       nDevices++;
  23.     }
  24.     else if (error == 4) {
  25.       Serial.print("Unknown error at address 0x");
  26.       if (address < 16)
  27.         Serial.print("0");
  28.       Serial.println(address, HEX);
  29.     }
  30.   }
  31.   if (nDevices == 0)
  32.     Serial.println("No I2C devices found\n");
  33.   else
  34.     Serial.println("done\n");
  35.   delay(5000);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement