We purchased the Heltec WiFi LoRa ESP32 V3 module, and I tested all the pins for their respective functions. When I checked the I2C communication for the SHT40 sensor separately, it worked properly, and I was able to get temperature and humidity values. However, when I connected the sensor along with the OLED display, the sensor failed to communicate, and the OLED display showed a “SHT not found” message. I suspect there might be a conflict in the I2C communication between the OLED and the SHT sensor.
To clarify this issue, I used an I2C scanner, which detected the SHT40 sensor at address 0x44 and showed successful initialization in the debug message. However, after initialization, the sensor stops responding. Below, I have attached my code for your review. Please help me resolve this issue.
#include “LoRaWan_APP.h”
#include “HT_SSD1306Wire.h”
#include “Arduino.h”
#include “Adafruit_SHT4x.h”
#include <Wire.h>
void OnTxDone(void);
void OnTxTimeout(void);
static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED); // addr , freq , i2c group , resolution , rst
extern TwoWire Wire1;
Adafruit_SHT4x sht4 = Adafruit_SHT4x(); // SHT40 sensor instance
int sdaPin = 41;
int sclPin = 42;
const int SHT = 0x44;
float temp,humd;
void VextON(void)
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, LOW);
}
void VextOFF(void) //Vext default OFF
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, HIGH);
}
void setup() {
Serial.begin(115200);
Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE);
VextON();
delay(100);
display.init();
display.clear();
display.display();
display.setContrast(255);
display.setTextAlignment(TEXT_ALIGN_LEFT);
delay(1000);
Wire1.begin(sdaPin,sclPin);
Wire1.beginTransmission(SHT);
Serial.println("Initializing I2C devices...");
// Initialize SHT40 sensor
if (!sht4.begin()) {
Serial.println("Couldn't find SHT4x sensor!");
showDisplay("Couldn't find SHT4x sensor!");
while (1);
}
Serial.println("Found sht4x sensor");
showDisplay("Found SHT4x sensor!");
sht4.setPrecision(SHT4X_HIGH_PRECISION); // Set to high precision mode
sht4.setHeater(SHT4X_NO_HEATER); // Disable the heater
}
void loop() {
sensors_event_t humidity, temp_event;
sht4.getEvent(&humidity, &temp_event);
temp = temp_event.temperature;
humd = humidity.relative_humidity;
Serial.print("Temperature: "); Serial.println(temp);
Serial.print("Humidity: "); Serial.println(humd);
showDisplay("Sensor value: ");
delay(2000);
}
void showDisplay(String message) {
display.clear();
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, message);
String tempStr = “Temperature: " + String(temp) + " C”;
String humdStr = “Humidity: " + String(humd) + " %”;
display.drawString(0, 16, tempStr);
display.drawString(0, 32, humdStr);
display.display();
}