I’m trying to use the PietteTech_DHT library to read a DHT22 on my raspberry pi 3.
I’ve verified I can read data off the sensor outside of the particle-agent using the Adafruit_DHT python lib, but am getting read timeout errors using the PIetteTech lib and particle-agent.
I’ve tried modifying the timeout for reads and changing pins to no avail.
What version of the lib are you using and how do you read (sync via dht.acquireAndWait(1000) or async via dht.acquire())?
Since that lib uses interrupts to do the async reading, and I can’t really find any docs about attachInterrupt() for RPi, I’m not sure you can read async.
Maybe @jvanier can chime in on the plans on interrupts on RPi.
Update:
As I’ve just confirmed with @jvanier, currently interrupts are not supported via the Particle framework on RPi and it’s a low priority issue too.
So you’ll have to go for a non-interrupt driven library on the RPi for now.
I was just reading your post as I am about to start working with a Particle Pi.
On Photons, I have used below sketch for a long time, as it needs no library and no interrupts.
It may help you to run it on the Particle Pi.
STARTUP(WiFi.selectAntenna(ANT_AUTO)); // FAVORITE: continually switches at high speed between antennas
char str[255]; // String for publishing events
// *D6 - RoomSense TEMP/HUM
#include "math.h" // to calculate mathematical functions!
int THpin = D6;
double ROOMTemp2;
double ROOMHumi;
double ROOMTdf; // Dewpoint temperature
int SafeMargin = 5; // Safety margin between Dewpoint and Set Minimum temperature.
double ROOMTout; // We can safely let the room temperature sink to this level when nobody is home for a long time.
unsigned int loopCnt;
unsigned long xtime;
int bits[40] = {0};// Store sensor output train: 40 "bits" in integer format
int getTempHumInterval = 300 * 1000;
int getTempHumLastTime = millis() - getTempHumInterval;
void setup()
{
// *D6 - RoomSense TEMP/HUM
Particle.variable("ROOM_Temp2", &ROOMTemp2, DOUBLE);
Particle.variable("ROOM_Humid", &ROOMHumi, DOUBLE);
Particle.variable("ROOM_Tout", &ROOMTout, DOUBLE);
}
void loop()
{
// *D6 - RoomSense TEMP/HUM
if ((millis()-getTempHumLastTime)>getTempHumInterval)
{
ReadTempHum();
sprintf(str, "\"ROOM Temp2 + Humid + Tout\": %2.1f + %2.0f + %2.1f",ROOMTemp2,ROOMHumi,ROOMTout);
Particle.publish("Status-ROOM", str,60,PRIVATE);
// Put eventual actions/calculations with Temp & Hum here...
getTempHumLastTime = millis();
}
}
// *D6 - RoomSense TEMP/HUM
void ReadTempHum()
{
reStart:
pinMode(THpin,OUTPUT);
digitalWrite(THpin,LOW);
delay(20);
digitalWrite(THpin,HIGH);
delayMicroseconds(40);
digitalWrite(THpin,LOW);
pinMode(THpin,INPUT);
loopCnt=10000;
while(digitalRead(THpin) == LOW)
{
if(loopCnt-- == 0)
{
goto reStart;
}
}
loopCnt=30000;
while(digitalRead(THpin) == HIGH)
{
if(loopCnt-- == 0)
{
goto reStart;
}
}
for(int i=0;i<40;i++)
{
while(digitalRead(THpin) == LOW)
{
}
xtime = micros();
while(digitalRead(THpin) == HIGH)
{
}
if (micros() - xtime >50)
{
bits[i]=1;
}
else
{
bits[i]=0;
}
}
ROOMHumi = bits[6]*512+bits[7]*256+bits[8]*128+bits[9]*64+bits[10]*32+bits[11]*16+bits[12]*8+bits[13]*4+bits[14]*2+bits[15];
ROOMHumi = ROOMHumi/10;
ROOMTemp2 = bits[22]*512+bits[23]*256+bits[24]*128+bits[25]*64+bits[26]*32+bits[27]*16+bits[28]*8+bits[29]*4+bits[30]*2+bits[31];
if (bits[16]==1)
{
ROOMTemp2 = ROOMTemp2/-10;
}
else
{
ROOMTemp2 = ROOMTemp2/10;
}
// Dewpoint calculation, based on: http://en.wikipedia.org/wiki/Dew_point
double a = 17.271;
double b = 237.7;
double calc1 = (a * (double) ROOMTemp2) / (b + (double) ROOMTemp2) + log( (double) ROOMHumi/100);
ROOMTdf = (b * calc1) / (a - calc1);
ROOMTout = ROOMTdf + SafeMargin;
}