Tuesday, January 14, 2014

DHT22 Blocking Library for AVR

Some time ago a updated a DHT22 library posted at AVRFreaks forum. That lib returned float values which inplies that the AVR-GCC added a very large library. The code size was above 2kB.
With this update, float number is not needed anymore and the lib returns the integral and decimal parts of the values in a defined struct format. Is needed, the user can configure the lib to return raw values from the sensor. Code size now is only around 300 bytes.


However, this lib is Blocking which means the processor keeps buzy while reading the values. This process can take, in the worst case, almos 6ms. If this is too much for you, please check my Interrupt Driven DHT22 Library for AVR that do not blocks the processor.

The lib is based on _delay_us and _delay_ms which means the user have to define the F_CPU constant with the value of the clock being used (in hertz).

Usage


Please, disable interrupts while reading sensor. Interrupting the reading process can lead to wrong measurements and CRC error.
DHT22_STATE_t state;
DHT22_DATA_t sensor_values;
DHT22_ERROR_t error;
cli();
error = readDHT22(&sensor_values);
sei();

Remember to configure the pin where the sensor is connected at the header file (DHT22.h).

Download


No comments:

Post a Comment