Skip to content

SHT31 not working over I2C with ESP32 and Stickbreaker's library.  #1395

@JacoFourie

Description

@JacoFourie

I got this RH probe

https://www.aliexpress.com/item/SHT30-SHT31-AM23XX-single-bus-protection-temperature-and-humidity-sensor-probe-soil-moisture-sensor-5m-cable/32850764307.html

I can not get it to work with the ESP32. It works with the Arduino Mega on 5V not 3V. The supplier says because the Arduino is 5V logic it wil only work on 5v with the Arduino. As the ESP32 is 3v it should work on 3v.

Here is the test code.

/*************************************************** 
  This is an example for the SHT31-D Humidity & Temp Sensor

  Designed specifically to work with the SHT31-D sensor from Adafruit
  ----> https://www.adafruit.com/products/2857

  These sensors use I2C to communicate, 2 pins are required to  
  interface
 ****************************************************/
 
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"

Adafruit_SHT31 sht31 = Adafruit_SHT31();

void setup() {
  Serial.begin(115200);

  Serial.println(SDA);
  Serial.println(SCL);
  
  while (!Serial)
    delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("SHT31 test");
  if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    //while (1) delay(1); }
  }
  else {
    Serial.println("Found SHT31 !!"); 
  }
}


void loop() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();

  if (! isnan(t)) {  // check if 'is not a number'
    Serial.print("Temp *C = "); Serial.println(t);
  } else { 
    Serial.println("Failed to read temperature");
  }
  
  if (! isnan(h)) {  // check if 'is not a number'
    Serial.print("Hum. % = "); Serial.println(h);
  } else { 
    Serial.println("Failed to read humidity");
  }
  Serial.println();
  //delay(1000);
}

I get a [E][esp32-hal-i2c.c:1127] i2cProcQueue(): I2C exitCode=0x112 error from time to time on the output.

[E][esp32-hal-i2c.c:1127] i2cProcQueue(): I2C exitCode=0x112
Failed to read temperature
Failed to read humidity

Failed to read temperature
Failed to read humidity

Failed to read temperature
Failed to read humidity

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions