chipKIT® Development Platform

Inspired by Arduino™

dht11

Created Thu, 08 Dec 2011 23:34:45 +0000 by shadow_of_god


shadow_of_god

Thu, 08 Dec 2011 23:34:45 +0000

i can you convert this library

http://www.ladyada.net/learn/sensors/dht.html


IGGYWOOWOO

Thu, 21 Jun 2012 01:37:20 +0000

Did you ever get this to work? I am attempting to use a DHT22 on my project, but the library does not seem to want to work. (Yes I am new to UNO 32).

I get this error: [color=#FF0040] temp_humidity.cpp.o: In function setup': C:\Users\user\AppData\Local\Temp\build5425966183673699178.tmp/temp_humidity.cpp:27: undefined reference to DHT::begin()' temp_humidity.cpp.o: In function loop': C:\Users\user\AppData\Local\Temp\build5425966183673699178.tmp/temp_humidity.cpp:33: undefined reference to DHT::readHumidity()' C:\Users\user\AppData\Local\Temp\build5425966183673699178.tmp/temp_humidity.cpp:34: undefined reference to DHT::readTemperature(bool)' temp_humidity.cpp.o: In function __static_initialization_and_destruction_0': C:\Users\user\AppData\Local\Temp\build5425966183673699178.tmp/temp_humidity.cpp:21: undefined reference to `DHT::DHT(unsigned char, unsigned char)' collect2: ld returned 1 exit status [/color]


shahrul

Sat, 23 Jun 2012 01:17:49 +0000

I have build this and function. I convert from C Language DHT11.

dht11_start();
    for(i=0;i<=4;i++) dht11[i]=dht11_byte();
    sum=(dht11[0]+dht11[1]+dht11[2]+dht11[3])&0xFF;
    if(sum==dht11[4])
    {
      humidity[0]=dht11[0];
      humidity[1]=dht11[1];
      temperature[0]=dht11[2];
      temperature[1]=dht11[3];
    }

Function

void dht11_start(void)
{
  pinMode(DHTPin,OUTPUT);
  digitalWrite(DHTPin,LOW);
  delay(25);
  digitalWrite(DHTPin,HIGH);
  delayMicroseconds(30);
  
  pinMode(DHTPin,INPUT);
  if(digitalRead(DHTPin)==LOW)
  {
    while(digitalRead(DHTPin)==LOW) continue;
  }
  while(digitalRead(DHTPin)==HIGH) continue;
}

char dht11_byte(void)
{  
  int i; 
  char value=0; 
 
  for(i=0;i<=7;i++)
  {
    while(digitalRead(DHTPin)==LOW) continue;
    delayMicroseconds(35);
    if(digitalRead(DHTPin)==HIGH)
    {
      value=value|(0x80>>i);
      while(digitalRead(DHTPin)==HIGH) continue;
    }
  }
  return value;
}