I bought a SenseAir S8 LP to connect to a Raspberry Pi 2. The specification[1] 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

Still, nothing.

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)

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/

# Source: https://rmtplusstoragesenseair.blob.core.windows.net/docs/Dev/publicerat/TDE2067.pdf

# Source: http://www.co2meters.com/Documentation/AppNotes/AN162-LP8-sensor-arduino-modbus-uart.pdf

print("Sleeping 2 seconds")

print("Reading bytes")
response = s.read(7)



$ python read.py 
Writing bytes
Sleeping 2 seconds
Reading bytes

Picture of wiring to Raspberry Pi 2

  • /dev/ttyUSB0 that doesn't look right as you're using a GPIO connection instead of USB. Probably should be /dev/serial0. Strange that you don't get any errors though
    – Dirk
    Commented Jun 15, 2021 at 12:55
  • Ah, yes. That's still a leftover from trying it through a USB-UART adapter. I will change the code though. Commented Jun 15, 2021 at 12:56

2 Answers 2


well, from what I can tell, the sensor isn't sending the data with the timeout. This isn't because the timeout is too short but because the sensor isn't sending the data so the RPi times out.

You may have to look at how the sensor is suppose to work

Hope this helps!


As an alternative, try sending the following sequence:


This should return the actual Modbus address of the module, default is 104 (0x68).

If that doesn't work, debug your Python code. I would start by getting rid of reset_output_buffer() (which discards the data, a no-op on a port you have just opened) and using flush() after write() (which forces the data to be transmitted) instead of just sleeping for 2 seconds (you should still sleep for a short time to give the module a chance to respond, 0.1s should be enough).

If you have an oscilloscope or a signal analyzer, watching the TX/RX lines would easily confirm that the bytes transmitted on the bus correspond to the sequence in your software, and whether there is a reply. If you have a sencond Pi, you could use piscope.

  • Aha, that is something interesting. I think I can debug the sensor with piscope. Since my bounty if expiring tomorrow I'm going to grant it to you right now, would be a shame otherwise. Thanks already! Commented Jun 24, 2021 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.