Unable to read temperature value from SHT30
-
-
@surya The alternate I2C address is 45, some suppliers set it to this by default.
Alternately you could try an sketch called an I2C scanner to see what devices are hooked up.
This little sketch works on my AtomS3:#include "M5UnitENV.h" SHT3X sht3x; void setup() { //runs once on start up Serial.begin(115200); //open the serial port for USB cable delay(500); Serial.println("in setup"); delay(1000); //wait for a second } void loop() { if (sht3x.begin(&Wire, 0x44, 2, 1, 400000U)) { Serial.println("Address 44 detected"); } else if (sht3x.begin(&Wire, 0x45, 2, 1, 400000U)) { Serial.println("Address 45 detected"); } else { Serial.println("No ENV detected"); }
-Terry
-
-
The SHT30 perfectly worked with "M5UnitENV.h". Thanks again!
Here I am encountering another challenge: I'm attempting to read temperature data from both the SHT30 and SHT40 simultaneously. However, both sensors share the same I2C address (0x44), leading to an error. I also experimented with changing the address to 0x45, but unfortunately, it didn't resolve the issue. Any advice is greatly appreciated.
Here is my new setup:
Code:
#include <M5AtomS3.h> #include <M5Unified.h> #include "Wire.h" #include "M5UnitENV.h" #include <SensirionI2CSht4x.h> SHT3X sht3x; SensirionI2CSht4x sht4x; float temperature, humidity; void setup() { Serial.begin(115200); if (!sht3x.begin(&Wire, SHT3X_I2C_ADDR, 2, 1, 400000U)) { Serial.println("Couldn't find SHT3X"); // while (1) // { // Serial.println("Couldn't find SHT3X"); // delay(1000); // } } sht4x.begin(Wire, SHT40_I2C_ADDR_45); } void loop() { temperature = humidity = NULL; uint16_t error; char errorMessage[256]; if (sht3x.update()) { Serial.println("-----SHT3X-----"); Serial.print("Temperature: "); Serial.print(sht3x.cTemp); Serial.println(" degrees C"); Serial.print("Humidity: "); Serial.print(sht3x.humidity); Serial.println("% rH"); Serial.println("-------------\r\n"); } error = sht4x.measureHighPrecision(temperature, humidity); if (error) { Serial.print("Error trying to execute measureHighPrecision(): "); errorToString(error, errorMessage, 256); Serial.println(errorMessage); } else { Serial.println("-----SHT4X-----"); Serial.print("Temperature:"); Serial.print(temperature); Serial.print("\t"); Serial.print("Humidity:"); Serial.println(humidity); Serial.println("-------------\r\n"); } delay(1000); }
Thanks
Surya -
@surya if you can’t physically change the addresses then you will need an I2C hub which overrides the I2C internal address
-
I'm just curious, Is there a way to accomplish this programmatically, without needing to physically change the addresses?
Thanks
Surya -
@surya Generally not as often the soldering of the devices pins is what's used to set the address.
-
@surya You need a PaHub:
https://docs.m5stack.com/en/unit/pahub2https://shop.m5stack.com/products/i2c-hub-1-to-6-expansion-unit-pca9548apw
They are easy to set up and work very well.
-
-
Okay, We're gonna buy PaHub to make it work.
Thank you all for your invaluable solutions and clarifications on my issue. Your help is greatly appreciated!