[英]How can I push a file out to multiple Raspberry Pi Pico's at once?
[英]How can i get raspberry pi pico to communicate with PC / external devices
例如,當我給代碼 5 時,我想打開我們的 rpi pico 中的 led(rpi pico 使用電纜連接到 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 pico 根據處理后的數據做出反應。 和 raspberry pi pico 通過電纜連接到 pc。
主機和 Pico 之間通信的一種簡單方法是使用串行端口。 我有一個rp2040-zero ,它以/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)
這顯然只是單向通信,但您當然可以實現一種將信息傳遞回主機的機制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.