使用 PySerial 我成功地将数据从 Raspberry Pi Pico 发送到 Windows PC,但反之则不然。
Windows PC 代码:
import serial
# Configure the serial connection
port = "COM5"
ser = serial.Serial(port, 9600)
message = b"Hey This is the message!!!!"
ser.write(message)
Raspberry Pi Pico 代码:
file = open('Results77.txt', 'wb')
while (True):
# I do not know what to do here to get the message that I sent into the variable data
data = input()
file.write(data)
Pico 代码可能看起来像这样
import select
import sys
# Set up the poll object
poll_obj = select.poll()
poll_obj.register(sys.stdin, select.POLLIN)
# Loop indefinitely
while True:
# Wait for input on stdin
poll_results = poll_obj.poll(1) # the '1' is how long it will wait for message before looping again (in microseconds)
if poll_results:
# Read the data from stdin (read data coming from PC)
data = sys.stdin.readline().strip()
确保您的 Windows 设备使用预期的行结尾
ser.write("Hey This is the message!!!!\r".encode())