I'm currently trying to establish an I2C connection between my ESP32-S2 and a PCA board, but I'm running into issues. The serial monitor keeps saying, "No I2C devices found," and I can't figure out why.
SCL on PCA → GPIO18 on ESP32-S2 (I know GPIO22 is the usual SCL pin, but the ESP32-S2 doesn’t have GPIO22, so I specified GPIO18 in my code.)
Code:
#include <Wire.h>
#define I2C_SDA 21
#define I2C_SCL 18
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial);
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.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown 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);
}
Serial monitor output
Scanning ....
No I2C devices found.
Does anyone have ideas on what might be wrong? Could it be a wiring issue, a problem with the code, or something specific to the ESP32-S2? Any help is greatly appreciated!
Had you put your sketch in a <CODE/> block and not in a screen shot, as requested in How to get the best out of this forum, it would have been possible to search your code for where you passed I2C_SDA and I2C_SCL to the Wire object to inform it that you wanted to use alternate pins.
However, since you didn't see fit to include your sketch in a <CODE/> block, no such search is possible. And I'm not eyeballing every line in the screen shots.
Thank you for doing that, and now that you have it took all of 5 seconds to search and discover that you didn't in fact use I2C_SDA or I2C_SCL anywhere in your sketch after #define ing them.
So think about that for a moment; how would Wire know to use your specific pins if you haven't told it about them?
Use 3.3V. Using 5V will pull up SDA and SCL to 5V which is too high for the ESP32S2. I would also disconnect all other wires for the I2C test. If you have other wires plugged in backwards or wrong voltages it may prevent the board from working. Debug the I2C interface before connecting more wires.