1

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.

Update:

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)
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)

Run

$ python read.py 
Writing bytes
Sleeping 2 seconds
Reading bytes
Response
b''

Picture of wiring to Raspberry Pi 2

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
    Jun 15 at 12:55
  • Ah, yes. That's still a leftover from trying it through a USB-UART adapter. I will change the code though. Jun 15 at 12:56
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!

2
+100

As an alternative, try sending the following sequence:

"\xFE\x44\x00\x20\x01\xC1\x24"

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.

1
  • 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! Jun 24 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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