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. 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. Even if I turn the Arduino off, the raspberry continues to receive data.
This is how I connected the two boards. This is the Arduino code:
#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 atRF24_PA_MA