I need to build the communication with micropython since I need it for school. The next issue that I can't seem to get done is that my communication needs to be from python program to raspberry pi pico and back. The farthest I've tried is this.
A program on the raspberry:
import sys
import utime
while(True):
x = sys.stdin.buffer.read()
if x == "1":
sys.stdout.print(x)
utime.sleep(1)
if x == 'end':
break
and a program on my pc: import serial from time import sleep
class Handler:
TERMINATOR = '\n'.encode('UTF8')
def __init__(self, device='COM19', baud=115200, timeout=1):
self.serial = serial.Serial(device, baud, timeout=timeout)
def receive(self) -> str:
line = self.serial.read_until(self.TERMINATOR)
return line.decode('UTF8').strip()
def send(self, text: str):
line = text
self.serial.write(line.encode('UTF8'))
def close(self):
self.serial.close()
sender = Handler('COM19',115200,1)
while(True):
x = input()
sender.send(x)
sleep(2)
print(sender.receive())
if x == 'end':
break
This code is absolutely not mine and is an amalgam of what I was able to find on the internet. What I am trying to do is put a number into the console on my computer program and I am trying to send it back with raspberry pi pico and read it on my pc. But I wasn't able to get that response. Any help would be fine, either pointers or solutions. Thank you for anything in advance.