Esp32/esp32 i2c scanner: Difference between revisions
From Federal Burro of Information
< Esp32
(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...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
for esp32 c3 mini dev board you can use pins 6 and 7, then do this: | |||
#define I2C_SDA 6 | |||
#define I2C_SCL 7 | |||
Script | |||
<pre> | |||
/********* | /********* | ||
Rui Santos | Rui Santos | ||
Line 55: | Line 64: | ||
delay(5000); | delay(5000); | ||
} | } | ||
<pre> | </pre> | ||
[[category:Electronics]] | |||
[[category:script]] |
Latest revision as of 02:41, 9 October 2023
for esp32 c3 mini dev board you can use pins 6 and 7, then do this:
#define I2C_SDA 6 #define I2C_SCL 7
Script
/********* 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"); 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); }