NRF24L01 not receiving data when connected to SPI

Hi, I'm having some weird problems with my RF communication and could do with some advice. At this point in the project I want to use 1 microcontroller to request data from another and have this second circuit transmit data back that has been read from an SD card. The user runs a Python script which interfaces with the microcontroller that is requesting data. The microcontroller that is requesting data uses the following hardware:

Orangepip Kona328
Crazepony-UK NRF24L01+ RF Modules with 3.3V Adapter

Has the following connections:

CE - 9
CSN - 10
MOSI - 11
MISO - 12
SCK - 13
Vcc - 5V
GND - GND

And uses this code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN


const uint64_t pipes[2] = {0xF0F0F0F0E1LL,0xF0F0F0F0D2LL};
int instruction = 0;
const char dev1_send_instr[] = "s1";


void setup() {
  Serial.begin(250000);
  radio.begin();
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  radio.setPALevel(RF24_PA_MIN);
  
  do {
    if (Serial.available() > 0) {
      instruction = Serial.read();
      }
    delay(2000);
    } while (instruction != 49);


  radio.stopListening();


  int counter = 0;
  if (instruction == 49) {
    do {
      radio.write(&dev1_send_instr, sizeof(dev1_send_instr));
      counter = counter + 1;
      Serial.println(counter);
      delay(1000);
    }while (counter < 10);
  }


  delay(1000);
  radio.startListening();
  receive_data();
}


void receive_data() {
  while(1) {
    if (radio.available()) {
      char text[16] = "";
      radio.read(&text, sizeof(text));
      digitalWrite(LED_BUILTIN, HIGH);
      Serial.println(text);
      delay(1000);
    }
    else {
      Serial.println("0,0,0");
      delay(1000);
    }
  }
}


void loop() {}

The circuit that is sending the data back consists of this hardware:

Orangepip Kona328
LIS3DH Accelerometer
Crazepony-UK NRF24L01+ RF Modules with 3.3V Adapter
kwmobile SD Card Reader Module

This circuit has the following connections:

For the LIS3DH:
SDA - A4
SCL - A5
Vcc - 5V
GND - GND

For the NRF24L01:
CE - 9
CSN - 10
MOSI - 11
MISO - 12
SCK - 13
Vcc - 5V
GND - GND

For the SD Card Module:
+5 - 5V
GND - GND
CS - 4
MOSI - 11
MISO - 12
SCK - 13

And uses this code:

#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

RF24 radio(9, 10); // CE, CSN
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
#define SD_CS 4
#define TX_CS 10
const uint64_t pipes[2] = {0xF0F0F0F0E1LL,0xF0F0F0F0D2LL};
char instruction[16] = "";

void setup() {
   Serial.begin(250000);
   pinMode(LED_BUILTIN, OUTPUT);
   pinMode(SD_CS, OUTPUT);
   pinMode(TX_CS, OUTPUT);
   digitalWrite(SD_CS, HIGH);
   digitalWrite(TX_CS, LOW);
   radio.begin();
   radio.openWritingPipe(pipes[0]);
   radio.openReadingPipe(1,pipes[1]);
   radio.setPALevel(RF24_PA_MIN);

   digitalWrite(TX_CS, HIGH);
   digitalWrite(SD_CS, LOW);

   if (!SD.begin(SD_CS)) {
     Serial.println("initialization failed!");
     while (1);
   }
   Serial.println("initialization done.");

   digitalWrite(SD_CS, HIGH);
   digitalWrite(TX_CS, LOW);

   radio.startListening();

   do {
     if (radio.available()) {
       radio.read(&instruction, sizeof(instruction));
       Serial.print("Received: ");
       bool result = radio.isChipConnected();
       Serial.println(result);
       Serial.println(instruction);
     }
     else {
       Serial.println("Not Received");
     }
     delay(1000);
   } while (strcmp("s1", instruction) != 0);

   digitalWrite(TX_CS, HIGH);

   Serial.println("here");
   radio.stopListening();
   delay(1000);
   transmit_data();
}

void loop() {}

void transmit_data() {
   File data_file;
   char filename[] = "data.txt";
   char char_array[32];
   int index = 0;

   digitalWrite(SD_CS, LOW);
   digitalWrite(TX_CS, HIGH);
   data_file = SD.open(filename);

   if (data_file) {
     while (data_file.available()) {
       char data = data_file.read();

       if (data == '\n') {
         digitalWrite(SD_CS, HIGH);
         digitalWrite(TX_CS, LOW);
         radio.write(&char_array, sizeof(char_array));
         delay(1000);
         for (int x = 0; x < sizeof(char_array) / sizeof(char_array[0]);
x++) {
           char_array[x] = 0;
         }
         index = 0;
         digitalWrite(SD_CS, LOW);
         digitalWrite(TX_CS, HIGH);
       } // end inside if

       else {
          char_array[index] = data;
          index++;
       }

     } // end while
     data_file.close();
   } // end outside if

   else {
     Serial.println("There was an error in opening the file.");
   } // end else
   digitalWrite(SD_CS, HIGH);
} // end data_transmit

The Python script successfully sends an instruction to the serial port and the Orangepip receives it correctly so the problem isn't here.

Basically the second circuit gets stuck printing out "Not Received" because it never receives the instruction "s1" from the other microcontroller.

Things I've tried:

I uploaded code to the circuit sending the data back that just read from the SD card and sent the data from it. This did not work initially, however when I removed the voltage regulator from the NRF24L01 and powered it from the 3.3V Arduino pin it sent the data. The problem with this is that when I re-upload the code above, radio.available() sometimes returns True even when the request instruction is not transmitted, and doesn't receive the instruction when it is sent.

I thought there could be a problem with having too many components using the 5V pin so I tried powering the NRF24L01 separately but this was also unsuccessful.
Any suggestions?
Thanks

I forgot to mention I have a 10uF capacitor attached to the Vcc and GND pins on the NRF24L01 modules.

Have a look at this Simple nRF24L01+ Tutorial.

The second example using the AckPayload feature provides a simple system for two-way communication.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to. If the first example does not work be sure to try the connection test for both of your Arduinos. Nothing will work if the connection test fails.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

If you are using the high-power nRF24s (with the external antenna) it may help to have a distance of about 3 metres between the two nRF24s so that the signal does not overwhelm the receiver. However someone on the Forum has had them working without that separation - I don't have any personal experience with them. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.

...R

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.