Micropython driver for SHT30 Shield for Wemos D1 Mini (and PRO).
The driver has been tested on Wemos D1 mini PRO, but it should work on whatever other micropython board, if anyone find problems in other boards, please open an issue and we'll see.
The SHT30 shield for ESP8266 board Wemos D1 Mini has an Arduino driver but not a micropython one.
- Sensor Datasheet
- Arduino driver
- SHT30 C Code Examples from sensor manufacturer
The measure()
method returns a tuple with the temperature in degrees Celsius and the relative humidity in percentage.
If the measurement cannot be performed then an exception is raised (SHT30Error
)
from sht30 import SHT30
sensor = SHT30()
temperature, humidity = sensor.measure()
print('Temperature:', temperature, '°C, RH:', humidity, '%')
The measure_dp()
method returns a similar tuple but with the dew point temperature (i.e. the temperature at which dew will form if the air is cooled adiabatically) instead of relative humidity. Both values are degrees Celsius.
from sht30 import SHT30
sensor = SHT30()
temperature, dew_point = sensor.measure_dp()
print('Temperature:', temperature, '°C, dew point:', dew_point, '°C')
There is another method, measure_int()
, that returns 4 integer values, no floating point operation is done, designed
for environments that doesn't support floating point operations, the four values are:
Temperature (integer part), Temperature (decimal part), RH (integer part), RH (decimal part)
For instance, if the measure()
method returns (21.5623, 32.0712)
the measure_int()
method would return: (24, 56, 32, 7)
The decimal
part is limited to 2 decimal digits.
t_int, t_dec, h_int, h_dec = sensor.measure_int()
print('Temperature: %i.%02i °C, RH: %i.%02i %%' % (t_int, t_dec, h_int, h_dec))
Both methods allow a raw
param that when it's True
returns the sensor measurement as-is, it's a bytearray(6)
with the format defined in the sensor datasheet document.
raw_measure = sensor.measure(raw=True)
print('Sensor measurement', raw_measure)
from sht30 import SHT30
sensor = SHT30()
print('Is connected:', sensor.is_present())
Check the Sensor Datasheet for further info about sensor status register
from sht30 import SHT30
sensor = SHT30()
print('Status register:', bin(sensor.status()))
print('Single bit check, HEATER_MASK:', bool(sensor.status() & SHT30.HEATER_MASK))
# The status register can be cleared with
sensor.clear_status()
The driver allows a soft reset of the sensor
from sht30 import SHT30
sensor = SHT30()
sensor.reset()
When the driver cannot access the sensor an SHT30Error
exception is raised
from sht30 import SHT30
sensor = SHT30()
try:
t, h = sensor.measure()
except SHT30Error as ex:
print('Error:', ex)