I bought a SenseAir S8 LP to connect to a Raspberry Pi 2. The specification shows the pins and how I should connect them. I have verified that the pins are connected properly (see image below).
As for the Pi, I have ensured that the serial port is enabled using
raspi-config. I've had other sensors connected to the same Pi, and there the code worked.
Example codes of how to read out the sensor are abundant, so I tried nearly all the ones I could find. Below is a minimal piece of code that should work. I've been trying all sorts of byte sequences to get the sensor to return something, but it never returns anything.
I'm starting to think that this sensor is simply broken.
I have gone through the documentation a bit more and understand that the following sequence of bytes should be a valid instruction:
0xFE, 0x04, 0x00, 0x00, 0x00, 0x01
0xFE: Any address
0x04: Read register instruction
0x00: Start address high bits
0x00: Start address low bits
0x00: Amount of registers high bits
0x01: Amount of registers low bits
The CRC check in the documentation helped me determine that the CRC check is "CRC-16/MODBUS", which can be computed here. So that gives me
0xC525. I have to put the low bits first and then high bits, so that gives me a total instruction of
0xFE, 0x04, 0x00, 0x00, 0x00, 0x01, 0x25, 0xC5
Additionally I have tried COMTool (https://pypi.org/project/COMTool/), but that didn't work either.
So, what am I doing wrong here?
import time import serial s = serial.Serial("/dev/serial0", timeout=1, baudrate=9600, stopbits=serial.STOPBITS_ONE, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS) s.reset_input_buffer() s.reset_output_buffer() print("Writing bytes") # Source: https://co2meters.com/Documentation/AppNotes/AN168-S8-raspberry-pi-uart.pdf # https://joshefin.xyz/measure-co2-with-senseair-s8-raspberry-pi-java/ #s.write(b"\xFE\x44\x00\x08\x02\x9F\x25") # Source: https://rmtplusstoragesenseair.blob.core.windows.net/docs/Dev/publicerat/TDE2067.pdf #s.write(b"\xFE\x00\x03\x00\x01\xD4\xC5") # Source: http://www.co2meters.com/Documentation/AppNotes/AN162-LP8-sensor-arduino-modbus-uart.pdf s.write(b"\xFE\x44\x00\x80\x20\x79\x3C") print("Sleeping 2 seconds") time.sleep(2) print("Reading bytes") response = s.read(7) print("Response") print(response)
$ python read.py Writing bytes Sleeping 2 seconds Reading bytes Response b''