1

I have recently bought two nRF24L01+ radio chips for communication between my Raspberry Pi and Arduino. I will be solely using this from Raspberry towards Arduino. The tutorial I followed: https://circuitdigest.com/microcontroller-projects/wireless-rf-communication-between-arduino-and-raspberry-pi-using-nrf24l01

My problem is: I don't receive anything. The Raspberry seems to send everything properly (i.e. "H", "i", "0", ... etc) Serial output is listed below. Can someone please help me?

The code I am using for Raspberry:

import RPi.GPIO as GPIO
import time
import spidev
from lib_nrf24 import NRF24

GPIO.setmode(GPIO.BCM)

pipes = [[0xE0, 0xE0, 0xF1, 0xF1, 0xE0], [0xF1, 0xF1, 0xF0, 0xF0, 0xE0]]

radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0,25)

radio.setPayloadSize(8)
radio.setChannel(0x76)
radio.setDataRate(NRF24.BR_1MBPS)
radio.setPALevel(NRF24.PA_MIN)

radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()

radio.openWritingPipe(pipes[0])
radio.printDetails()

sendMessage = list(" Hi")
while len(sendMessage) < 8:
    sendMessage.append(0)

while True:
    start = time.time()
    radio.write(sendMessage)
    print("Sent the message: {}".format(sendMessage))
    radio.startListening()

    while not radio.available(0):
        time.sleep(1/100)
        if time.time() - start > 2:
            print("Timed out.")
            break

    radio.stopListening()
    time.sleep(3)

The code for my Arduino:

#include<SPI.h>                   // spi library for connecting nrf
#include<RF24.h>                  // nrf library

RF24 radio(9, 10) ;  // ce, csn pins    
void setup() {
  Serial.begin(9600) ;     // start serial monitor baud rate
  Serial.println("Starting.. Setting Up.. Radio on..") ; // debug message
  radio.begin();        // start radio at ce csn pin 9 and 10
  radio.setPALevel(RF24_PA_MIN) ;   // set power level
  radio.setChannel(0x76) ;            // set chanel at 76
  const uint64_t pipe = 0xE0E0F1F1E0LL ;    // pipe address same as sender i.e. raspberry pi
  radio.openReadingPipe(1, pipe) ;        // start reading pipe 
  radio.enableDynamicPayloads() ;
  radio.powerUp() ;          
}

void loop() {

  radio.startListening() ;        // start listening forever
  char receivedMessage[8] = {0} ;   // set incmng message for 32 bytes
  if (radio.available()) {       // check if message is coming
    radio.read(receivedMessage, sizeof(receivedMessage));    // read the message and save
    Serial.println(receivedMessage) ;    // print message on serial monitor 
    Serial.println("Turning off the radio.") ;   // print message on serial monitor
    radio.stopListening() ;   // stop listening radio
    String stringMessage(receivedMessage) ;     // change char to string
    delay(1000);    // delay of 1 second 
    Serial.print(stringMessage);   // print received mesage
  }
  delay(10);
}

Output: just a loop of

Turning off the radio.

Turning off the radio.

Turning off the radio.

I have checked my wiring three times over...

  • 1
    Comments are not for extended discussion; this conversation has been moved to chat. – Ghanima Jan 24 at 11:23
1

This fixed my issues with Raspberry Pi 3 B+ and Raspberry Pi 4 In lib_nrf24.py in function:

def begin(self, csn_pin ... after self.spidev.openadd:

self.spidev.max_speed_hz = 4000000

Did you find out an other solution?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.