rs-dht-pio/readme.md

33 lines
2.2 KiB
Markdown
Raw Normal View History

2023-09-09 12:02:14 +00:00
# DHT PIO Rust Library
2023-09-09 15:59:26 +00:00
[![crates.io](https://img.shields.io/crates/v/dht-pio)](https://crates.io/crates/dht-pio) [![GitHub](https://img.shields.io/github/license/jnthbdn/rs-dht-pio)](https://github.com/jnthbdn/rs-dht-pio) [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/jnthbdn/rs-dht-pio)
2023-09-09 12:02:14 +00:00
_[french version](readme_fr.md)_
## Why?
The DHT (22 or 11) uses a 1-Wire protocol, which is not compatible with the [Dallas Semicondutors](https://en.wikipedia.org/wiki/1-Wire) protocol of the same name. The [Raspberry Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/) (like other microcontrollers) has no dedicated peripherals for this protocol.
Numerous crates exist for using DHT via a digital pin, but after testing several of them, they don't work reliably. The main problem is the implementation of the [embedded_hal](https://crates.io/crates/embedded-hal) by [rp2040_hal](https://crates.io/crates/rp2040-hal). Manipulating the state and direction of a pin takes too long (I measured between 2µs and 6µs depending on the action requested). This is due, among other things, to the impossibility of placing a pin in open drain, which requires "simulating" this feature
## The PIO ❤️
The RP2040 chip (used for the Pico) has a rather atypical peripheral called PIO (Programmable Input/Output), [Chapter 3 of the DataSheet](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf). In simple terms, the idea is to be able to run a small program (max. 32 instructions), which executes independently. It can manipulate GPIOs and share information with the main program.
The PIO is programmed using an assembler called `pioasm`, with just a few very basic instructions. What's interesting is that each instruction takes (usually) 1 cycle to execute. What's more, it's possible to divide the clock at which the program executes. In our case, we divide the main clock of 125 MHz by 125, giving us one instruction per microsecond.
## Example
todo!()`
## Support
### Board
For the moment, the crates have only been tested on a Raspberry Pico.
### DHT
✅ DHT22
2023-09-09 12:13:35 +00:00
❌ DHT11
## TODO
2023-09-09 12:32:14 +00:00
- [ ] Finish Readme
- [ ] Add CRC read
- [ ] Check CRC
- [ ] DHT11 support
- [ ] Test DHT11
- [ ] Document code