22
loading...
This website collects cookies to deliver better user experience
./
Contains the central CMakeLists.txt
file for three different build types: library only, tests, and examples../include
Contains the header file./src
The library source files and its accompanying cmake configuration./test
Using the CMocka framework, tests validate that the library objects and functions are correct./examples
Simple recipes how to use the libraryDHT11
with this signature:typedef struct DHT11
{
uint8_t DATA_PIN;
double last_temp;
double last_humidity;
double temp_measurements[30];
double humidity_measurements[30];
} DHT11;
dht11_new
, and then provides these functions:dht11_probe()
- Take a new measurement from the sensor, but only when it’s at least two seconds after the last trydht11_process()
- A helper method that receives the sequenced 40bit data, calculates the checksum, and updates the internal values when the probe was valid.dht11_get_last_temperature_measurement()
- Returns the most recent temperature measurementdht11_get_last_humidity_measurement()
- Returns the most recent humidity measurementdht11_get_historic_temperature_measurement()
- Retrieves a temperature measurement from the last 30 probesdht11_get_historic_humidity_measurement()
- Retrieves a humidity measurement from the last 30 probessleep_us
call to explicitly wait for the time as specified in the data sheet. I would then output a debug statement after each phase to confirm that the sensor behaves as expected.// I Activate DHT
{
gpio_put(pin, 0); // LOW
sleep_ms(18); // 18us
gpio_put(pin, 1); // HIGH
sleep_us(20); // 20us
}
// II Read DHT Confirmation
{
gpio_set_dir(pin, GPIO_IN);
bool init_state = 0;
int count = 0;
while(init_state = !gpio_get(pin)) { // EXPECT LOW 80us
count++;
sleep_us(1);
};
printf("DHT Confirmation LOW: %d\n", count);
count = 0;
while(init_state = gpio_get(pin)) {
count++;
sleep_us(1);
};
printf("DHT Confirmation HIGH: %d\n", count); // EXPECT HIGH 80us
}
Failed to read from DHT sensor!
. The sensor was broken, and all that time wasted.Humidity: 46.00% Temperature: 24.30°C 75.74°F Heat index: 23.99°C 75.18°F
sleep
for the amount of time as specified by the sensor, but I could not get it done. Investing further project time to study the timing effects of the various statements in my code - like what is the impact of the counter, and what of the printf - was also not working.22