Skip to content
Dr. Takeyuki Ueda edited this page Apr 9, 2024 · 19 revisions

Install

pip install mh_z19

Import

import mh_z19

1. Measure Functions

Read CO2 concentration and return as following json string: {'co2': 583}

Read CO2 consentration and undocumented other values.

read_from_pwm(gpio=12, range=5000)

Read CO2 value from PWM interface, not Serial port.

params:

gpio: The gpio pin number for reading. the numbering is by BCM system. The default value is 12. range: The range value to pass to the sensor module. The default vaule is 5000.

checksum(array)

Compute the Checksum for the array of int value and return as packed value for unsigned char

2. CALIBRATION & detection range functions

I'm afraid the following functions are not tested due to the lack of necessary devices and apparatus for the test. I'll really appreciate it if some kind person who has the necessary stuff tries following functions and tell me the result as a issue report, thank you!

The command 0x79 ON/OFF Auto Calibration on the Software Section on the DataSheet. This function set ABC as ON.

The command 0x79 ON/OFF Auto Calibration on the Software Section on the DataSheet. This function set ABC as OFF.

span_point_calibration(span, serial_console_untouched=False)

The command 0x88 Calibrate Span Point (SPAN) on the Software Section on the DataSheet.

zero_point_calibration(serial_console_untouched=False)

The command 0x87 Calibrate Span Point (ZERO) on the Software Section on the DataSheet.

detection_range_10000(serial_console_untouched=False)

The command 0x99 Detection range setting on the Software Section on the DataSheet. This function set range as 10000.

detection_range_5000(serial_console_untouched=False)

The command 0x99 Detection range setting on the Software Section on the DataSheet. This function set range as 5000.

detection_range_2000(serial_console_untouched=False)

The command 0x99 Detection range setting on the Software Section on the DataSheet. This function set range as 2000.

3. parameter serial_console_untouched for the functions using serial port

In default, the default serial port on the Raspberry Pi is occupied by the serial console for debugging. To send commands to sensor module via serial port, need to rent serial port from the serial console as stop serial console temporary during send command and read a response, then reopen serial console.

If you are using the serial port, or you've stopped the serial console by yourself, the temporal stopping of the serial console is meaningless or harmful in some cases. In these case, set this param as true.

4. Serial device used to communicate with sensor module

default

In default, serial device selected automatically as follows:

  • /dev/serial0 if exist
  • or else
    • /dev/ttyS0 in case RPi model is 3 Model B, 4 Model B or "Zero W"
    • or else /dev/ttyAMA0

-code

set_serialdevice(device)

Set serial device file passed by parameter to use. Parameter device is a string of full path device file name like /dev/ttyAMA0.

-code