Can't show DHT22 data on screen

-deleted-
14 Oct 2016

Hi!

For a school's project, I have to collect some sensor's data and show them on a web interface (transfer with SIGFOX). I have a DISCO-L053C8 and actually I want to show DHT22's data on the board's screen.

I've begin with 2 examples (first to show something on screen and second to get sensor's data). I merged them to write temperature and humidity value on the screen but it always show "0" for the both.

After some days of trying, I ask some help of friends because they success this part. They give me them code and it simply doesn't work on my board. We have check the branch, the sensor, even cables.. all is ok. So I have no idea what could be the problem.

This is my code :

DHT22

#include "mbed.h"
#include "EPD_GDE021A1.h"
#include "DHT.h"

#define EPD_CS       PA_15
#define EPD_DC       PB_11
#define EPD_RESET    PB_2
#define EPD_BUSY     PA_8
#define EPD_POWER    PB_10
#define EPD_SPI_MOSI PB_5
#define EPD_SPI_MISO PB_4
#define EPD_SPI_SCK  PB_3
#define p21          PA_13

EPD_GDE021A1 epd(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY, EPD_POWER, EPD_SPI_MOSI, EPD_SPI_MISO, EPD_SPI_SCK);

DigitalOut myled(LED1);
DigitalOut Error(LED2);
DHT dht22(p21,DHT22);  

int main()
{  
    epd.Clear(EPD_COLOR_WHITE);  
    epd.DisplayStringAtLine(3, (uint8_t*)"LOADING...", CENTER_MODE);
    epd.RefreshDisplay();
    wait(2);

    while(1) {
        int err=dht22.readData();
        if (err==0) {
            Error=0; 
            //printf("T: %.1f C",dht22.ReadTemperature(CELCIUS));
            //printf(" H %.1f\% \n\r",dht22.ReadHumidity());
            
            char str1[5], str2[5];
            sprintf(str1, "%.1f", dht22.ReadTemperature(CELCIUS));
            sprintf(str2, "%.1f", dht22.ReadHumidity());
            
            epd.Clear(EPD_COLOR_WHITE);  
            epd.DisplayStringAtLine(5, (uint8_t*)"Weather Station", CENTER_MODE);
            epd.DisplayStringAtLine(3, (uint8_t*)"Temperature:", LEFT_MODE);
            epd.DisplayStringAtLine(3, (uint8_t*)str1, RIGHT_MODE);
            epd.DisplayStringAtLine(2, (uint8_t*)"Humidity:", LEFT_MODE);
            epd.DisplayStringAtLine(2, (uint8_t*)str2, RIGHT_MODE);
            epd.RefreshDisplay();
        }
        else {
            Error=1;
            dht22.printErr(err);
        }  
        
        myled = 1;
        wait(3);
        myled = 0;
    }
}

If I let the 29 line, the program simply didn't run on the board (no problem of compiling). If I remove it (and all line link to this var), it shows "0".

I hope I will find some help here because it's only the beginning and I'm a little pressed by time.

Thanks.