esp32-S3 no psram and SHt40, false readings [code]

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rvcc
 
Posts: 10
Joined: Wed Mar 16, 2022 11:01 pm

esp32-S3 no psram and SHt40, false readings [code]

Post by rvcc »

The temperatue value generated is 35C high. My code is in C.
I have got an feather esp32-s3 no psram, connected with QT cable to an SHT40 sensor.
I have tried multiple sht 40 sensors and have the same issue.


Using Arduino IDE 2.1.0, with the ESP32 board support package from git hub.
I have deleted and reinstalled the Adafruit Sht4x library.
I have deleted and re cloned the Esp32 library.








#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_SHT4x.h>

// WiFi credentials
const char* ssid = "@$#$%#%#$%";
const char* password = "%$&$^$^&%$";

// MQTT broker
const char* mqtt_server = "0.0.0.0";
const int mqtt_port = 0000;

// MQTT topic
const char* mqtt_topic = "Temp sensor 2";

WiFiClient espClient;
PubSubClient client(espClient);
Adafruit_SHT4x sht4x;

void setup() {
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, mqtt_port);
if (!sht4x.begin()) {
Serial.println("Couldn't find SHT4x");
while (1) delay(10);
}
}

void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();

sensors_event_t temp, humidity;
sht4x.getEvent(&temp, &humidity);

if (!isnan(temp.temperature) && !isnan(humidity.relative_humidity)) {
String payload = "Temperature: " + String(temp.temperature) + " C, Humidity: " + String(humidity.relative_humidity) + " %";
client.publish(mqtt_topic, payload.c_str());
}
else {
Serial.println("Failed to read from SHT4x sensor!");
}

delay(2000);
}

void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
if (client.connect("ESP32Client")) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}

User avatar
rvcc
 
Posts: 10
Joined: Wed Mar 16, 2022 11:01 pm

Re: esp32-S3 no psram and SHt40, false readings [code]

Post by rvcc »

I have added the following to my code to turn the heater off.
sht4x.setPrecision(SHT4X_HIGH_PRECISION);
sht4x.setHeater(SHT4X_NO_HEATER);
i have also changed it to a 10 sec delay between reads.

still having the same issue

User avatar
freddyboomboom
 
Posts: 267
Joined: Wed Feb 16, 2022 7:55 pm

Re: esp32-S3 no psram and SHt40, false readings [code]

Post by freddyboomboom »

I don't use Arduino, sorry.

But even with a 10 second delay between reads you're turning it on 6 times per minute.

I usually do one read every 15 minutes and find that's close enough for my purposes.

Since I don't have any other calibrated temperature measurement device, I'm stuck with comparing different uncalibrated temperature sensors like the SHT40, so they're only about 1 to 3 degrees different from each other.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”