ESP32 board will not recognize I2C devices

AlikModi
Posts: 1
Joined: Tue Feb 08, 2022 5:11 pm

ESP32 board will not recognize I2C devices

Postby AlikModi » Tue Feb 08, 2022 6:34 pm

I am working on an indoor air sensor station with 2 air sensors:

Adafruit BME280
Adafriut CCS811

I also have an OLED screen I am using to display the data from the sensors. All on the same I2C bus.

I started by hooking everything up to an Elegoo UNO to get my code running and make sure the sensors worked and I got that working great. But now that I have transitioned to the ESP32 the board will not recognize the I2C devises on the bus.

I ran the I2C scan example sketch and it finds 2 of the 3 devices on the line, the BME280, and the OLED. But it will not see the CCS811.

At first I thought it was the lack of a Pull up Resistor as I did not have them when I wired the sensors to the UNO. So I added a 1K resistor to the bus on both the clock and data lines going to the 5V. But that seems to have made no difference.

I am sure it's something stupid that I am missing as this is my first project and I am a NOOB at this, any help would be great thanks a lot for your help. Here are some pictures and diagrams with code.


IMG_0368.jpg
IMG_0368.jpg (4.25 MiB) Viewed 3128 times
IMG_0369.jpg
IMG_0369.jpg (1 MiB) Viewed 3128 times

[Codebox]
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_CCS811.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SEALEVELPRESSURE_HPA (1013.25)


// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_CCS811 ccs;
Adafruit_BME280 bme; // I2C



float rTemp, rPres, rHum, rCO2, rTVOC;
//String disTemp, disPres, disHum, disCO2, disTVOC;

void setup() {

Serial.begin(9600);

if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
}

Serial.println("BME test");


if (!bme.begin()) {
Serial.println(F("BME Senor failed to start."));
}

Serial.println("CCS811 test");

if (!ccs.begin()) {
Serial.println(F("CSS Senor failed to start."));
}

display.clearDisplay();

while (!ccs.available());

}

void loop() {
printSerialValues();

rTemp = ((bme.readTemperature()* 9/5) + 32 );
rPres = (bme.readPressure() / 100.0F);
rHum = bme.readHumidity();
rCO2 = ccs.geteCO2();
rTVOC = ccs.getTVOC();



/*disTemp = String(rTemp, 0);
disPres = String(rPres, 0);
disHum = String(rHum, 0);
disCO2 = String(rCO2, 0);
disTVOC; String(rTVOC, 0);*/

oledUpdateFunc();

delay(5000);
}
[/Codebox]


[Codebox]
void oledUpdateFunc() {

//String disTemp, disPres, disHum, disCO2, disTVOC;

//disTemp = String(rTemp, 0);
//disPres = String(rPres, 0);
//disHum = String(rHum, 0);
//disCO2 = String(rCO2, 0);
//disTVOC; String(rTVOC, 0);

/*display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
// Display static text
display.println("Air Sensor");
//display.display();*/

display.clearDisplay();
display.setTextSize(2);
//display.setTextColor(WHITE);
display.setCursor(10, 0);
//Display static text
display.print(rTemp);
display.print(" F");

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 20);
//Display static text
display.print("Press: ");
display.print(rPres);
display.print(" hPa");

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 30);
//Display static text
display.print("Hum: ");
display.print(rHum);
display.print(" %");

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 40);
//Display static text
display.print("CO2: ");
display.print(rCO2);
display.print("ppm");

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 50);
//Display static text
display.print("TVOC: ");
display.print(rTVOC);
display.display();


}
[/Codebox]


[Codebox]
void printSerialValues() {

Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");

Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");

Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");

if (ccs.available()) {
if (!ccs.readData()) {
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.println(ccs.getTVOC());
}
else {
Serial.println("ERROR!");
while (1);
}
}
Serial.println();
}
[/Codebox]
Attachments
Schematic_Air Sensor_2022-02-08.pdf
(35.36 KiB) Downloaded 223 times

ESP_LJH
Posts: 387
Joined: Tue May 18, 2021 9:21 am

Re: ESP32 board will not recognize I2C devices

Postby ESP_LJH » Thu Feb 10, 2022 3:48 am

Have you measured I2C signals from oscilloscope or logic analyzer?
And since ESP32 only supports up to 3.6 V, could you make sure I2C lines are 3.3 V interface then have a try?

MikeLemon
Posts: 45
Joined: Tue Feb 02, 2021 5:55 pm

Re: ESP32 board will not recognize I2C devices

Postby MikeLemon » Tue Feb 22, 2022 7:33 am

ESP_LJH wrote:
Thu Feb 10, 2022 3:48 am
Have you measured I2C signals from oscilloscope or logic analyzer?
And since ESP32 only supports up to 3.6 V, could you make sure I2C lines are 3.3 V interface then have a try?
After checking the hardware interface physically try testing with an I2C scanner code which can commonly be found on the internet especially for Arduino platform that'll help you see if your SDA and SCL lines are not swapped.

after this check's I'd generally recommend running a know to work example code to test the hardware.

Who is online

Users browsing this forum: No registered users and 47 guests