Skip to content

Commit 06d703f

Browse files
committed
micropython/drivers: Add "sht3x" sensor driver.
1 parent 8503017 commit 06d703f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module("sht3x.py", opt=3)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

0 commit comments

Comments
 (0)