Esp32/esp32 i2c scanner

From Federal Burro of Information
Revision as of 04:00, 20 November 2022 by David (talk | contribs) (Created page with "→‎******** Rui Santos Complete project details at https://randomnerdtutorials.com ********: #include <Adafruit_NeoPixel.h> #include <Wire.h> #define I2C_SDA 0 #define I2C_SCL 1 #define PIN 8 // On Trinket or Gemma, suggest changing this to 1 #define NUMPIXELS 1 // Popular NeoPixel ring size Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); void setup() { Wire.begin(I2C_SDA, I2C_SCL); Serial.begin(115200); Serial.println("\nI2C Scanner...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

/*********

 Rui Santos
 Complete project details at https://randomnerdtutorials.com  
                  • /
  1. include <Adafruit_NeoPixel.h>
  2. include <Wire.h>
  1. define I2C_SDA 0
  2. define I2C_SCL 1
  3. define PIN 8 // On Trinket or Gemma, suggest changing this to 1
  4. define NUMPIXELS 1 // Popular NeoPixel ring size

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

 Wire.begin(I2C_SDA, I2C_SCL);
 Serial.begin(115200);
 Serial.println("\nI2C Scanner");
 pixels.begin();

}

void loop() {

 pixels.clear();
 pixels.show();
 // pixels.setPixelColor(0, pixels.Color(0, i, 0));
 byte error, address;
 int nDevices;
 Serial.println("Scanning ...");
 nDevices = 0;
 for(address = 1; address < 127; address++ ) {
   Wire.beginTransmission(address);
   error = Wire.endTransmission();
   if (error == 0) {
     Serial.print("I2C device found at address 0x");
     if (address<16) {
       Serial.print("0");
     }
     Serial.println(address,HEX);
     nDevices++;
   }
   else if (error==4) {
     Serial.print("Unknow error at address 0x");
     if (address<16) {
       Serial.print("0");
     }
     Serial.println(address,HEX);
   }    
 }
 if (nDevices == 0) {
   Serial.println("No I2C devices found\n");
 }
 else {
   Serial.println("done\n");
 }
 delay(5000);          

}