0

I'm using this specific CO2 sensor:

https://www.co2meter.com/products/sprintir6s-100-co2-smart-sensor?variant=43960919195846

for a school project and ultimately I'm trying get it connected to a Raspberry Pi for research purposes.

I'm trying to use a Python script to communicate with the device connected to my PC via USB currently as the device came with a USB cable that a connects to the proper leads on the board ("PWR", "GND","RX", "TX", as printed on the PCB).

The manual for the device listed here:

https://www.gassensing.co.uk/wp-content/uploads/2023/05/SprintIR-R-Data-Sheet-Rev-4.12_3.pdf

(PAGE 18) states the devices communicates using ASCII and to be honest I'm feeling a little 'in over my head'. So perhaps I should start with the python code:

import serial
import time

try:
    COM_PORT='COM3'
    ser = serial.Serial(COM_PORT, 38400, timeout=1)
    print("Serial port connected")
    time.sleep(2) # Wait for the connection to establish

    command = 'K 1\r\n'
    ser.write(command.encode('ascii'))
    time.sleep(2) # Wait for the response

    response = ser.read_all().decode('ascii')
    print("Response:", response)

except serial.SerialException as e:
    print(f"Error: {e}")

finally:
    if ser.is_open:
        ser.close()
        print("Serial port closed")

The code seems to run fine but I'm not getting any response, which looks like this

Serial Port connected
Response: 
Serial Port closed

Any help would be appreciated. Thanks!

3
  • 1
    "The code seems to run fine ..." - No, it's just not generating any visible errors nor obviously failing; that's not the same as "runs correctly". Since the command interface uses ASCII text, set aside your untested code, and verify the serial connection to the sensor with a proven terminal emulation program, such as PuTTY, TeraTerm, or (if you're desperate) Hyperterm. Commented Apr 15 at 7:09
  • Maybe start with a simpler command, such as Y\r\n, which should return the firmware version. Also, make sure you are communicating over the correct COM-port and with the correct protocol. I agree with @sawdust that using a terminal can rule out wiring and hardware errors, so that you can focus on fixing software errors. Commented Apr 15 at 9:19
  • Also, are you using a physical COM-port on your PC (which have become quite rare these days) or a COM-Port emulation? Please provide some more details. Commented Apr 15 at 9:50

1 Answer 1

0

This is two bulky for a comment. I will expand the answer once you provide more insights.

First step: Make sure you are using the correct connection settings:

print(f'Port:     {ser.portstr}')   # check if the correct port is used
print(f'Baudrate: {ser.baudrate}')  # check baudrate
print(f'Bytesize: {ser.bytesize}')  # check bytesize
print(f'Parity:   {ser.parity}')    # check parity
print(f'Stopbits: {ser.stopbits}')  # check stopbits
print(f'Is Open:  {ser.isOpen()}')  # check if port is open

This should match the control interface from your manual: Control interface parameters

Now, send a simple command, i.e. ser.write(b'Y\r\n') to test your connection. You might have to ser.flush() to ensure your data is actually written.

Finally, extend to more complex commands, e.g. setting modes or actual readouts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.