我试图制作一个有关NRF24L01 +的项目,并将其连接到arduino和树莓派。然后,我编写了代码。它没有回应。因此,我从一个网站上获取了它,并且有效。但是,它只发送了一次消息。但是那里写的代码是连续发送的。因此,我决定在Arduino代码中放入一条串行线,以弄清我做错了什么。如预期的那样,串行线打印了一次“ A”。但是我把它放在一个循环中!那么,你们对我在做什么错有想法吗?
arduino代码如下所示:
//These libraries are fully downloaded.
#include<SPI.h>
#include<RF24.h>
// ce, csn pins, connected properly.
RF24 radio(9, 10) ;
//Here, I set up the stuff needed for the Transciever.
void setup(void){
radio.begin() ;
radio.setPALevel(RF24_PA_MAX) ;
radio.setChannel(0x76) ;
radio.openWritingPipe(0xF0F0F0F0E1LL) ;
radio.enableDynamicPayloads() ;
radio.powerUp() ;
Serial.begin(9600);
}
void loop(void){
const char text[] = "Hello World!" ;
Serial.println("A");
radio.write(&text, sizeof(text)) ;
delay(1000) ;
//s
}
RPI3代码如下所示:
#The libraries are downloaded.
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()
try:
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))
except KeyboardInterrupt:
GPIO.cleanup()
那么,您在我的代码中看到任何问题吗?我真的需要解决这个问题。 这是我从中获得他们的链接: https://www.google.com.tr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=11&cad=rja&uact=8&ved=2ahUKEwi-vPCDxo7hAhUKyaYKHZP9DQ8QFjAKegQIAxAB&url=http%3A%2F%2Fthezanshow.com%2Felectronics-tutorials%2Fraspberry-pi%2Ftutorial-34-35&usg=AOvVaw26oek-_CM80ujzcc_PBk0N
这是运行代码时终端的屏幕截图: image
答案 0 :(得分:0)
RF24 模块的文档说写函数会阻塞,直到接收者成功确认:Description of write function 所以我假设你没有从你的 RPI 发送任何确认。我建议仔细阅读 documentation 并选择其他写入方法之一。另外看看lib_nrf24的Python文档