This is just some simple code as example
now as mentioned before, everything works fine when set to the default settings but soon as as i change the timer 0 to 1 and do the below it the DHT11 doesn't work.
according to the link i posted i should change the wiring.c code to get it to count at the correct speed however changing this files does nothing. ( im not to worried about that as long as the DHT11 will work)
interestingly i've change the second timer to "1" and while it works after a while it starts giving incorrect information back
#define DHT11_PIN 0 // ADC0 humididty
long fixtimer;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args) write(args);
#else
#define printByte(args) print(args,BYTE);
#endif
uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8] = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8] = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
byte read_dht11_dat()// humididty
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds((30 * fixtimer));
if(PINC & _BV(DHT11_PIN))
result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
void setup()
{
TCCR0B = TCCR0B & 0b11111000 | 1;
fixtimer = 64;
DDRC |= _BV(DHT11_PIN); // Hum
PORTC |= _BV(DHT11_PIN); //Hum
Serial.begin(9600); //hum
Serial.println("Ready"); //hum
// Serial.begin(57600);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.createChar(0, bell);
lcd.createChar(1, note);
lcd.createChar(2, clock);
lcd.createChar(3, heart);
lcd.createChar(4, duck);
lcd.createChar(5, check);
lcd.createChar(6, cross);
lcd.createChar(7, retarrow);
lcd.home();
lcd.setCursor(0, 0);
for(int i = 0;i < 20; i++) lcd.printByte(6);
lcd.setCursor(0, 1);
lcd.printByte(6);
lcd.print(" Hello world ");
lcd.printByte(6);
lcd.setCursor(0, 2);
lcd.printByte(6);
lcd.print(" i ");
lcd.printByte(3);
lcd.print(" Adele ! ");
lcd.printByte(6);
lcd.setCursor(0, 3);
for(int i = 0;i < 20; i++) lcd.printByte(6);
// lcd.clear();
}
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 * fixtimer));
PORTC |= _BV(DHT11_PIN);
delayMicroseconds((40 * fixtimer));
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds((40 * fixtimer));
dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in)
{
Serial.println("dht11 start condition 1 not met");
return;
}
delayMicroseconds((80 * fixtimer));
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in)
{
Serial.println("dht11 start condition 2 not met");
return;
}
delayMicroseconds((80 * fixtimer));// 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.println("DHT11 checksum error");
}
lcd.setCursor(0, 0);
lcd.print(dht11_dat[0], DEC);
lcd.setCursor(0, 2);
lcd.print(dht11_dat[2], DEC);
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");
delay((2000 * fixtimer));
}