adafruit / Adafruit_CircuitPython_SHT31D

CircuitPython driver for the SHT31-D temperature and humidity sensor
MIT License
20 stars 18 forks source link

Reading out SHT31D causes SHT40 temperature+humidity to spike #22

Closed ACrazyConcept closed 3 years ago

ACrazyConcept commented 3 years ago

I hooked up both a SHT31D and a SHT40 to the same RPi. But I kept getting these weird spikes in the SHT40 values if I also read the SH31D just before the SHT40, and worst of all if I read them both at the same time.

If I read the SHT40 before the SHT31D the values seem fine. But if I read the SHT40 too soon after the SHT31D it returns very high temperature and very low humidity.

I initially thought it was heat from the wires or some kind of interference. But now after having tried nearly all possible wiring alternatives, both with 3V and 5V, I think something might be happening due to the python code in some way.

Pasting two different tets. One where the SHT40 is read first and one where the SHT31D is read first.

import time
import board
import adafruit_sht31d
import adafruit_sht4x

i2c = board.I2C()

sht40 = adafruit_sht4x.SHT4x(i2c)
sht40.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION

sht31d = adafruit_sht31d.SHT31D(i2c)

while True:
    sht40_temperature, sht40_humidity = sht40.measurements
    sht31d_temperature = sht31d.temperature
    sht31d_humidity = sht31d.relative_humidity
    print(round(sht31d_temperature,4), round(sht31d_humidity,4), round(sht40_temperature,4),round(sht40_humidity,4))
    time.sleep(1)
23.3871 61.1612 -45.0 58.2023
23.4138 61.1643 24.4072 56.1099
23.3871 61.1368 24.6075 53.4148
23.4005 61.1521 24.7356 51.332
23.3871 61.146 24.8371 49.7259
23.3711 61.0605 24.9039 48.5853
23.4005 61.088 24.9866 47.7118
23.3871 61.0971 25.0587 47.0766
23.4005 61.0086 25.1095 46.5406
23.4138 61.0407 25.1602 46.1229
23.4005 61.0269 25.2243 45.7548
23.4138 61.0178 25.251 45.5354
23.4005 61.0315 25.3151 45.2856
23.4138 61.0193 25.3552 45.1501
23.4138 60.9873 25.3632 44.9728
23.4005 61.0101 25.3899 44.8698
23.4138 61.0147 25.4299 44.7095
23.4138 60.9903 25.4433 44.6371
23.4272 60.9766 25.4833 44.5627
import time
import board
import adafruit_sht31d
import adafruit_sht4x

i2c = board.I2C()

sht40 = adafruit_sht4x.SHT4x(i2c)
sht40.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION

sht31d = adafruit_sht31d.SHT31D(i2c)

while True:
    sht31d_temperature = sht31d.temperature
    sht31d_humidity = sht31d.relative_humidity
    time.sleep(0.1)
    sht40_temperature, sht40_humidity = sht40.measurements
    print(round(sht31d_temperature,4), round(sht31d_humidity,4), round(sht40_temperature,4),round(sht40_humidity,4))
    time.sleep(1)
23.4699 60.7202 32.541 56.9129
23.4699 60.7248 32.9736 54.2655
23.4565 60.7355 33.1338 51.8222
23.4699 60.7263 33.2086 50.0769
23.4859 60.7126 33.294 48.8066
23.4565 60.6928 33.3742 47.8643
23.4859 60.7126 33.4089 47.1987
23.4565 60.6928 33.4943 46.7142
23.4565 60.7126 33.537 46.3213
23.4699 60.6928 33.5744 46.0371
23.4565 60.708 33.6225 45.8654
23.4565 60.6836 33.6358 45.6384
23.4565 60.6973 33.6572 45.5431
23.4699 60.6851 33.6839 45.3943
anecdata commented 3 years ago

I believe they both have the same default I2C address (0x44), so they can't be used on the same bus like that. It may be that the libraries are similar enough that there is no error, just erroneous results.

The SHT31 has a jumper to change the address, the SHT40 does not. Or you may be able to use different I2C busses for each, or an I2C multiplexor.

ACrazyConcept commented 3 years ago

The SHT31 has a jumper to change the address, the SHT40 does not.

I wasn't aware of that option. But it appears to have solved the issue completely. Thanks!