例如,当我给出5的代码时,我想打开rpi pico中的led (用电缆连接到pc )。
#This code will run in my computer (test.py)
x=int(input("Number?"))
if (x==5):
#turn on raspberry pi pico led
rpi pico的代码:
#This code will run in my rpi pico (pico.py)
from machine import Pin
led = Pin(25, Pin.OUT)
led.value(1)
反之亦然(在计算机上的代码中使用rpi pico中的代码执行某些操作)
以及如何在pc中调用/获取变量到rpi pico。
注意:我正在用opencv python编写一个代码,我想处理来自我计算机上的摄像头的数据,我希望rpi图片能够根据处理后的数据做出反应。和覆盆子皮皮连接到pc与电缆。
发布于 2022-05-07 15:48:20
主机和Pico之间通信的一个简单方法是使用串口。我有一个rp2040 2040-0,它将自己呈现给主机为/dev/ttyACM0
。如果我在rp2040上使用这样的代码:
import sys
import machine
led = machine.Pin(24, machine.Pin.OUT)
def led_on():
led(1)
def led_off():
led(0)
while True:
# read a command from the host
v = sys.stdin.readline().strip()
# perform the requested action
if v.lower() == "on":
led_on()
elif v.lower() == "off":
led_off()
然后我可以在主机上运行这个来闪烁LED:
import serial
import time
# open a serial connection
s = serial.Serial("/dev/ttyACM0", 115200)
# blink the led
while True:
s.write(b"on\n")
time.sleep(1)
s.write(b"off\n")
time.sleep(1)
这显然只是单向通信,但是您当然可以实现一种将信息传递回主机的机制。
https://stackoverflow.com/questions/72151781
复制相似问题