This repository contains library for DHT11 temperature and humidity module. DHT11 requires 18ms delay in its read start sequence. This library has separate API for beginning and end of this sequence, it's up to the user to decide how to implement the delay (blocking, state machine or RTOS task based).
- Modify HAL include in
dht11.h
if needed. - Configure pin that is connected to DHT11 as EXTI interrupt on falling and rising edge
- Configure timer for 1us tick
- Initialize
DHT11_TypeDef
with: pointer to data buffer, pointer to timer handle, GPIO pin and GPIO Port. - Put
DHT11_IRQHandler
in interrupt handler or EXTI callback. - Implement function
void DHT11_RecieveCpltCallback(DHT11_TypeDef *dht)
- Call
DHT11_Start_Init
- Wait for ~18ms
- Call
DHT11_Start_End
- DHT11 will send data now, it will be available after callback executes.
Data is saved in 5 byte long buffer, meaning of bytes:
- Humidity - integral part
- Humidity - decimal part (always 0 on DHT11)
- Temperature - integral part
- Temperature - decimal part
- Checksum - should be equal to a sum of previous bytes in buffer
Interrupts (orange) and transmitted bits (white):
Full data transmission: