This library provides an interface for the DHT11 temperature and humidity sensor using STM32F4 microcontrollers, specifically tested with the STM32 Nucleo F401RE.
- Read temperature and humidity data from the DHT11 sensor
- Simple API for easy integration
- STM32F4 microcontroller (tested with STM32 Nucleo F401RE)
- STM32CubeMX and HAL libraries
- DHT11 sensor
- Clone the repository:
git clone https://github.com/Baryonics/dht11-stm32f4.git
- Add the entire
dht11-stm32f4
folder to your projectsLibs
folder. - Include the DHT11 library in your
CMakeLists.txt
file:# Add sources to executable target_sources(${CMAKE_PROJECT_NAME} PRIVATE # Add user sources here Libs/dht11-stm32f4/Src/dht11-stm32f4.c ) # Add include paths target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE # Add user defined include paths Libs/dht11-stm32f4/Inc )
- Include the DHT11 library in your main code:
#include "dht11-stm32f4.h"
- Initialize the DHT11 sensor (ensure the timer
htim
is prescaled so that one tick equals one microsecond. For the Nucleo F401RE, set the prescaler to 84): - Initialize the DHT11 sensor:
DHT11_Init(DHT11_DATA_Port, DHT11_DATA_Pin, htim);
- Read data from the sensor:
uint16_t temp; uint16_t rh; DHT11_Status dht11_status = dht11_read(&temp, &rh);
Initializes the DHT11 sensor.
Reads temperature and humidity data from the DHT11 sensor.
*temp
: Pointer to a variable to store the read temperature data.*rh
: Pointer to a variable to store the read humidity data.- Returns
DHT11_OK
on success, or an error code on failure.