micropython/drivers: Add "sht3x" sensor driver.#549
micropython/drivers: Add "sht3x" sensor driver.#549wemos wants to merge 3 commits intomicropython:masterfrom
Conversation
| @@ -0,0 +1 @@ | |||
| module("sht3x.py", opt=3) | |||
There was a problem hiding this comment.
Please add a metadata() with description and version.
| # SHT3x driver for MicroPython on ESP8266/ESP32 | ||
| # MIT license; Copyright (c) 2022 WEMOS.CC | ||
|
|
||
| import utime |
| @@ -0,0 +1,26 @@ | |||
| # SHT3x driver for MicroPython on ESP8266/ESP32 | |||
There was a problem hiding this comment.
Doesn't look like this is specific to ESP as it uses the common i2c API.
Can you also add that it's a temp/humidity sensor, and made by Sensirion.
| class SHT3X: | ||
| def __init__(self, i2c, address=0x45): | ||
| self.bus = i2c | ||
| self.slv_addr = address |
| def measure(self): | ||
| self.bus.writeto(self.slv_addr, b"\x24\x00") | ||
| utime.sleep(1) | ||
| self.buf = self.bus.readfrom(self.slv_addr, 6) |
There was a problem hiding this comment.
This should be readfrom_into to avoid re-allocating buf.
| utime.sleep(1) | ||
| self.buf = self.bus.readfrom(self.slv_addr, 6) | ||
|
|
||
| def humidity(self): |
There was a problem hiding this comment.
I wonder about adding a non-floating point version of these functions (to avoid float allocations), i.e.return an integer in 1/10ths of a degree / percent. (The point being that if you remove this float allocation and with the readfrom_into above, then the whole driver is non-allocating).
There was a problem hiding this comment.
Or perhaps just have only the versions that return tenths and the calling code can simply convert to float by doing `s.humidity() / 10.0' if necessary.
| humidity = 100.0 * float(humidity_raw) / 65535.0 | ||
| return humidity | ||
|
|
||
| def temperature(self): |
There was a problem hiding this comment.
Assuming this is in degrees Celcius? (Maybe add a comment so someone can easily check this by looking at the code, or perhaps rename the variable to temperature_c)
|
@wemos Thanks for implementing the We're keen to merge this PR, but please address the review comments first. |
|
ok |
Add "sht3x" sensor driver.