Open tim-seoss opened 5 years ago
Just realised that I didn't search for the si7021 on crates.io, and there seems to be this:
https://crates.io/crates/si7021
I don't have either compatible devices, but I've seen breakouts for both on ebay for circa €2, so I'll order a couple.
I'm not sure if those compatible devices compied the entire protocol (including fetching serial number), or only parts of it. Would be worth checking.
In any case, as far as I know Sensirion were the first to release digital temperature sensors with that protocol, so if we want a crate that offers official support for all of them, I think it should either have a generic name, or sht2x
.
I've taken a quick look at the HTU21D and Si7021 datasheets both seem pretty feature complete and it looks like it should be reasonably easy to support all three.
Ok, I also ordered both of them off Aliexpress. This should allow us to test all three sensors for compatibility with this library.
Ok, I also ordered both of them off Aliexpress.
Hm, I don't think I ever received those... Confirmation timeout is already reached. I guess I'll order them again.
I've done some basic testing with an HTU21 and a Si7021, I've also added CRC support, serial-number reading support (both implemented as optional features), an example to read data using an I²C capable FTDI USB adapter (tested in Linux, but should work for Windows and Mac too), and another example to read data using an stm32f411.
I haven't yet looked at adding heater control support (which I may need because I plan to use a couple of these sensors in an environment which is likely to have sustained very high humidity).
Nice! Did you already update the crate to the latest embedded-hal version? Then we don't need nightly anymore.
Feel free to open a PR (either separate for easier discussion, or a single PR if that's easier for you). I can also add you as comaintainer to this repo.
By the way, the shtcx crate might also help as inspiration. And there's also https://github.com/Sensirion/sensirion-i2c-rs, but I don't know how much we gain from using it.
Or, actually, since you seem to be interested in maintaining this: I can also transfer the repo to you (or alternatively you simply fork and publish). I don't actively use this sensor anymore (I switched to SHTC3), so feel free to take over.
Further ideas for improvement: Tests with embedded-hal-mock could be added (similar to here).
Did you already update the crate to the latest embedded-hal version?
Yep, I updated that already (same with rustfmt, but missed re-running that with the previous PR).
By the way, the shtcx crate might also help as inspiration.
Thanks, I'll take a look.
And there's also https://github.com/Sensirion/sensirion-i2c-rs, but I don't know how much we gain from using it.
I found that crate when I was implementing the CRC support, but Sensirion changed the CRC8 parameters in the SHT3x and later sensors (the initialisation byte changed from 0x00
in SHT2x to 0xff
in SHT3x). Because sensirion-i2c-rs hard-codes the init byte, I used the crc crate ( https://crates.io/crates/crc ) instead.
Or, actually, since you seem to be interested in maintaining this: I can also transfer the repo to you (or alternatively you simply fork and publish). I don't actively use this sensor anymore (I switched to SHTC3), so feel free to take over.
I'm happy to either maintain or co-maintain - whichever you prefer.
@linuxtim sorry, I missed your reply.
The best way to go forward: You fork this repo and publish to crates.io (the sht2x
name is still free). I update the README of this repo and point to your fork.
Does that sound good to you?
OK, cool. I'll do that but I'm super-busy at the moment, so I may not have time until Sept or Oct.
I think the minimum necessary for releasing to crates.io is probably to fix the temp type (#2) and add humidity measurement. I've got working code for that which returns an i32 for the RH value in thousands of a %RH (which I believe can go negative due to measurement errors, hence the i32).
I could also add an example based on the stm32f103 testrig which I'm using, which would probably be useful.
There are a few other possible features, such as reading the device serial number and implementing (optional) CRC checking which would probably be useful, as well as reset.
Also, a number of other devices have been created by other manufacturers which implement the same protocol as the Sensirion SHT2x, such as the Silicon Labs Si7021 & the TE (previously Measurement Specialties) HTU21D, so it would be useful if this at least showed up in crates.io searches (by adding it to the description) but alternatively the name could reflect this I suppose?