-
-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Hello Damien,
I tried your softuart with two (one at a time) MH-Z19 Co2 sensor https://www.winsen-sensor.com/d/files/infrared-gas-sensor/ndir-co2-sensor/mh-z19b-co2-manual(ver1_6).pdf. Doesn't work.
I did some further investigations, it reads CO2 values, but my code is very different from the commands stated in datasheet (200105).
Communication between ESP8266 and PC over FTDI UART to USB works flawless.
No it does not. The behavior is hard to describe, lets say some sequences of bytes are ok (200105).
When I hook up the sensor, the answers from MH-Z19 don't make sense. My initialization with readout goes like this:
from machine import SoftUART
from machine import Pin
import time
softuart = SoftUART(Pin(4), Pin(5), baudrate=9600, timeout=1, timeout_char=2)
time.sleep(2)
softuart.write(b"\xFF\x01\x86\x00\x00\x00\x00\x00\x79")
time.sleep(1)
r=softuart.read(9)
print(r)
FF 01 86 00 00 00 00 00 79 (command to readout)
FF 86 02 3E 46 00 00 00 F4 (answer from 1st sensor over FTDI UART)
FF 86 01 9A 00 00 00 00 DF (answer from 1st sensor over FTDI UART)
Both make sense.
b'\xff\x86\x02&G\x00\x00\x00\x0b' (answer from 1st sensor over ESP8266)
b'\xff\x86\x02XH\x00\x00\x00\xd8' (answer from 1st sensor over ESP8266)
Well.
Setting timeout to 1 gives values "closer to good". Playing with timeout_char has almost no influence.
MH-Z19 uses a STM32 µC.
Maybe you give it a try with https://github.com/plerup/espsoftwareserial which runs pretty good and is still supported. There are some examples on github which use a MH-Z19 and an ESP8266 on the Arduino platform. I'm positiv that it's possible to communicate with an ESP8266 over software UART on the Micropython platform to devices.
I really appreciate your good work.
hcet14