1 Reply Latest reply on May 12, 2015 8:31 AM by DiegoV_Intel

    How can I test DHT11 sensor on edison+arduino board?

    yehong

      sensor: Temperature and Humindity Sensor (model name: DHT11)

      board: base shield on Edison+arduino expand board

      connection: GPIO 4

      result:Data not good, skip

      what's wrong?

       

      void DHT11::SetDHT11(int pin) {

        uint8_t laststate = HIGH;

        uint8_t counter =0;

        uint8_t j =0, i;

        float f;

       

        dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;

       

        dht11 = new mraa::Gpio(pin);

        dht11->dir(mraa::DIR_OUT);

        //dht11->mode(mraa::MODE_PULLDOWN);

        dht11->write(LOW);

        sleep(20/1000); //18);

       

        dht11->write(HIGH);

        usleep(40);

       

        dht11->dir(mraa::DIR_IN);

        //dht11->mode(mraa::MODE_PULLUP);

       

        for ( i = 0; i < MAXTIMINGS; i++ ) {

        counter =0;

        while(dht11->read() == laststate) {

        counter++;

        usleep(1);

        if(counter ==255) {

        break;

        }

        }

        if ( (i >= 4) && (i % 2 == 0) ) {

        dht11_dat[j / 8] <<= 1;

        if ( counter > 16 )

        dht11_dat[j / 8] |= 1;

        j++;

        }

        }

       

        if ( (j >= 40) &&

            (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) )

        {

        f = dht11_dat[2] * 9. / 5. + 32;

       

       

        printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",

        dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f );

        }else  {

        printf( "Data not good, skip\n" );

        }

      }