Go Down

Topic: nRF24L01 and UNO R3 Tutorial (Read 105689 times) previous topic - next topic

Sunnyflorida

Dec 22, 2012, 06:38 pm Last Edit: Dec 22, 2012, 06:43 pm by Sunnyflorida Reason: 1
I have been struggling for a few days how to get the nRF24L01 module to work with my Arduino Uno and an standalone ATMega328. Here is how I eventually did it. I use the IDE 1.0.1.

This sketch simply turns on a LED on the receiver when a button on the transmitter is pressed. The transmitter transmits the code "111." The receiver receives the code "111" and turns on the LED. This is the way I did it, let me know if it works for you or if you have any improvements.


1. Go to www.github.com/maniacbug/RF24.
2. Download the ZIP file (button is located near the top).
3. Unpack the ZIP file.
4. Go to the folder /Users/YourUserName/Documents/Arduino/libraries.
5. Create the following folders in the "libraries" folder:
    1. nFR24L01
    2. RF24
6. Open the "nFR24L01" folder, and drag the following file from the ZIP folder into it:
    - nRF24L01.h
7. Open the "RF24L01" folder, and drag the following files from the ZIP folder into it:
    - RF24_config.h
    - RF24.ccp
    - RF24.h
8. Connect the following pins to your Arduino:
    - Pin 9 - CE
    - Pin 10 - CS(N)
    - Pin 11 - MOSI
    - Pin 12 - MISO
    - Pin 13 - SCK
    On the Receiver:
    - Pin 3 - LED
    On the Transmitter:
    - Pin 7 - Button

9. Copy the following sketch to your TX arduino:
(Adapted from http://www.bajdi.com/rf24-library-revisited/)

Code: [Select]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void){
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(pipe);}

void loop(void){
 if (digitalRead(SW1) == HIGH){
 msg[0] = 111;
 radio.write(msg, 1);}}


10. Copy the following sketch to your RX arduino:

Code: [Select]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void){
 Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(1,pipe);
 radio.startListening();
 pinMode(LED1, OUTPUT);}

void loop(void){
 if (radio.available()){
   bool done = false;    
   while (!done){
     done = radio.read(msg, 1);      
     Serial.println(msg[0]);
     if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
     else {digitalWrite(LED1, LOW);}
     delay(10);}}
 else{Serial.println("No radio available");}}

PeterH

If you just want to share your success, this would be better under the Exhibition / Gallery section of the forum. The Project Guidance section is really for people who are seeking project guidance.

asking

can you give some more information regarding changing the pipe and on which channel data is transmitter it might be useful for debuggin NRF24L01+ on some other hardware plateforms..

Thanks

Soarmor

Hello,

I just saw your Tutorial but since I bought a arduino micro I haven't got
- Pin 11 - Pin 12   - Pin 13 
witch I resume is necessary   for the MOSI,MISO, SCK connections.
I would like to know if there is any possibility to change them to different pins?

Thanks,

PeterH

If your Arduino's SPI is connected to different pins then just wire it to the equivalent pins on your Arduino. For the Arduino Micro, you'd need to use the relevant pins on the ICSP header.

farmkid

Hey there!

I followed your instructions, and I when I used the serial monitor on the RX adrduino(I am using two Nanos) I keep getting the "Radio Not Available" message.  I have checked my wires and connections to make sure that there are no opens, but I don't know what else to try.  Does anyone have any suggestions or you ran into the same issue?  Thanks!

PeterH


Does anyone have any suggestions


Post a drawing / picture showing your hardware connections, and your sketches, and link to the source for any non-standard libraries you're using, and details of what it's doing (or not doing) wrong. For example if it's printing an error message on the serial port then give a copy of the serial output.

elektrokan

Hi, how can I add more leds this sketch? Thx.

wonza

#8
Sep 28, 2014, 04:44 am Last Edit: Sep 28, 2014, 04:48 am by wonza Reason: 1


I have my nano setup just like in the image above, (without the lamp connection). I have tested all my connections, and they're all good, bit I constantly get the "No radio available" message. Any ideas?

The only thing I can think is that I don't have the libraries set up right, but I don't get any errors about them. I wondered what the instructions meant when it said to create these two folders:
    1. nFR24L01
     2. RF24

But then only move the following files into the nFR24L01 folder. Does the RF24 folder need anything?

6. Open the "nFR24L01" folder, and drag the following file from the ZIP folder into it:
     - nRF24L01.h
7. Open the "RF24L01" folder, and drag the following files from the ZIP folder into it:
     - RF24_config.h
     - RF24.ccp
     - RF24.h

wonza

Ok, I  can't believe I did this, but as soon as I posted I realized I don't have a problem.

I connected my transmitter up and and when I send a message I get the 111 message up on my receiver.  When it's not receiving any messages is when the no radio message comes up... Unless I have something setup wrong that is... Anyway, I thought I'd leave my original message up as that diagram I posted helped me get this set up and running.

Thanks! :)

amando

How to pass a string using exempor?

Code: [Select]


#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;
 
void setup(void){
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);}
 
void loop(void){
  if (digitalRead(SW1) == HIGH){
  msg[0] = 111;
  radio.write(msg, 1);}}


arshamSh

#11
Nov 08, 2014, 12:58 am Last Edit: Nov 08, 2014, 01:00 am by arshamSh
Hi, I upload the following code to atMega2560 and an Uno Board...





Uno as sender...

Code: [Select]
/*        
        ####UPLOAD TO UNO####
        #    MOSI==>11      #
        #    MISO==>12      #
        #    SCK===>13      #
        # # # # # # # # # # #
        #CE_pin 7&CSN_pin 8 #
        #####################
*/


//====# header files #====
#include<SPI.h>
#include<nRF24l01.h>
#include<RF24.h>

//====# define #====
#define CE_pin 7
#define CSN_pin 8

//====# pre initializing #====
RF24 radio(CE_pin,CSN_pin);
const uint64_t mega_to_uno_pipe=0x0f0f0f0f01LL; //40 bit add, differs in lsb
const uint64_t uno_to_mega_pipe=0x0f0f0f0f02LL; // LL means long-long
int A=0xaaaa;
bool done;
//====# SetUp part #====
void setup(){
  Serial.begin(9600);
  radio.begin();
  radio.setPayloadSize(sizeof(A));
  radio.openReadingPipe(1,mega_to_uno_pipe);
  radio.openWritingPipe(uno_to_mega_pipe);
  radio.setRetries(0,0);
  radio.setDataRate(RF24_1MBPS);


  

}

//====# The main program #====
void loop(){
 done=radio.write( &A, 1 );
 Serial.print(done);
 delay(100);
}


And for Mega2560...

Code: [Select]
/*      
        ####UPLOAD TO MEGA####
        #     MOSI==>51      #
        #     MISO==>50      #
        #     SCK===>52      #
        # # # # # # # # # # ##
        # CE_pin 7&CSN_pin 8 #
        ######################
*/


//====# header files #====
#include<SPI.h>
#include<nRF24l01.h>
#include<RF24.h>

//====# define #====
#define CE_pin 7
#define CSN_pin 8

//====# pre initializing #====
RF24 radio(CE_pin,CSN_pin);
const uint64_t mega_to_uno_pipe=0x0f0f0f0f01LL; //40 bit add, differs in lsb
const uint64_t uno_to_mega_pipe=0x0f0f0f0f02LL; // LL means long-long
int A;
bool done=false;
//====# SetUp part #====
void setup(){
  Serial.begin(9600);
  radio.begin();
  radio.setPayloadSize(sizeof(A));
  radio.openReadingPipe(1,uno_to_mega_pipe);
  radio.openWritingPipe(mega_to_uno_pipe);
  radio.setRetries(0,0);.
  radio.setDataRate(RF24_1MBPS);
  pinMode(13,OUTPUT);

}

//====# The main program #====
void loop(){
  radio.startListening();
  if(A==0xaaaa){
    done=true;
  }
  radio.read(&A,sizeof(A));
  radio.stopListening();
  digitalWrite(13,done);
  Serial.print(done);
  Serial.println(A);
  delay(100);
}



but I just received lots of 0 on my Serial Monitoring ...
please help me to connect my NRF it is very important 4 me...

ChilliTronix

Ok... You need a 10uF capacitor across the power of the NRF24L01 board.

Then try the pingpair example (Under file->examples-RF24.

Wire up as per instructions in the sketch, noting where your SPI pins actually are.


arshamSh

#13
Nov 08, 2014, 01:50 am Last Edit: Nov 08, 2014, 02:18 am by arshamSh
Thanks a lots
looks like it's time for soldering :)
Ok I'll add ...
But do you mean my code is correct??

but still did not worked :(

ChilliTronix

Try the pingpair example and post a picture of your code.

Also, you don't actually need to solder the capacitor on the board, I connect using a Dupont female to male into a breadboard and have the capacitor on the bread board.

Once you have the ping pair example working then you can move on.

Go Up