File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
micropython/drivers/sensor/sht3x Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ module ("sht3x.py" , opt = 3 )
Original file line number Diff line number Diff line change
1
+ # SHT3x driver for MicroPython on ESP8266/ESP32
2
+ # MIT license; Copyright (c) 2022 WEMOS.CC
3
+
4
+ import utime
5
+
6
+
7
+ class SHT3X :
8
+ def __init__ (self , i2c , address = 0x45 ):
9
+ self .bus = i2c
10
+ self .slv_addr = address
11
+ self .buf = bytearray (6 )
12
+
13
+ def measure (self ):
14
+ self .bus .writeto (self .slv_addr , b"\x24 \x00 " )
15
+ utime .sleep (1 )
16
+ self .buf = self .bus .readfrom (self .slv_addr , 6 )
17
+
18
+ def humidity (self ):
19
+ humidity_raw = self .buf [3 ] << 8 | self .buf [4 ]
20
+ humidity = 100.0 * float (humidity_raw ) / 65535.0
21
+ return humidity
22
+
23
+ def temperature (self ):
24
+ temperature_raw = self .buf [0 ] << 8 | self .buf [1 ]
25
+ temperature = (175.0 * float (temperature_raw ) / 65535.0 ) - 45
26
+ return temperature
You can’t perform that action at this time.
0 commit comments