I’m trying to read temperature and humidity from a DHT22 sensor on an Argon board.
I’ve tried two different libraries: Adafruit and PietteTech.
The former returns temperature=nan and humidity=0.0. The latter always returns -3.0.
To @ScruffR 's point, you need to do an acquireAndWait() prior to trying to access the temperature and humidity readings.
You might want to post a snippet of your code that’s reading the values.
FWIW, here are some snippets of code I use in one of my several programs used for DHT22’s:
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN D1 // Digital pin for communications
//declarations
void dht_wrapper(); // must be declared before the lib is initialized
//Lib instantiate
PietteTech_DHT DHT(DHTPIN,DHTTYPE, dht_wrapper);
void readSensor() {
//read temperature and humidity from DHT22 sensor
gLastRead = gNow;
Log.info("readSensor entered");
int result = DHT.acquireAndWait();
delay(1000);
Log.info("after acquireAndWait");
gResult = result;
switch (result) {
case DHTLIB_OK:
Log.info("DHT OK");
gHumidity = DHT.getHumidity();
gTemperature = DHT.getFahrenheit();
Log.info("Temp: %.1f, Humidity: %.1f",gTemperature,gHumidity);
break;
case DHTLIB_ERROR_CHECKSUM:
Log.info("Error--Checksum error");
break;
case DHTLIB_ERROR_ISR_TIMEOUT:
Log.info("Error--ISR time out error");
break;
case DHTLIB_ERROR_RESPONSE_TIMEOUT:
Log.info("Error--Response time out error");
break;
case DHTLIB_ERROR_DATA_TIMEOUT:
Log.info("Error--Data time out error");
break;
case DHTLIB_ERROR_ACQUIRING:
Log.info("Error--Acquiring");
break;
case DHTLIB_ERROR_DELTA:
Log.info("Error--Delta time to small");
break;
case DHTLIB_ERROR_NOTSTARTED:
Log.info("Error--Not started");
break;
default:
Log.info("Unknown error");
break;
}
if(gResult!=DHTLIB_OK) {
gErrorCode = result;
Log.info("Failed to read from DHT sensor!");
delay(5000);
}
}
@vault , what’s the part number of that sensor? I’ve used the DHT22 (from Adafruit and others) without issue with the code I have above. The only time I’ve had issues is if the sensor is bad (very rare).
Hmmm…the ones I’ve used do not have the small PCB protruding from the bottom–just 4 leads (VCC, Gnd, Data, and NC). Having looked a bit at Amazon, it appears some folks had trouble when powering these with 3.3 Vdc and had better success at 5Vdc. Might be work trying. If you’ve powered it in reverse by accident, it’s likely smoked.
There are several offerings on Amazon, so I’m not sure I’m looking at the exact same one that you’re using.
Actually I’ve had problems with VUSB and reverted to 3.3V: the board was freezing after some minutes (the loop stopped and it was no longer doing its job), and I read that the cause was using 5V instead of 3.3V… Never happened to you?