DHT11 Pico Library - C++ - Raspberry Pi Pico  1.0
The DHT11 Pico Library provides a C++ implementation for interfacing with the DHT11 temperature and humidity sensor on the Raspberry Pi Pico microcontroller. It offers functions to read temperature and relative humidity from the sensor and supports error handling. This library simplifies the integration of the DHT11 sensor into Pico-based projects, allowing developers to easily retrieve environmental data for various applications.
dht11-pico.h
Go to the documentation of this file.
1 
10 #ifndef DHT11_PICO_H
11 #define DHT11_PICO_H
12 
13 #include "pico/stdlib.h"
14 
18 const int THRESHOLD = 7;
19 
23 const int POLLING_LIMIT = 50;
24 
28 const int TRANSMISSION_ERROR = -999;
29 
33 const long long RH_INT_MASK = 0xFF00000000;
34 
38 const long long RH_DEC_MASK = 0x00FF000000;
39 
43 const long long TEMP_INT_MASK = 0x0000FF0000;
44 
48 const long long TEMP_DEC_MASK = 0x000000FF00;
49 
53 const long long CHECKSUM_MASK = 0x00000000FF;
54 
62 class Dht11 {
63  uint gpioPin;
64 
73  long long read(void);
74 
75 public:
76 
82  Dht11(uint pin);
83 
87  ~Dht11();
88 
97  double readT(void);
98 
107  double readRH(void);
108 
118  void readRHT(double* temperature, double* rel_humidity);
119 };
120 
121 #endif
DHT11 Sensor Class.
Definition: dht11-pico.h:62
long long read(void)
Private method to read raw data from the DHT11 sensor.
Definition: dht11-pico.cpp:23
double readRH(void)
Read and retrieve the humidity value from the DHT11 sensor.
Definition: dht11-pico.cpp:100
uint gpioPin
GPIO pin connected to the DHT11 sensor.
Definition: dht11-pico.h:63
Dht11(uint pin)
Dht11 class constructor. Initializes GPIO and waits for the sensor to stablize.
Definition: dht11-pico.cpp:13
double readT(void)
Read and retrieve the temperature value from the DHT11 sensor.
Definition: dht11-pico.cpp:87
~Dht11()
Dht11 class destructor. De-initialize GPIO.
Definition: dht11-pico.cpp:19
void readRHT(double *temperature, double *rel_humidity)
Read both temperature and humidity values from the DHT11 sensor.
Definition: dht11-pico.cpp:111
const int THRESHOLD
Threshold for differentiating between bit 0 and bit 1 during DHT11 data transmission.
Definition: dht11-pico.h:18
const int POLLING_LIMIT
Maximum number of polling attempts during DHT11 data transmission.
Definition: dht11-pico.h:23
const long long RH_DEC_MASK
Bit mask to extract the decimal part of relative humidity from the raw data.
Definition: dht11-pico.h:38
const long long CHECKSUM_MASK
Bit mask to extract the checksum from the raw data.
Definition: dht11-pico.h:53
const long long TEMP_INT_MASK
Bit mask to extract the integer part of temperature from the raw data.
Definition: dht11-pico.h:43
const int TRANSMISSION_ERROR
Error value returned when there is a transmission error during DHT11 data reading.
Definition: dht11-pico.h:28
const long long TEMP_DEC_MASK
Bit mask to extract the decimal part of temperature from the raw data.
Definition: dht11-pico.h:48
const long long RH_INT_MASK
Bit mask to extract the integer part of relative humidity from the raw data.
Definition: dht11-pico.h:33