我正在尝试通过VRF槽NRF24l01模块在Arduino和RaspberryPi 3模型之间建立通信。
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x76)
radio.setDataRate(NRF24.BR_1MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openReadingPipe(1, pipes[1])
radio.printDetails()
radio.startListening()
while(1):
# ackPL = [1]
while not radio.available(0):
time.sleep(1 / 100)
receivedMessage = []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print("Received: {}".format(receivedMessage))
print("Translating the receivedMessage into unicode characters")
string = ""
for n in receivedMessage:
# Decode into standard unicode set
if (n >= 32 and n <= 126):
string += chr(n)
print("Out received message decodes to: {}".format(string))
#include<SPI.h>
#include<RF24.h>
// ce, csn pins
RF24 radio(9, 10);
void setup(void){
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(0x76);
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.enableDynamicPayloads();
radio.powerUp();
}
void loop(void){
const char text[] = "Hello World is awesome";
radio.write(&text, sizeof(text));
delay(1000);
}
RPi无法读取arduino发送的数据。在终端中,它使用与arduino发送的内容无关的整数来打印数组。不论是否插入arduino,RPi都能打印出相同的结果,因此很明显根本没有任何连接。