[Python] How to create an if statement with serial data?

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    How would I write the code so if I recieve 'hello' it runs a function?

    import serial


    ser = serial.Serial(port='/dev/tty.usbmodem11201',baudrate=9600)

    while True:
    value= ser.readline()
    valueInString=str(value, 'UTF-8')
    print(valueInString)

    if ser.is_open == hello:
    print("Hi")


    This is what I saw to do but it did not work. How would I get it to work? Thanks!

    Continue reading...

Compartilhe esta Página