how to read i2c with esp32 NodeMCU

A.Mourazo
Posts: 1
Joined: Wed Nov 11, 2020 2:39 pm

how to read i2c with esp32 NodeMCU

Postby A.Mourazo » Wed Nov 11, 2020 2:49 pm

I'm trying to read the i2c data from a scl30 sensor co2, but the esp32 don't doing anything, I'm write the sketch with Arduino IDE, how can I read sda y scl for gpio34 and gpio35 pins? The sensor works with an arduino and, with esp32 the power supply it's on, I see the infrared ligth but when I try to read the data the serial monitor it's empty and not recive data. What can I do? Thanks in advance

Image

Code: Select all

#include <Wire.h>

#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;

void setup()
{
   
  Serial.begin(115200);
 
  Serial.println("SCD30 Example");
  Wire.begin(35,34, 1000000);

  if (airSensor.begin() == false)
  {
    Serial.println("Air sensor not detected. Please check wiring. Freezing...");
    while (1)
      ;
  }

  //The SCD30 has data ready every two seconds
}

void loop()
{
  if (airSensor.dataAvailable())
  {
    Serial.print("co2(ppm):");
    Serial.print(airSensor.getCO2());

    Serial.print(" temp(C):");
    Serial.print(airSensor.getTemperature(), 1);

    Serial.print(" humidity(%):");
    Serial.print(airSensor.getHumidity(), 1);

    Serial.println();
  }
  else
    Serial.println("Waiting for new data");

  delay(500);
}

felmue
Posts: 70
Joined: Mon Nov 16, 2020 2:55 pm

Re: how to read i2c with esp32 NodeMCU

Postby felmue » Mon Nov 16, 2020 4:50 pm

Hello

GPIO34 and GPIO35 can only be used as inputs. SCL requires an output and SDA needs to be input and output.

Please see Pin Definition here: https://www.espressif.com/sites/default ... eet_en.pdf

Thanks
Felix

Who is online

Users browsing this forum: No registered users and 99 guests