DHT22 - Senzor temperature i relativne vlažnosti vazduha
Proizvodjač: Aosong Electronics Co. Ltd.
Napon napajanja: 3.3...6 V
Izlazni signal: digitalni jednožicni, 40bits [50us + (’0’=26-28us) or (’1’=70 us)]
Opseg merenja: vlažnost 0...100 %, temperatura -40 °C...+80 °C
Rezolucija merenja: vlažnost 0.1 %, temperatura 0.1 °C
Tačnost merenja: vlažnost 2 % (max 5 %), temperatura 0.5 °C
Period merenja: 2 s
Software in C++ for Raspberry Pi
//----------------------------------------------------------------------
...
// ----- Vlaznost vazduha (%)
rh = hex_val2(buf[4],buf[5],buf[6],buf[7])*0.1;
printf("%2.1f%% ",rh);
// ----- Temperatura vazduha (C)
t = hex_val2(buf[8],buf[9],buf[10],buf[11])*0.1;
printf("%2.1fC ",t);
...
//----------------------------------------------------------------------
Software in Assembler for PIC16F876 (Q=4.096MHz), rutina se poziva na 2 sekunde
;----------------------------------------------------------------------
;Single-bus data is used for communication between PIC and DHT22
;Max time this subprogram is 6ms
DHT22_service
bsf STATUS,RP0
bcf TRISA,5 ; output
bcf STATUS,RP0
bcf PORTA,5 ; Start signal
call Delay_2ms
bsf PORTA,5
call Delay_30us
bsf STATUS,RP0
bsf TRISA,5 ; input
bcf STATUS,RP0
call Delay_160us
call Read_BYTE
movf BYTE,W
movwf RH_H ; RH_H
call Read_BYTE
movf BYTE,W
movwf RH_L ; RH_L
call Read_BYTE
movf BYTE,W
movwf T_H ; T_H
call Read_BYTE
movf BYTE,W
movwf T_L ; T_L
call Read_BYTE
movf BYTE,W
movwf DHT_CRC ; CRC
return
;- - - - - - - - - - - - - - - - - - - - - - - - - -
Read_BYTE
clrf BYTE
movlw .7
movwf count
RB_loop
clrf D1 ; D1=0
btfss PORTA,5 ; ?'1'
goto $-1
RB_loop_5
incf D1,F ; D1=D1+1, signal counter
btfsc PORTA,5 ; ?'0'
goto RB_loop_5
movf D1,W ; W=D1
sublw .7 ; W=7-W
btfss _C ; ?W
bsf BYTE,0 ; W<0,C=0,'1'
bcf _C ; W>0,C=1,'0'
rlf BYTE,f
decfsz count,f
goto RB_loop
; check the last bit
clrf D1
btfss PORTA,5
goto $-1
RB_loop_6
incf D1,F
btfsc PORTA,5
goto RB_loop_6
movf D1,w
sublw .7
btfss _C
bsf BYTE,0
bcf _C
return
;- - - - - - - - - - - - - - - - - - - - - - - - - -
Delay_2ms
movlw .12
movwf D2
L11
movlw .50
movwf D1
L10
decfsz D1,f
goto L10
decfsz D2,f
goto L11
return
Delay_30us
movlw .7
movwf D1
L1
decfsz D1,f
goto L1
return
Delay_160us
movlw .51
movwf D1
L2
decfsz D1,f
goto L2
nop
return
;----------------------------------------------------------------------
Download File:
dht22.c - Software za RPi, C izvorni kod za testiranje DHT22
dth.c - Software za RPi, C izvorni kod za testiranje DHT22, koristi wiringPi biblioteku
Šema RPI WS
Šema PIC WS
Data Sheet - DHT22.pdf
Data Sheet - AM2302.pdf
Data Sheet - AM2302.pdf