Hi All
Ordered a MH-Z19B NDIR CO2 sensor from flea bay
After looking at the data sheet https://www.winsen-sensor.com/d/files/MH-Z19B.pdf
I hooked it up to a 28x2 with the following code, but not recieving any data back
The data sheet state that interface volltage is 5v compatable or should I use a logic level shift converter on RX and TX
I have tried the baud rate as N9600 and T9600 with either not returning values
Or is the code interpritation of the data sheet skew wiff
regards john
Ordered a MH-Z19B NDIR CO2 sensor from flea bay
After looking at the data sheet https://www.winsen-sensor.com/d/files/MH-Z19B.pdf
I hooked it up to a 28x2 with the following code, but not recieving any data back
Code:
#no_data
#no_table
symbol byte0=w1
symbol byte1=w2
symbol byte2=w3
symbol byte3=w4
symbol byte4=w5
symbol byte5=w6
symbol byte6=w7
symbol byte7=w8
symbol byte8=w9
symbol checksum=w10
symbol PPM=w11 symbol lsb=b22 symbol msb=b23
symbol Co_braud=T9600
symbol RX=C.2'connected to TX MH-X19B pin6
symbol TX=C.3'connected to RX MH-X19B pin7
' MH-Z19B NDIR CO2 Module
' Commands
' 0x86|read CO2 concentration
' 0x87|calibrate zero point (zero)
' 0x88|calibrate span point (span)
' 0x79|on/off self calibrate for zero point
' 0x99| detection range (PPM)
' Byte8 is the checksum Add together byte1 to byte7(var checksum)
' checksum= 0xFF-checksum
' checksum=checksum+1
pre_heat:
sertxd(" pre heat",cr,lf)
for b0=0 to 29
pause 6000
sertxd("b0= ",#b0,cr,lf)
next b0
sertxd("leaving pre heat",cr,lf)
inti:
high tx
pause 5 'by0 by1 by2 by3 by4 by5 by6 by7 by8
serout TX,Co_braud,($FF,$01,$79,$00,$00,$00,$00,$00,$86)'self calibration off
sertxd("self calibration sent",cr,lf)
pause 200
serout TX,Co_braud,($FF,$01,$99,$00,$00,$00,$07,$D0,$8F)'limit PPM to 0 to 2000 via byte2 $99
sertxd("PPM range sent",cr,lf)
pause 200
main:
do
serout TX,Co_braud,($FF,$01,$86,$00,$00,$00,$00,$00,$79)'read command
sertxd("read command sent",cr,lf)
serin RX,Co_braud,(byte0,byte1,PPM,byte3,byte4,byte5,byte6,byte7,byte8)
gosub verify
pause 2000
loop
verify:
sertxd("in verify",cr,lf)
checksum=checksum+byte1:checksum=checksum+PPM:checksum=checksum+byte3:checksum=checksum+byte4:checksum=checksum+byte5:checksum=checksum+byte6:checksum=checksum+byte7
checksum=$FF-checksum
checksum= checksum+1
if checksum=byte8 then
sertxd("Read sucessful",cr,lf)
elseif checksum<>byte8 then
sertxd("Read fail Csum= ",#checksum," byte8= ",#byte8,cr,lf)
endif
PPM=PPM*256+byte3
b1 = PPM / $10 + "0" : If b1 > "9" Then : b1 = b1 + 7 : End If
b0 = PPM & $0F + "0" : If b0 > "9" Then : b0 = b0 + 7 : End If
sertxd(#b1,#b0," PPM",cr,lf)
return
I have tried the baud rate as N9600 and T9600 with either not returning values
Or is the code interpritation of the data sheet skew wiff
regards john