Exemplo n.º 1
0
int readRHT03 (const int pin, int *temp, int *rh)
{
    static unsigned int nextTime   = 0 ;
    static          int lastTemp   = 0 ;
    static          int lastRh     = 0 ;
    static          int lastResult = TRUE ;

    unsigned char buffer [4] ;

    // Don't read more than once a second

    if (millis () < nextTime)
    {
        *temp = lastTemp ;
        *rh   = lastRh ;
        return lastResult ;
    }

    lastResult = maxDetectRead (pin, buffer) ;

    if (lastResult)
    {
        *temp      = lastTemp   = (buffer [2] * 256 + buffer [3]) ;
        *rh        = lastRh     = (buffer [0] * 256 + buffer [1]) ;
        nextTime   = millis () + 2000 ;
        return TRUE ;
    }
    else
    {
        return FALSE ;
    }
}
Exemplo n.º 2
0
/*
 *********************************************************************************
 * dht22_read_wiring
 *
 * Making use of the wiringPiDev library. The function will only return when
 * reading the sensor is successful
 *
 *********************************************************************************
 */
int dht22_read_wiring(int r) 
{
	//int myTemp        = 0;
	//int myRelHumidity = 0;
	int attempts      = 100;
	int goodReading   = 0;
	piHiPri (10);
	while (!goodReading && (attempts-- >= 0)) {
	
		usleep(1000*10);
		if (maxDetectRead (DHT22PIN, dht22_val)) {
			goodReading = 1;
		}
				
		//if ( readRHT03(DHT22PIN, &myTemp, &myRelHumidity) == 0) {
		//	goodReading = 0;		//keep looping and try again
		//} else {
		//	goodReading = 1; 		// stop now that it worked
		//}
		usleep(1000*500);
	}
	piHiPri (0);
	//printf("Temp: %2.1fF  ",(((((float)myTemp/10)*9)/5)+32));
	//printf("RH: %2.1f%%\n",((float)myRelHumidity/10));
	humidity    = (float) (dht22_val[0]*256+dht22_val[1])/10;
	temperature = (float) (dht22_val[2]*256+dht22_val[3])/10;
	printf("%2d, humidity: %2.1f; temperature: %2.1f; WPI. ", r+1, humidity, temperature);
	return(attempts);
}