[Python] Trying to connect to a UART CO2 sensor to to get readings using a python script but I...

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    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!

    Continue reading...

Compartilhe esta Página