如何使用pi pico运行micropython从计算机读取数据



我在网上到处找,可惜我找不到任何东西。无论如何,我可以从我的电脑读取数据到raspberry pi pico运行micropython?任何帮助都会很感激。我使用pyserial在我的计算机上发送和接收数据。

我也有这个问题,从这个链接我能够找出它。要从usb端口读取数据,使用"sys.stdin.buffer.read(8)"

这是一个简短的代码,你可以把它上传到pico。

import time
import sys
while True:
print("hello")
data = sys.stdin.buffer.read(8)
# to convert to string use data = sys.stdin.buffer.read(8).decode("utf-8")
print(data)
time.sleep(1)

使用此代码,它将等待直到8个字节进入,直到那时它将空闲。我肯定有办法,只是还没试过而已。

我使用Arduino IDE串行监视器发送数据。在Thonny上传这段代码(将其保存为main.py开始对权力),然后断开pico,把插头插回去时,打开Arduino连续监测。发送类似"12345678"这样的东西,它应该会把它吐出来。

编辑:

上面的代码将闲置,直到您发送数据。pico的继续运行,如果没有数据发送,使用以下(源):

import time
import sys
import select
while True:
print("hello")
res = select.select([sys.stdin], [], [], 0)
data = ""
while res[0]:
data = data + sys.stdin.read(1)
res = select.select([sys.stdin], [], [], 0)
print(data, end = "")
time.sleep(1)

你可以使用thony来发送数据,你不需要Arduino IDE。

最新更新