I'm working on a project involving a Node website and an Adafruit 8x8 button matrix using the Feather M4 Express microcontroller and CircuitPython. I am trying to sort out clean serial communication between the website and the button grid via USB.
This is the current loop I have on the microcontroller, which is supposed to just check for serial input, and print it if it exists.
while True:
    # the trellis can only be read every 17 millisecons or so
    trellis.sync()
    if supervisor.runtime.serial_bytes_available:
        data = input()
        print(data)
    time.sleep(0.02)
This works for the first iteration. The problem is, after the first input() call,
supervisor.runtime.serial_bytes_available isn't being reset to False.
Hence, in the second iteration, the microcontroller hangs at input() until I send it
something over serial. This happens for every following iteration.
How can I make sure supervisor.runtime.serial_bytes_available will be set back to False after I read the input?
 
    