0

here are the codes and i don't know why it does not communicate. The arduino should send some example data and the raspberry pi should simply receive the data.

Transmitter code (Arduino)

#include "RF24.h"
#include "nRF24L01.h"
#include "RF24.h"

RF24 radio(7, 8);
const uint64_t data_pipe[1] = {0xF0F0F0F0E1};

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPayloadSize(32);
  radio.setChannel(0x76);
  radio.setPALevel(RF24_PA_MAX);
  radio.openWritingPipe(data_pipe);
  radio.enableDynamicPayloads();

}

void loop() {
  radio.stopListening();
  char data[] = "1234567890";
  Serial.println("");
  Serial.print("Data: ");
  Serial.println(data);
  Serial.print("sizeof(data): ");
  Serial.println(sizeof(data));
  radio.write(&data, sizeof(data));
  Serial.println("Data send");
  delay(1000);
}

Receiver code (Raspberry Pi, Python)

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

GPIO.setmode(GPIO.BCM)

pipes = [0xF0F0F0F0E1]

radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17) 
radio.setPayloadSize(32)
radio.setRetries(15, 15)
radio.setChannel(0x76)
radio.setPALevel(radio.PA_MAX)
radio.enableDynamicPayloads()
radio.openReadingPipe(0, pipes)

z = 1
while(1):
    radio.startListening()
    while not radio.available(0):
        print("Radio unavailable...")
        time.sleep(1 / 100)
    receivedMessage = []
    size = radio.getDynamicPayloadSize()
    if size>0:
        print("Dynamic Payload Size: ", size)
        radio.read(receivedMessage, size)
        print("Received: ", receivedMessage)
        print("Translating...")
        string = []
        n = 0

        while n<len(receivedMessage):
            if receivedMessage[n] >= 33:
                string.append(chr(receivedMessage[n]))
            n = n+1
        print("Message: ", string)
    else:
        print("No Payload ", z)
    time.sleep(0.9)
    z = z+1

The Raspberry Pi always prints "No Payload".

Arduino connection:

IRQ -> not connected

MOSI -> D11

CSS -> D8

VCC -> 3.3V

MISO -> D12

SCK -> D13

CE -> D7

GND -> GND

Raspberry Pi (Model 3B+) connection:

IRQ -> not connected

MOSI -> GPIO 12

MOSI (SPI) CSS -> GPIO 12 CE0

(SPI) VCC -> 3.3 VDC Power

MISO -> GPIO 13

MISO (SPI) SCK -> GPIO 14

SCLK (SPI) CE -> GPIO 0

GND -> Pin 14 (Ground)

  • 1
    How far are they apart? Using RF24_PA_MAX while they are next to each other will make them not work. – Gerben Jan 26 at 15:49
  • Okay i have it changed to MIN but it doesn't work either. – Haha321 Jan 26 at 16:59
  • How are you running the Raspberry Pi sketch? Are you sure there's actual SPI communication going on? – Avamander Jan 28 at 16:12
  • I run it with the Python IDE and SPI is in raspi-config activated. – Haha321 Jan 30 at 13:05

Your Answer

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

Browse other questions tagged or ask your own question.