Skip to content

100% nan when using Ticker #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TinkerFu opened this issue Apr 12, 2018 · 1 comment
Closed

100% nan when using Ticker #103

TinkerFu opened this issue Apr 12, 2018 · 1 comment

Comments

@TinkerFu
Copy link

TinkerFu commented Apr 12, 2018

This is on an esp8266.

Went from polling sensor every 30 seconds via delay(30000) to using a Ticker. 100% failure.
I've even removed all wifi code down to just a ticker.

#include <DHT.h>
//#include <ESP8266WiFi.h>
//#include <ESP8266HTTPClient.h>
#include <Ticker.h>

#define DHTTYPE DHT22   // DHT 11
const int DHTPin = 2;

DHT dht(DHTPin, DHTTYPE);
Ticker sensor1;

void setup () {
 
  Serial.begin(115200);
  delay(10);
  sensor1.attach(30.0, getReadings);
}
 
void loop() {
}

void getReadings() {
      dht.begin();
      delay(50);
      float h = dht.readHumidity();
      float f = dht.readTemperature(true);

      if (isnan(h) || isnan(f)) {
        Serial.println("Failed to read from Sensor!");      
      }
      else{
        Serial.print("Humidity: ");
        Serial.print(h);
        Serial.print(" %\t Temperature: ");
        Serial.print(f);             
        Serial.println(" *F");
      }

}

I enabled debug:

    Max clock cycles: 80000
    Timeout waiting for start signal low pulse.

I've used this #48 as a reference but even after applying fix it still fails every time. Relevant section of my DHT.cpp

    // End the start signal by setting data line high for 40 microseconds.
    //digitalWrite(_pin, HIGH);
    //delayMicroseconds(40);

    // Now start reading the data line to get the value from the DHT sensor.
    pinMode(_pin, INPUT_PULLUP);
    delayMicroseconds(50);  // Delay a bit to let sensor pull data line low.

Same board works fine if the read code is put in main loop.

@PaintYourDragon
Copy link
Contributor

Try newest library - reopen if still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants