NRF24L01+ Arduino Mega Problem....

Hello everybody,

This is my first post here, so I hope everything is done correctly :wink:

Little backstory, I'm making a project for school and I have to have a wireless communication.
I bought these small NRF24L01+ transceivers to use it. I will use this to send 7 variables from a UNO to a MEGA.
Its working from uno to uno. But When I change the receiver with a MEGA I get no data...?

I'm using this site for the wiring: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
(chart in the middel of the page)

This is the code on the Receiving Mega:

/* YourDuinoStarter Example: nRF24L01 Receive Joystick values

 - WHAT IT DOES: Receives data from another transceiver with
   2 Analog values from a Joystick or 2 Potentiometers
   Displays received values on Serial Monitor
 - SEE the comments after "//" on each line below
 - CONNECTIONS: nRF24L01 Modules See:
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED
   
 - V1.00 11/26/13
   Based on examples at http://www.bajdi.com/
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe


/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
float joystick[7];  // 2 element array holding Joystick readings

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(500);
  if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( joystick, sizeof(joystick) );
      
      Serial.println(joystick[0]);
           
      Serial.println(joystick[1]);
      Serial.println(joystick[2]);
      Serial.println(joystick[3]);
      Serial.println(joystick[4]);
      Serial.println(joystick[5]);
      Serial.println(joystick[6]);
      
    }
  }
  else
  {    
      Serial.println("No radio available");
  }

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//NONE
//*********( THE END )***********

And this is the code of the sending UNO:

/* YourDuinoStarter Example: nRF24L01 Transmit Joystick values
 - WHAT IT DOES: Reads Analog values on A0, A1 and transmits
   them over a nRF24L01 Radio Link to another transceiver.
 - SEE the comments after "//" on each line below
 - CONNECTIONS: nRF24L01 Modules See:
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED
   - 
   Analog Joystick or two 10K potentiometers:
   GND to Arduino GND
   VCC to Arduino +5V
   X Pot to Arduino A0
   Y Pot to Arduino A1
   
 - V1.00 11/26/13
   Based on examples at http://www.bajdi.com/
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <OneWire.h>



/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10
#define JOYSTICK_X A0
#define JOYSTICK_Y A1

int DS18S20_Pin = 2; // Pin Temperatuur Sensor
OneWire ds(DS18S20_Pin); // Write Pin Temperatuur Sensor

float temperature;
int floattemp;

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe


/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
float joystick[7];  // 2 element array holding Joystick readings

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
}//--(end setup )---




void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  temperature = getTemp();
  floattemp = (int)temperature;
 
  joystick[0] = temperature;
  joystick[1] = 1;
  joystick[2] = 2;
  joystick[3] = 3;
  joystick[4] = 4;
  joystick[5] = 5;
  joystick[6] = 6;
 
  radio.write( joystick, sizeof(joystick) );

}//--(end main loop )---


float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      //Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      //Serial.print("Device is not recognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

  
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
  
  ds.reset_search();
  
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  return TemperatureSum;
  
}

There is an digital temperature meter connected to D2 on the sending UNO (OneWire).
When I use a UNO for receiving I get the correct data on the serial monitor:
(23.56, 1.00, 2.00, 3.00, 4.00, 5.00, 6.00) <- this is what I'm expecting to receive! (Yay!)

But when I use a MEGA (Wired like that site says) I get this in my serial monitor...
(nan, nan, nan, nan, nan, nan, nan)

Can someone help me? I hope I didn't forget something to type here.

Thanks in advance!!!

The Mega has the SPI pins on pins 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).
Even if you've wired it up correctly, your posted code for the Mega is still specifying pins 9 and 10.

Pete

el_supremo:
The Mega has the SPI pins on pins 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).
Even if you've wired it up correctly, your posted code for the Mega is still specifying pins 9 and 10.

Pete

So what should these be then? When I change them, the serial monitor says "Radio not available".?

Still, thank you for your response.

Regards Thomas

If you have wired the Mega as described in the page you linked, then you need to change the receiving Mega's code from:

#define CSN_PIN 10

to

#define CSN_PIN 53

Pete

el_supremo:
If you have wired the Mega as described in the page you linked, then you need to change the receiving Mega's code from:

#define CSN_PIN 10

to

#define CSN_PIN 53

Pete

Thank you but it didn't work :~ Part of the project is working on my uno now, due to pin count I will have to change a few plans but I think it will work.

Regards Thomas