Go Down

Topic: Tm1638 gives DHT wrong value!!! (Read 1 time) previous topic - next topic

Please help,

i get my Tm1638 to work perfect and my DHT to work perfect.. same arduino, same sketch but not at the same time!

when i connect the Tm1638 the DHT gives seemingly random temp and humidity numbers (within about 10 deg C ). I can even start the sketch and get random numbers remove the tm1638 while the scetch is running and the temp and humidity will return to normal!!

does anyone have any idea why? (everything is connected as per suggested in documentation except i changed the pins for the tm1638 to pin 2 , 3 , 6 .

i checked on two tm1638 lcds. both give same results(one varies a bit more than the other).

any ideas and suggestions would be highly welcomed

rgds
Willie

robtillaart

please post your code and schematics ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ok here is the code, its just the start.. everything is just put in to get it to work i know i need to clean it up a lot!!!

The current code will serial.print the temp/humid/key pressed and float to string. so i can see whats happening.

i also found that when i set the lcd clear the temp/humid stabilizes and doesnt jump around! so i made the lcd display for 2 seconds then clear and the temp/humid continues, the first readings could be eradic but stabilizes after 2-3 readings. though temperature looks to be about 3 deg C high...

also i attached a pic of my layout...that shows exactly how the wires come together..


Code: [Select]
#include "DHT.h"
#include "TM1638.h"
#include "stdlib.h"
#include "EEPROM.h"
//EEPROM.write(a,b);The parameter a is the position 0-1023
//z = EEPROM.read(a); must be integer 0-255 nothing else!

//*****************Setup Temp Sensor*************
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
//*****************Setup LCD*********************
// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(2, 3, 6);
String Temp;
String Humid;
unsigned long time;  // for time keeping
unsigned long timeOld;
float tempOld;
float humidOld;



void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");//---------------------Serial Greet
  module.setDisplayToString(" HELLO",0);//--------------Greet me
  delay(500);
  dht.begin();//---------------------------------------Start Temp sensor
}



void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  char buffer1[10];

  //if (t != tempOld){
    tempOld == t;
    byte keys = module.getButtons();
  module.clearDisplay();
  module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));

 
//dtostrf(FLOAT,WIDTH,PRECSISION,BUFFER);
String ttd =dtostrf(t,5,2,buffer1);

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
   Serial.println(ttd);
   Serial.print("   ");
   Serial.println(keys);


if (keys == 0b00000001){  //1,2 ,4,8,16,32,64,128 // THIS IS DONE SO THE DHT CAN READ THE CORRECT TEMP.
  //module1.getButtons() == 0b00011000
   
    module.setDisplayToString(ttd);
    delay(2000);
    module.setLEDs(0x0000);
    module.clearDisplay();
  }
  if(keys== 0b10000000){
   module.setDisplayToString("TEST");
   delay(500);
  }
 
  }
 
//}
}

robtillaart

Quote
// define a module on data pin 8, clock pin 9 and strobe pin 7
TM1638 module(2, 3, 6);

code / comment conflict => code wins ;)


if t == NaN  what does dtostrf do? is it valid to make that call?
//dtostrf(FLOAT,WIDTH,PRECSISION,BUFFER);
String ttd =dtostrf(t,5,2,buffer1);


Think it is a power problem as a clear display might use just less power so:
does the LCD draw too much current so the sensor does not get enough? => what power supply do you use?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

sorry should i replace my
Code: [Select]
if (isnan(t) || isnan(h)) {
with
Code: [Select]
if t == NaN and h == NaN
??

Code: [Select]
String ttd =dtostrf(t,5,2,buffer1);
This casts a float or double to a string. I have no idea if its valid but it works ;)

I thought its a power problem too, but the LCD should use less than what arduino itself can supply, but i added a external power supply (5v,3A) but got exactly the same results.

hehe on the comment and code difference, the comment is to remind myself how it works but i changed the actual pins and code for some reason only myself at 2am in the morning knew!!

at the moment the temp difference to a thermometer is about 1 degC but i still cant use the LCD with the sensor or the sensor gives false values :(

robtillaart

Quote
should i replace my
Code:

if (isnan(t) || isnan(h)) {

with
Code:

if t == NaN and h == NaN

??

No that is just the same

Quote
I have no idea if its valid but it works smiley-wink


I think this conversion to string should only be done when the value of t is a valid number. so move the dtostrf() inside the else...

code snippet
Code: [Select]
//dtostrf(FLOAT,WIDTH,PRECSISION,BUFFER);
String ttd;

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    ttd = dtostrf(t,5,2,buffer1);
    Serial.print("Humidity: ");
etc


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Hey thanks but that isnt fixing the problem :(
i cant figure this one out :smiley-sad-blue:

robtillaart

As I don't have your hardware I cannot recreate your project.

lets see, do you have a zip of the module library, or a link as your code seems to be OK in itself.

do you have a voltmeter and did you check the voltage during operation?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Hey Rob,
here is the link to where i got the library:
http://www.ladyada.net/learn/sensors/dht.html

ive tested with both my DHT sensors and get the same results, the weird thing is i cant seem to get the sensors to work right even with the LCD disconnected :~.
Ive tried on 2 arduino's and still get values that jump around...

i changed the resistor up to 100k no change...

i dont have a working multimeter, will try and get one today and see if voltage drops...

These sensors must be accurate to like .5C but i get variations of up to 2 deg without the LCD and up to 5 - 10 with LCD conected :(

Thanks for ur time :)

Willie

robtillaart


Please try my DHT lib - http://arduino.cc/playground/Main/DHTLib - if it shows the same behavior?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

sert00

sorry for necroing soo old 3ad,but compiled on a uno this sketch,and same behaviour than user.
a strange thing after playing a bit with resistor;bein with 10k as suggested above,then 2.2k as suggested on dht11 tests at adafruit..both give me nothin,fail to read on serial monitor in arduino IDE.when i accidentally pulled up a leg of the resistor..the serial monitor begin show me real temperature and umidity.
now the dht side is ok then,but can display it well on the tm1638 based 7segments display board.
Anyone who can help me?i'm not good at programming,began studiyng C (related to arduino only)from 2 weeks myself.
Any help would be appreciated! :)

sert00

#11
Apr 08, 2013, 12:07 am Last Edit: Apr 08, 2013, 12:12 am by sert00 Reason: 1
sorry for necroing soo old 3ad,but compiled on a uno this sketch,and same behaviour than user.
a strange thing after playing a bit with resistor;bein with 10k as suggested above,then 2.2k as suggested on dht11 tests at adafruit..both give me nothin,fail to read on serial monitor in arduino IDE.when i accidentally pulled up a leg of the resistor..the serial monitor begin show me real temperature and umidity.
now the dht side is ok then,but it can't display it well on the tm1638 based 7segments display board.
1-i can see temperature on the left..but zero on the right(the humidity side i think...)for me here the problem is that i see the doble zero of for example 45.00%.i think it's to move to the right display all the hum sensing,here seems to be over the temperatures value,and i see only final numbers of humidty values.just my idea
2-what i can see (number of temperature sensing) is visible only by pushing the first push button.possible to have always displaying t and h?tried inserting some command,like serialprint or other but i had compilation error.
Anyone who can help me?i'm not good at programming,began studiyng C (related to arduino only)from 2 weeks myself.
Any help would be appreciated! :)

Docedison

Your sketch and mostly the hardware would likely work a great deal better with some bypassing (your drawing shows none) on the AM2302 and the TM1638, there I'd use a .1 and a 10 uF at the AM2302 a .1 should be enough although it could well be higher. I have a .1 uF and a 47uF cap within an inch of three AM2302's and ALL are very surprisingly accurate or at least identical and agree with a BMP085 sensor. All of this and a GPS receiver for the clock portion and all driving a 4.3" Itead color GLCD.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

sert00

thanks for the reply!
oh i missed a thing..i have a dht11,not dht22 (it's not arrived yet),also bmp85 and dallas ds18xx (don't remember names..)but used dht for the facility and because this sketch uses it.changed in the define dht to dht11,but as i sad,with resistor between data and 5v the serial monitor give "failed to read dht sensor H 0.00 T 0.00..only without it begin works as intended.strange...not?
As of now anyway i find the most accurate the dallas ds18xx...but a bit complicated to set.i awaiting the dht22\am2302 one,but as you sad and for what i red,it's very accurate and good!

Go Up