LowPowerLab Forum

Hardware support => Moteino => Topic started by: diverdale on January 08, 2015, 01:02:01 PM

Title: DHT11 different values
Post by: diverdale on January 08, 2015, 01:02:01 PM
I have a couple of Moteinos I'm planning on using for sensor nodes.  Everything works with the communication and such.  I started playing with powerDown last night and noticed that I get different Temp values from the sensor Mote that I put to sleep vs the  one I don't.  The sleepy one gets a cpl degrees F higher reading.  I swapped the DHT11s physically and the numbers follow the powerDown code.  I added a delay before reading the sensor but still getting the issue.  I have both of the Motes on my bench within mm of each other so I would expect the same reading. Here's the code snippet:


void loop() {   

    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
 
    //fill in the struct with new values
    theData.nodeId = NODEID;
    theData.sensorID = SENSORID;
    theData.var1_usl = millis();
    theData.var2_float = dht.readTemperature(true); // send Farenheit
    theData.var3_float = dht.readHumidity();
    Serial.print("Sending struct (");
    Serial.print(sizeof(theData));
    Serial.print(" bytes) ... ");
    if (radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)))
    {
      Serial.print(" ok!");
      radio.sleep();
    }
    else Serial.print(" nothing...");
    Serial.println();
    Blink(LED,3);
}


Any suggestions?

Thanks,
Dale
Title: Re: DHT11 different values
Post by: TomWS on January 08, 2015, 02:47:40 PM
It isn't clear which DHT library you're using and I haven't used the DHT11 so I'm not sure how different it from the DHT22, which I do use.

In my set up I used a stripped down version of the adafruit DHT-sensor library and I power the DHT device from a Moteino output pin.  Before I 'sleep', I power down the device and, when I come out of sleep, ready to sample, I power up the DHT22 and then wait a full 2 seconds plus the various delays built into the library, before reading the device.  With this setup I get VERY consistent results.

Tom
Title: Re: DHT11 different values
Post by: diverdale on January 08, 2015, 03:38:47 PM
I'm using the Adafruit library.  Could would you be able to post a code snip where you sleep and wake up/read? 

Thanks,
Dale
Title: Re: DHT11 different values
Post by: TomWS on January 08, 2015, 05:25:05 PM
Quote from: diverdale on January 08, 2015, 03:38:47 PM
I'm using the Adafruit library.  Could would you be able to post a code snip where you sleep and wake up/read? 

Thanks,
Dale
Attached is the library I've made from the adafruit library.  Here's the salient sketch code:

...other includes
#include <DHTtws.h>

DHTtws th(6,DHT22,6,7);   // uses pin 6 as signal, its a DHT22, uses default 'count', pin 7 as pwr

  //============================================================================
  //============================================================================
void setup(void)
{
// other setup stuff here...
//

  th.begin();   // start TH Monitor
 
  Serial.begin(SERIAL_BAUD);
 
  thMote.initialize();
 
}

void loop(void)
{
    //... a bunch of gorpy stuff here...
    // then the sampling code finished off with sleeping
    th_data.temperature = th.readTemperature();
    th_data.humidity = th.readHumidity();
   
    TwsMoteHeader tmDataIn=TM_H_INIT(TM_DATA_IN);
    thMote.beginPacket(tx_buf, &tmDataIn.h);   // encapsulate our data packet into a DataIn packet
    thMote.buildPacket(tx_buf, &th_data.h);
    thMote.sendPacket((TwsMoteHeader*)tx_buf);
    byte *pAck = thMote.getAckData();
    if (pAck)
    {
    // got something, parse the packet
      parseRecvPacket(pAck, thMote.GATEWAYID, thMote.MY_DEVICE_ID, pAck[0]); 
    }
   
    while (now < stayAwake) {   // we got something that wants us to stay awake for a bit longer, let's see what we're getting!
    now = millis();
    radioCheckIn(rx_buf);
    }
   
    th.sleep();            // put TH sensor to off
    thMote.radio.sleep();  // put radio to sleep

    Serial.flush();        // flush any residual crap in Serial port
    sleep.pwrDownMode();   //set sleep mode
    sleep.sleepDelay(sleepTime); //sleep for: sleepTime
    th.begin();            // waking up, restart sensor (radio restarts on transmit)
}


Let me know how it works with the DHT11 if you try it.
Tom