问题描述
我想交流两个RaspBerry Pi。我必须将输入数据从Master Pi发送到Slave Pi。
这是主RPi代码
# Master
import RPi.GPIO as GPIO
import spidev #SPI Communication
import time
GPIO.setmode(GPIO.BCM)
spi = spidev.SpiDev() #Create the SPI object
spi.open(0,0) #Open the SPI port Module 0,Device 0
spi.max_speed_hz = 5000
try:
while True:
command = input("Enter command: ")
command = command + "\n"
command = command.encode() #Convert the command to an a byte array
spi.xfer(command) #Send the command
time.sleep(0.25) #Delay
except KeyboardInterrupt:
# Ctrl+C
print ("Keyboard Interrupt")
finally:
spi.close()
GPIO.cleanup()
print ("Clean GPIO and SPI port closed")
这是Slave RPi代码:
# Slave
import RPi.GPIO as GPIO
import spidev #SPI Communication
import time
GPIO.setmode(GPIO.BCM)
spi = spidev.SpiDev() #Create the SPI object
spi.open(0,Device 0
spi.max_speed_hz = 5000
try:
while True:
read = spi.readbytes(3)
if (read[0] != 255):
print(read)
time.sleep(0.25)
except KeyboardInterrupt:
spi.close()
这是主机的RPi输出。
>>> %run hello.py
Enter command:
这是从RPi输出:
>>> %run raspBerry.py
[0]
[0]
[0]
[0]
[0]
[0]
[0]
如果我输入任何命令,则从属Pi仅打印"[0]"
不会执行任何操作。我只想在从属RPi中打印我在主RPi中输入的内容。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)