This repository contains a driver for the DHT22 temperature and humidity sensor for use with the Raspberry Pi Pico. The driver communicates with the DHT22 sensor over a single data line using specific timing to read the temperature and humidity values.
The diagram above illustrates the signal timing for single-bus communication between the host (Raspberry Pi Pico) and the DHT22 sensor.
📌 AM2302 Pin Diagram
These images show the pin assignments for the AM2302 sensor. Make sure to connect them correctly to your Raspberry Pi Pico.
Before using this driver, ensure that the Raspberry Pi Pico SDK is installed and the PICO_SDK_PATH
environment variable is set.
To build the project, use the following commands:
mkdir build
cd build
cmake ..
make
This will compile the driver and create an executable.
To integrate the DHT22 driver into your own project:
- Copy the
DHT22-master
directory into your project. - In your
CMakeLists.txt
, add the directory of the DHT22 driver totarget_include_directories
. - Include
DHT22.h
in youradd_executable
command.
The DHT22 sensor sends data in 5 bytes, where:
- The first two bytes represent the humidity percentage.
- The next two bytes represent the temperature in Celsius.
- The last byte is a checksum for data integrity.
Here's an example from the datasheet:
Received Data:
0000 0010 1001 0010 0000 0001 0000 1101 1010 0010
Calculated Checksum:
0000 0010 + 1001 0010 + 0000 0001 + 0000 1101 = 1010 0010 (Parity bit)
The received data is correct:
Humidity: 65.8% RH
Temperature: 26.9°C
Note: If the highest bit of the temperature data is 1, it indicates a negative temperature value.
For temperatures below 0°C, the highest bit of the temperature data will be set. For example, a temperature of -10.1°C will be represented as:
1 000 0000 0110 0101
Feel free to fork this project and contribute to improving the driver. If you encounter any issues or have suggestions, please open an issue in the repository.
This project is licensed under the MIT License - see the LICENSE file for details.