8 years, 2 months ago.

Nucleo w/ DHT22 temperature/humidity sensor

Hi, I'm trying to use the DHT22 temperature and humidity sensor with the Nucleo-L152RE. The wiring seems straight forward, I have a pull up resistor on the data pin.

But I'm only getting 0 values from the ReadHumidity() function call. The library I'm using is

https://developer.mbed.org/users/Wimpie/code/DHT/file/9b5b3200688f/DHT.h

include the mbed library with this snippet

#include "mbed.h"
#include "MBed_Adafruit_GPS.h"
#include "DHT.h"
 
Serial * gps_Serial;
Serial pc (SERIAL_TX, SERIAL_RX); //this is the USB serial output
DHT mydht(PB_4, DHT22); //pin 5 on nucleo
//Serial pc (USBTX, USBRX);


int main() {
    
    pc.baud(9600); //sets virtual COM serial communication to high rate; this is to allow more time to be spent on GPS retrieval

    char c;
    Timer refresh_Timer;
    const int refresh_Time = 2000; 

    
    wait(1);
    
    refresh_Timer.start();  //starts the clock on the timer
    
    while(true){

        if (refresh_Timer.read_ms() >= refresh_Time) {
            refresh_Timer.reset();
            int temperature = mydht.ReadHumidity();
            pc.printf("Satellites: %d\n", temperature);

        }
    }
}


Question relating to:

Affordable and flexible platform to ease prototyping using a STM32L152RET6 microcontroller.

1 Answer

8 years, 2 months ago.

Hi Eric,

Thanks for your question :)

A couple of things:

What value of pull up resistor are you using, id recommend 4.7K to 10k.

Have you tried this in a simple program?

Have you tried a different library? such as found here:

https://developer.mbed.org/cookbook/Grove-temperature--humidity-sensors

Regards,

Andrea, team mbed

Accepted Answer