Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DHT22 temperature sensor doesn't send data
03-10-2015, 03:04 PM,
#1
DHT22 temperature sensor doesn't send data
Hello guys:

I'd like to make my termometer with Pinguino Board and temperature sensor DHT22.
I found (in this forum) a library to work with the sensor, but I have some troubles.

Electrical connection is (same as arduino projects):

[Image: arduino-dht22-temperature-hookup.svg]

I've tried a lot of things:
  • If I use Vcc=5V and digital pin for data input, I think it doesn't work because digital pin voltage is 3,7V. Output is:
       Humidity: 0.00 Temperature: 0.00   Humidity: -107374184.00 Temperature: 0.00
  • If I user Vcc = 3,7v (digital pin), it doesn't work again.
I imagine that the problems was start signal from MCU/Sensor, so I tried to see what sensor gave me:

Code:
/*-----------------------------------------------------
Author: --<>
Date: 2015-09-30
Description:

-----------------------------------------------------*/
#include <printf.c>
#include <delay.c>
#define CDCPRINTF
#define CDCPRINT

#define VCCPIN 7 //Pin #7 Vcc
#define DHTPIN 8 //Pin #8 (por ejemplo)
#define MCU_INI_LOW 1100 //MCU Low 1ms minimum
#define MCU_INI_HIGH 40 //MCU High 20-40us

void setup() {
// Pinguino starts. Mantenemos la alimentación a Vcc durante 1 segundo.
CDC.print("Test sensor DHT22:\n");
CDC.print("Pin 7 = Vcc, Pin 8 = DATA:\n");
pinMode(USERLED, OUTPUT);
}

void loop() {
//variables
u32 curTime;


pinMode(VCCPIN, OUTPUT);
digitalWrite(VCCPIN, HIGH);
CDC.print("High voltage Vcc\n");
delay(1100);
//INI-Inicialización del sensor. El host, por el pin de datos, debe:
//1. Voltaje LOW durante al menos 1ms
//2. Voltaje HIGH durante al menos 20-40 us
CDC.printf("PIN %d - Host signal LOW\n", DHTPIN);

pinMode(DHTPIN,OUTPUT); //Se activa como salida
digitalWrite(DHTPIN,LOW);//LOW voltage para activar el sensor
Delayus(MCU_INI_LOW); //Este delay es para esperar el tiempo recomendado para acceder al sensor (1 segundo = 1000ms). También con Delayms(ms);

CDC.printf("PIN %d - Host signal HIGH\n", DHTPIN);
digitalWrite(DHTPIN,HIGH); //LOW voltage para activar el sensor
Delayus(MCU_INI_HIGH); //delay.c. Otherwise delayMicroseconds() in pinguino.pdl32

digitalWrite(USERLED, LOW);
pinMode(DHTPIN,INPUT); //Cambio a pin de entrada de datos
//Señal de inicio de transferencia de datos por parte del sensor
//80us LOW, 80us HIGH

int i =0;
int data = 0;
int data_1=0;
int isFirst = 1;
while (i<1000){
if( digitalread(DHTPIN) ){
data=1;
}else{
data=0;
}
if (isFirst==1){
CDC.printf("First %d - %d\n", i, data);
isFirst = 0;
}else if (data_1 != data){
CDC.printf("%d - %d\n", i, data);
}
data_1 = data;
i++;

}
CDC.print("sale del bucle\n");
delay(5000);
digitalWrite(VCCPIN, LOW);

}

Output is quite weird:

Code:
High voltage Vcc

PIN 8 - Host signal LOW
PIN 8 - Host signal HIGH
First 0 - 1
1 - 0
49 - 1
50 - 0
51 - 1

High voltage Vcc

PIN 8 - Host signal LOW
PIN 8 - Host signal HIGH
First 0 - 0
29 - 1
56 - 0
57 - 1
68 - 0
84 - 1
sale del bucle

High voltage Vcc
PIN 8 - Host signal LOW
PIN 8 - Host signal HIGH
First 0 - 0
1 - 1
6 - 0
15 - 1
16 - 0
17 - 1
18 - 0
19 - 1
sale del bucle

It should provide two bits for data init (0, 1) and then 16bits humidity, 16bits temperature and 8 bits checksum.
Instaed of that, it provides High voltage (1) from a random point.

Does anyone know why this behaviour? Is Code wrong in any point? Don't I understand something in DHT22 datasheet?

Thank you a lot,

machocastellano.
Reply
08-10-2015, 05:42 PM,
#2
RE: DHT22 temperature sensor doesn't send data
Hi,

1/ no #include in your code (the IDE will add them automatically)
2/ replace Delayus with delayMicroseconds (to keep the compatibility with the Arduino syntax)
3/ I found this : https://github.com/emmertex/DHT22-Library
I hope it helps, if it works, please share.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)