Hi everyone.
I used a Arduino UNO to do I2C scanner an ESP32, did't get any result, why?
Thanks
Adam
We have no way of knowing what you did.
The ESP32 is 3V3, your device needs to be the same.
Pull-ups need to be ~10k.
You need to use the correct I2C ESP32 pins.
I2C Device | ESP32 |
---|---|
SDA | SDA (default is GPIO 21) |
SCL | SCL (default is GPIO 22) |
SDA to go to SDA, SCL to go to SCL.
/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop() {
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);
}
Most probably because you did the hardware wrong. We have no clue what hardware you have (other than the ESP32) and how you wired it.
What does that actually mean? Please post a schematic showing how you wired the Uno to the ESP. Can we assume the i2c scanner sketch is running on the Uno? What code was uploaded to the ESP?
I2C scanner certainly works on the ESp32 - I have also used I2C_detect
Thanks for all.
have a good weekend.
actually, I wonder if the Arduino be able to scann a mcu board's I2C. because my other I2C parts can be easily scanned such like: OLED, MCP2317.
I2C scan on MCUs is typically attempting a write to the slave address and checking for an ACK, e.g. for a PIC24F
// scan for I2C devices - you may have to enable some devices for this to work
void I2C1scan(void)
{
int address=0xa0;
printf("\nSLAVE_I2C_GENERIC_RETRY_MAX %d SLAVE_I2C_GENERIC_DEVICE_TIMEOUT %d\n", SLAVE_I2C_GENERIC_RETRY_MAX , SLAVE_I2C_GENERIC_DEVICE_TIMEOUT );
printf("\n\nI2C1 scaning address \n");
byte x=0;
for(address =0x2;address<255;address+=2) {
ClrWdt ();
I2C1_Initialize();
//if(I2C1scanWriteAddress(address) == 1) printf("\naddress 0x%02X found\n", address);
if(I2C1writeSlaveAddress(address, &x, 1, 0) == 1) printf("\naddress 0x%02X found\n", address);
//if(I2C1readSlaveAddress(address,0,0, &x, 1) == 1) printf("\naddress 0x%02X found\n", address);
else printf("0x%02X ", address);
}
// test particular address
//if(I2CscanWriteAddress(address=0xa0) == 1) printf("address 0x%02x found\n", address);
//else printf("address ox%02x NOT foud\n", address);
}
It can if that MCU is programmed to react on I2C requests. Otherwise it won't see anything, which is good and the expected behavior.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.