Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

OPi PC+ and MH-Z19

Featured Replies

Hi everyone.

I almost gave up while reading tons of forums:(

I bought CO2 sensor MH-Z19 from aliexpress.

As I figured out this sensor used by RPi without any problems. Manual I found here:

https://www.circuits.dk/testing-mh-z19-ndir-co2-sensor-module/

I connected module as mentioned:

Vin - 2 pin gpio
GND - 9 pin
Tx - 13 pin
Rx - 11 pin

Module was blinking when I powered on my OPi, but when I tried to send data to UART nothing happened. I got timeout.

I tried to connect Tx and Rx (11 and 13 pin) by cable, then sent bytes and immediatley got answer, UART work, as I understood.

I checked uart in armbian-config menu and all (1,2,3) was enabled.

Orange PI PC Plus
Linux orangepipcplus 5.4.30-sunxi #20.02.9 SMP Mon Apr 6 19:46:24 CEST 2020 armv7l GNU/Linux

Can somebody help me, please?

 

Spoiler

import serial
import time
import subprocess
import getrpimodel

serial_dev = '/dev/ttyS2'
stop_getty = 'sudo systemctl stop serial-getty@ttyS0.service'
start_getty = 'sudo systemctl start serial-getty@ttyS0.service'

def mh_z19():
    ser = serial.Serial(serial_dev,
                        baudrate=9600,
                        bytesize=serial.EIGHTBITS,
                        parity=serial.PARITY_NONE,
                        stopbits=serial.STOPBITS_ONE,
                        timeout=1.0)
    while 1:
        s=ser.read(9)
        result=ser.write("\xff\x01\x86\x00\x00\x00\x00\x00\x79")
        s=ser.read(9)
        print(s)
        if len(s) >= 4 and s[0] == "\xff" and s[1] == "\x86":
            return {'co2': ord(s[2])*256 + ord(s[3])}
        break

def read():
    p = subprocess.call(stop_getty, stdout=subprocess.PIPE, shell=True)
    result = mh_z19()
    p = subprocess.call(start_getty, stdout=subprocess.PIPE, shell=True)
    if result is not None:
        return {'CO2': result["co2"]}

if __name__ == '__main__':
#  value = mh_z19()
#  print "co2=", value["co2"]
    value = read()
    if value is not None:
        print "co2=", value["CO2"]
    else:
        print "None"

 

 

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.