I got this code, and it works perfectly on a Arduino Duemilanove. I got the sensor attached to a Electronic Brick Chassis V1.1 shield, and when I move that shield to my Seeeduino Mega, I only get "dht11 start condition 1 not met".
I am not entirely sure what this code actually does, only that it works on my Duemilanove, and on the same pin on the mega wont work.
Anyone of your smart heads out there that can figure out what is going on, and maybe know what the pin difference is between the two?
#define DHT11_PIN 5 // ADC0
byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN))
{
result |=(1<<(7-i));
}
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
void setup()
{
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
Serial.begin(9600);
Serial.println("Ready");
Serial.print("$CLEAR\r\n");
}
void loop()
{
byte dht11_dat[5];
byte dht11_in;
byte i;
// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);
dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in)
{
Serial.println("dht11 start condition 1 not met");
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in)
{
Serial.println("dht11 start condition 2 not met");
return;
}
delayMicroseconds(80);
// now ready for data reception
for (i=0; i<5; i++)
{
dht11_dat[i] = read_dht11_dat();
}
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.print("$CLEAR\r\n");
Serial.print("$GO 1 2\r\n");
Serial.print("$PRINT Checksum error\r\n");
delay(1000);
}
else
{
if (millis() < 10000) //Waiting to skip the first fast jumping numbers
{
Serial.print("$GO 1 1\r\n");
Serial.print("$PRINT Collecting...\r\n");
Serial.print("$GO 2 1\r\n");
Serial.print("$PRINT ");
Serial.print(map(100,0,10000,0,millis()));
Serial.print("%\r\n");
delay(100);
}
else
{
Serial.print("$GO 1 1\r\n");
Serial.print("$PRINT Humdity ");
Serial.print(dht11_dat[0], DEC);
Serial.print("%\r\n");
Serial.print("$GO 2 1\r\n");
Serial.print("$PRINT Temperature ");
Serial.print(dht11_dat[2], DEC);
Serial.print("C\r\n");
}
delay(500);
}
}
The sensor: http://www.seeedstudio.com/depot/electronic-brick-indoor-temp-humidity-sensor-p-683.html?cPath=48_52