Is there a way to check if data is available in the serial read bus? Or is it possible to define like a callback functions that runs when data is available? I'm quite new to python so any help is appreciated

Example code
Code: Select all
from machine import Pin
import sys
led = Pin(25, Pin.OUT) #LED pin
while True:
data = sys.stdin.readline(1) #<-- this line is blocking. It shouldn't
if data == "N":
led.on()
elif data == "F":
led.off()
print("Working") #represents other code that should continue to run.
sleep(0.2)