Hello everyone, i have recently started tinkering with arduinos attinys and anything of the sort. For the past month or so i have been trying to make an attiny 85 work with the dht22 sensor. The DHT22 works perfectly well with my arduino both using serial and an lcd to output the readings. With the attiny though it only outputs the correct readings when using serial. When i try to output the readings in the lcd (using a shift register) it shows bad readings (-99.9 or something for both humidity and temperature) and says there is a timeout error. As you can see from my code below in both circumstances i have put many delays so that i will be sure the 2 second between readings rule is followed. I would really appreciate the help from anyone who might know something.
My working code on arduino:
#include "DHT.h"
#include <LiquidCrystal595.h>
DHT dht;
LiquidCrystal595 lcd(0,1,2);
float maxt = 0.0;
float maxh = 0.0;
float mint = 100.0;
float minh = 100.0;
void setup() {
lcd.begin(16,2);
dht.setup(3);
}
void loop() {
delay(dht.getMinimumSamplingPeriod());
delay(3000);
float h = dht.getHumidity();
float t = dht.getTemperature();
lcd.clear();
if (maxh < h) {
maxh = h;
}
if (maxt < t) {
maxt = t;
}
if (minh > h) {
minh = h;
}
if (mint > t) {
mint = t;
}
if (isnan(t) || isnan(h)) {
lcd.print("Failed to read from DHT");
} else {
lcd.print("Humidity: ");
lcd.print(h);
lcd.setCursor(0, 1);
lcd.print("Temperature:");
lcd.print(t);
delay (10000);
lcd.clear();
lcd.print("Max Humidity: ");
lcd.setCursor(0, 1);
lcd.print(maxh);
delay (2500);
lcd.clear();
lcd.print("Max Temperature:");
lcd.setCursor(0, 1);
lcd.print(maxt);
delay (2500);
lcd.clear();
lcd.print("Min Humidity: ");
lcd.setCursor(0, 1);
lcd.print(minh);
delay (2500);
lcd.clear();
lcd.print("Min Temperature:");
lcd.setCursor(0, 1);
lcd.print(mint);
delay (2500);
lcd.clear();
}
}
And this is the code that is not workin g on the attiny (the exact same code works in serial but not on lcd)
Also i want to be able to have minimum and maximum shown if this makes any difference.
#include <dht.h>
#include <LiquidCrystal595.h>
dht DHT;
LiquidCrystal595 lcd(0,1,2);
#define DHT22_PIN 3
void setup()
{
delay (3000);
lcd.begin(16,2);
lcd.println("DHT TEST PROGRAM ");
lcd.print("LIBRARY VERSION: ");
delay(1000);
lcd.clear();
lcd.println(DHT_LIB_VERSION);
lcd.println();
delay(1000);
lcd.clear();
lcd.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
delay (3000);
// READ DATA
lcd.print("DHT22, \t");
lcd.clear();
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK:
lcd.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
lcd.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
lcd.print("Time out error,\t");
break;
default:
lcd.print("Unknown error,\t");
break;
}
delay (3000);
lcd.clear();
// DISPLAY DATA
lcd.print(DHT.humidity, 1);
lcd.print(",\t");
lcd.println(DHT.temperature, 1);
delay(1000);
}
Thank you all in advance