Skip to content

Commit

Permalink
Update chapter-7/TempHumidDewpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ejgertz committed Dec 2, 2011
1 parent 52ff709 commit cd90fab
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions chapter-7/TempHumidDewpoint
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,31 @@ mySerialPort.print("8888");
delay(WDelay);
mySerialPort.print("xxxx");
delay(WDelay);


}






void loop(void)
{
float tempC;
float tempF;
float humid;
float dewPoint;




DHT22_ERROR_t errorCode;


delay(2000);


errorCode = myDHT22.readData();

Serial.print(errorCode);
Expand All @@ -113,7 +125,9 @@ switch(errorCode)
dispData((int)tempC, 'C');

tempF = (tempC*1.8)+32;




delay(WDelay);
dispData((int) tempF, 'F');
delay(WDelay);
Expand All @@ -133,7 +147,9 @@ switch(errorCode)
Serial.println("d");

delay(WDelay);




break;
case DHT_ERROR_CHECKSUM:
Serial.print("Error Cheksum");
Expand All @@ -145,37 +161,43 @@ switch(errorCode)
Serial.print("Not Present");
break;
case DHT_ERROR_ACK_TOO_LONG:
Serial.print("ACK too long");
break;
case DHT_ERROR_SYNC_TIMEOUT:
Serial.print("Sync timeout");
break;
case DHT_ERROR_DATA_TIMEOUT:
Serial.print("Data timeout");
break;
case DHT_ERROR_TOOQUICK:
Serial.print("Too quick!");
break;
}




}




float calculateDewpoint(float T, float RH)
{
// approximate dewpoint using the formula from wikipedia's article on dewpoint


float dp = 0.0;
float gTRH = 0.0;
float a = 17.271;
float b = 237.7;


gTRH = ((a*T)/(b+T))+log(RH/100);
dp = (b*gTRH)/(a-gTRH);


return dp;
}



void dispData(int i, char c)
{

Expand All @@ -185,7 +207,8 @@ void dispData(int i, char c)
return;

}



if((i<-999) || (i>9999))
{
mySerialPort.print("ERRx");
Expand Down Expand Up @@ -236,6 +259,12 @@ void dispData(int i, char c)

}







/*
DHT22.cpp - DHT22 sensor library
Developed by Ben Adams - 2011
Expand Down Expand Up @@ -287,7 +316,7 @@ extern "C" {
#include <avr/pgmspace.h>
}

#define DIRECT_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask) ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask) ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask) ((*(base+2)) &= ~(mask))
Expand Down

0 comments on commit cd90fab

Please sign in to comment.