Using Arduino Due (as Receiver) and Arduino Uno (as Transmitter) with nRF24L01

Hi everyone.

I’m trying to use the nRF24L01 Sensor to communicate between 2 Arduino boards: Arduino Uno and Arduino Due.

The Arduino Uno is the transmitter and the Arduino Due is the receiver.

I also connected a DHT11 to the Arduino Uno board.

I first tried to just the temp and humidity from the DHT11 sensor to the Arduino Due board and then display the data that was received in the Arduino Due board (using the nRF24L01 sensor) on the serial monitor (with Serial.println).

But i don’t get any data in the Arduino Due board.

I know the nRF24L01 sensors work because i receive the data when i use 2 Arduino Uno boards. the problem is with the Arduino Due board.

i connected the nRF24L01 sensor to the SPI header pins in the Arduino Due board: SCK to pin 3, MOSI to pin 4 and MISO to pin 1 (i connected the Vcc and the Gnd to the other Vcc and Gnd pins. not to the Vcc and Gnd pin in the SPI header (pins 2 and 6)). and i don’t get anything on the serial monitor.

The Arduino Uno (the transmitter) code:

#include <dht.h>

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <SPI.h>
#define dht_Apin A0 //define DHT11 Analog before first run!!
dht DHT;

int CE_Pin = 7;
int CNS_Pin = 8;
float temp = 0.0;
float humid = 0.0;

RF24 radio(CE_Pin, CNS_Pin);
char tempstr[]="Temp: ";
char humidstr[]="Humidity: ";
const byte address[6] = "00001";
void float2str(float src,char dst[]);
bool TransmitData(const byte addr[6], char data[], int dataToWrite);

void setup() {
  // put your setup code here, to run once:
  radio.begin();
  Serial.begin(9600);
  DHT.read11(dht_Apin);

}

void loop() {
  // put your main code here, to run repeatedly:
  temp = DHT.temperature;
  humid = DHT.humidity;
  char datta[5] = "";
  float2str(temp,datta);
  if (TransmitData(address, tempstr, sizeof(tempstr))) Serial.println("data deliverd!!");
  delay(1000);
  if (TransmitData(address, datta, sizeof(datta))) Serial.println("data deliverd!!");
  delay(1000);
  float2str(humid,datta);
  if (TransmitData(address, humidstr, sizeof(humidstr))) Serial.println("data deliverd!!");
  delay(1000);
  if (TransmitData(address, datta, sizeof(datta))) Serial.println("data deliverd!!");  
  delay(1000);
}

bool TransmitData(const byte addr[6], char data[], int dataToWrite)
{
  bool writeStatus = false;
  delay(5);
  radio.openWritingPipe(addr);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  writeStatus = radio.write(data, sizeof(char) * dataToWrite);
  return writeStatus;
}



void float2str(float src,char dst[])
{
  int Hdigits=src;
  int Ldigits=(src-(float)Hdigits)*100;
  for(int i=1;i>=0;i--)
  {
    int temp=Hdigits%10;
    dst[i]=temp;
    dst[i]+='0';
    Hdigits=Hdigits/10;
  }
  dst[2]='.';
  for(int i=4;i>=3;i--)
  {
    int temp=Ldigits%10;
    dst[i]=temp;
    dst[i]+='0';
    Ldigits=Ldigits/10;
  }
}

The Arduino Due (the receiver) code:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <SPI.h>
RF24 radio(6,7);
const byte address[6] = "00001";
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0,address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  
}

void loop() {
  // put your main code here, to run repeatedly:
  if(radio.available())
  {
    char data[30]="";
    radio.read(&data,sizeof(data));
    Serial.print(data);
  }
}

Arduino Uno (the transmitter) pin assignment:
nRF24L01 Gnd pin => Arduino Uno Gnd pin
nRF24L01 Vcc pin => Arduino Uno Vcc(3.3V) pin
nRF24L01 CE (Chip Enable) pin => Arduino Uno pin 7
nRF24L01 CSN (Chip Select Not) pin => Arduino Uno pin 8
nRF24L01 SCK pin => Arduino Uno pin 13
nRF24L01 MISO pin => Arduino Uno pin 12
nRF24L01 MOSI pin => Arduino Uno pin 11
DHT11 Gnd pin => Arduino Uno Gnd pin
DHT11 Vcc pin => Arduino Uno Vcc(5V) pin
DHT11 Data out pin => Arduino Uno pin A0

Arduino Due (the receiver) pin assignment:
nRF24L01 Gnd pin => Arduino Due Gnd pin
nRF24L01 Vcc pin => Arduino Due Vcc(3.3V) pin
nRF24L01 CE (Chip Enable) pin => Arduino Due pin 6
nRF24L01 CSN (Chip Select Not) pin => Arduino Due pin 7
nRF24L01 SCK pin => Arduino Due SPI header SCK pin (pin 3)
nRF24L01 MISO pin => Arduino Due SPI header MISO pin (pin 1)
nRF24L01 MOSI pin => Arduino Due SPI header MOSI pin (pin 4)

What do i need to change in the Arduino Due code to make the Arduino Due to receive the data that is sent to the nRF24L01 sensor from the Arduino Uno board?

Thank you for your help,
Reshef

Have a look at this Simple nRF24L01+ Tutorial.

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

I don't have any experience with a DUE but, assuming it does SPI I can't see why it would present a problem.

If you have a second Uno it would be useful to get communications working between the Unos before trying to replace one of the Unos with the DUE

...R

Hi.

I'll try your example code.

I have 2 Uno board and i tried to send data between them and everything worked fine.

The problem started when i used the Due board as the receiver (instead of the second Uno board).

I guess the problem is in the SPI connection in the Arduino Due board (maybe i forgot to write some commands to turn on the SPI communication). but i don't know where is the problem (in the code or in the pin wiring connection) and how to fix it.

And another thing: I used (when i tried to send data using the 2 Uno boards instead of the Uno and the Due) the same code without changing the transmitter code and without changing the receiver code, and everything worked fine.

MISO and MOSI pins of the SPI header of the DUE are NOT pins 1 and 4 ! Check that first.

As stated by Robin2, in a first attempt to make that work, do not connect any sensor, but try with the most simple communication sketch you can find (another example https://maniacbug.wordpress.com/2012/03/30/rf24network/)

And don't forget the DUE is a 3.3volt device.