[英]Radio Transmition between Arduino Uno and Raspberry Pi 4 not working (using NRF24L01 module)
I'm currently trying to send strings from my Arduino Uno to my Raspberry Pi 4 using the radio module NRF24L01, but it's not working.我目前正在尝试使用无线电模块 NRF24L01 将字符串从我的 Arduino Uno 发送到我的 Raspberry Pi 4,但它不起作用。 I think the problem is in the raspberry part.
我认为问题出在覆盆子部分。 When I launch the program it starts receiving garbage data and not what my Arduino is transmitting.
当我启动程序时,它开始接收垃圾数据,而不是我的 Arduino 正在传输的数据。 Even if I turn the Arduino off, the raspberry continues to receive data.
即使我关闭 Arduino,覆盆子仍会继续接收数据。
This is how I connected the two boards.
这就是我连接两个板的方式。 This is the Arduino code:
这是 Arduino 代码:
#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10);
void setup() {
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(0x76);
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.enableDynamicPayloads();
radio.powerUp();
}
void loop() {
const char text[] = "HELLO";
radio.write(&text, sizeof(text));
Serial.println("--> SENT");
delay(1000);
}
This is the raspberry pi code:这是树莓派代码:
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
#------------ SETUP RADIO LISTENER ------------------------------------------------
GPIO.setmode(GPIO.BCM)
pipes = [[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[0])
radio.printDetails()
radio.startListening()
GPIO.cleanup()
#--------------------------------------------------------------------------------------
while True: #LOOP FUNCTION
while not radio.available(0):
time.sleep(1/100)
receivedMessage=[]
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print("--> {}".format(receivedMessage))
print("Converting message...")
string=""
for n in receivedMessage:
if(n>=32 and n<=126):
string+=chr(n)
print("--> {}".format(string))
All the libraries are installed correctly.所有库均已正确安装。 The only thing that raspberry pi catches is:
树莓派唯一能捕捉到的是:
STATUS = 0x03 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=1
RX_ADDR_P0-1 =
0xfdfdfdfdfd 0x7e7e7e7efc
RX_ADDR_P2-5 =
0xf8
0xf9
0xf9
0xf9
TX_ADDR =
0xfdfdfdfdfd
RX_PW_P0-6 =
0x80
0x8c
0x80
0x80
0x80
0x80
EN_AA =
0x8f
EN_RXADDR =
0x80
RF_CH =
0x9f
RF_SETUP =
0xff
CONFIG =
0x9b
DYNPD/FEATURE =
0x83
0x81
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = 8 bits
PA Power = PA_HIGH
--> [192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
--> [128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Converting message...
-->
It continues forever.它永远持续下去。 I can't figure out what's wrong.
我不知道出了什么问题。 Any help?
有什么帮助吗?
RF24_PA_MAX
, if the power supply is not able to deliver enough current then the module will not communicate for tests it is better to stay at RF24_PA_MA
RF24_PA_MAX
,如果电源无法提供足够的电流,则模块将无法通信进行测试,最好留在RF24_PA_MA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.