I´m just trying to get the Co2 MH-Z16 up and running. I´m using a raspberry pi 3 b+ wit a grove pi+. So far i disabeld serial communication, diabeld the blothoth on s0 and the Sensor is connected to the priser port of the grove pi+. When im using the python Co2 test script (https://github.com/DexterInd/GrovePi/tree/master/Software/Python/grove_co2_sensor) i get the following output:
_Traceback (most recent call last):_
_ File "/ directory/sensor.py", line 7, in <module>_
_ [ppm,temp]= co2.read()_
_ File "/directory/grove_co2_lib.py", line 24, in read_
_ ser.write(self.cmd_get_sensor)_
_ File "/directory/serialposix.py", line 518, in write_
_ d = to_bytes(data)_
_ File "/directory/serialutil.py", line 63, in to_bytes_
_ raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))_
_TypeError: unicode strings are not supported, please encode to bytes: 'ÿ\x01\x86\x00\x00\x00\x00\x00y'_
i came a little bit fürther… by changing the codeline in the python libary at line 13 to: cmd_get_sensor = b"\xff\x01\x86\x00\x00\x00\x00\x00\x79"
the bytes seem to be send but i get the following error message:
Traceback (most recent call last):
File "/home/pi/netzspeicher/Generic-FlashDisk-01/sensor.py", line 7, in <module>
[ppm,temp]= co2.read()
File "/home/pi/netzspeicher/Generic-FlashDisk-01/grove_co2_lib.py", line 26, in read
high_level = struct.unpack('B', self.inp[2])[0]
TypeError: a bytes-like object is required, not 'int'
so it sends data back but not in bytes but in integers, so may anyone can help me with that so i can recive bytes instead of integers?
any help is welcomed
You didn’t connect the sensor to the right port. That being the RPISER port of the GrovePi.
You didn’t switch the hardware serial port (/dev/ttyAMA0) to point to the appropriate hardware pins instead of not letting it be used by the Bluetooth - especially important on Pi3/Pi3 B+.
Something is wrong with the code.
As for making sure you’ve got the serial port configured properly, check this page. Everything is described in detail: