I've worked with Arduino's before, where I use serial communication to send messages to the Arduino. I'm trying to do the same for the Pico, but if there are better options, let me know!
So, I've found that I can use the sys.stdin.readline() command to read from the serial, like so:
Code: Select all
from machine import Pin
import sys
led = Pin(25, Pin.OUT)
while True:
data = sys.stdin.readline()
if data == "N":
led.on()
else if data == "F":
led.off()
Then since the code will always be running for the PID system to work, I need to only read when there is some data in the serial buffer. So in the above code, the LED turns on, but immediately turns off in the next while iteration. With Arduino you can simply user serial.Available(). I've tried the solution here: https://stackoverflow.com/questions/376 ... -some-data, but it didn't work so well.
Can someone help me in the right direction? In the end I would like to be able to send things like the PID values and the setpoint.