Amanoo
Posts: 6
Joined: Sun Feb 05, 2012 3:15 pm

NRF24L01 RF Transceiver

Tue Sep 11, 2012 2:29 pm

Hello. I would like to control an Arduino through a NRF24L01 transceiver, but I have no idea to how GPIO works. I'm not very well-versed on hardware and I have no idea how to connect the transeiver to the Pi and make it work. Can anyone help?

tekmanro
Posts: 14
Joined: Tue Jul 17, 2012 9:57 pm

Re: NRF24L01 RF Transceiver

Wed Sep 12, 2012 6:27 am

I had the same idea of using Raspberry PI as a sort of internet-connected "router" for several low-cost AVR-based devices/sensors all linked together with NRF24L01+ transceivers. I haven't received the hardware yet, but I did find this page that describes how to do it for the Beaglebone (similar board to the Pi). I assume this will work with minor modifications: http://theredblacktree.wordpress.com/20 ... llo-world/ (for example on the PI the SPI lives on GPIO pins 9-11 and you should be able to use any 2 random pins for linking CE and CSN on the transceiver).

Keep this thread updated on your progress if you get the library up and running.

Amanoo
Posts: 6
Joined: Sun Feb 05, 2012 3:15 pm

Re: NRF24L01 RF Transceiver

Wed Sep 12, 2012 9:43 am

I don't know if I can do anything with it, but I'll check it out. It is more resources and it is probably better than trying to port Arduino libraries. This is all completely new territory to me, though.

Amanoo
Posts: 6
Joined: Sun Feb 05, 2012 3:15 pm

Re: NRF24L01 RF Transceiver

Wed Sep 12, 2012 10:39 pm

http://www.mediafire.com/?0watbvnaq63b4ub This might be a working library. It assumes CE is connected to GPIO pin 23 and CSN is connected to GPIO pin 24 (als known as respectively pins 4 and 5). Many examples also assume pin 7 (not sure to which physical GPIO pin that maps, the raspberry pi wiki should have info on that) is used to change modes. I think it was that if you ground that pin the module goes on receiver mode. The examples should be clear about these modes. The other parts are connected as you suggested. I could not find any info about the SPI pins in the source code so I assumed the proper handling of it would be done automatically. On another forum they suggested me importing the WirePi library into the source code and changing the pins to which the module was connected in the source code, and that is what I did.
I could not figure out those git systems, so someone else will have to do it if this code appears working.

I must admit I don't have much of an idea to what I'm doing.

EDIT: Here someone says that if a serial status is printed I can replace it with "cout" or "printf" and that certain types such as "uint_8_t, uint64_t, bool can give problems and that I should try defining them with a typedef or replace them by for example an (unsigned) int. I completely didn't do any of those things and I hardly have any idea to what this even means :D When it comes to C and C++ I'm such a noob.

Amanoo
Posts: 6
Joined: Sun Feb 05, 2012 3:15 pm

Re: NRF24L01 RF Transceiver

Mon Sep 17, 2012 2:01 pm

http://www.mediafire.com/?ssor8dfpznd4l6j

This is an edited Arduino library, no idea if it works at all, it was hardly edited :D
If you manage to get anything working yourself, please tell me.

Amanoo
Posts: 6
Joined: Sun Feb 05, 2012 3:15 pm

Re: NRF24L01 RF Transceiver

Mon Sep 17, 2012 2:35 pm

Newer version, still untested

http://www.mediafire.com/?n8apkyz9kj3b9wa

direk
Posts: 6
Joined: Thu Jul 26, 2012 11:23 am

Re: NRF24L01 RF Transceiver

Sun Sep 30, 2012 11:48 am

Hi guys!

I was managed to run nRF24L01+ on RPi and made it to talk with arduino thru nRF :)
Basically RF24 library made for arduino by maniacbug and ported for BeagleBone by purinda works from the scratch :)

The only thing you need is correct kernel module for spi device - /dev/spidev0,0 and 0.1 should be visible in system and make your own cabling for CSN pin (i am using GPIO25).

Code for this port is here: https://bitbucket.org/purinda/rf24bb/wiki/Home

Oh, one more thing. You probably need to modify makefile to make it work on RPi.

rza.android
Posts: 3
Joined: Sun Oct 07, 2012 10:02 am

Re: NRF24L01 RF Transceiver

Tue Oct 23, 2012 10:05 pm

direk wrote:Hi guys!

I was managed to run nRF24L01+ on RPi and made it to talk with arduino thru nRF :)
Basically RF24 library made for arduino by maniacbug and ported for BeagleBone by purinda works from the scratch :)

The only thing you need is correct kernel module for spi device - /dev/spidev0,0 and 0.1 should be visible in system and make your own cabling for CSN pin (i am using GPIO25).

Code for this port is here: https://bitbucket.org/purinda/rf24bb/wiki/Home

Oh, one more thing. You probably need to modify makefile to make it work on RPi.

Hi Direk how do i use this i downloaded the source cross compiled it but when i run it on rpi it says
#rf24bb
cant open device no such file or directory
aborted.

how do i run this ?
spi0.0 and spi0.1 are visible

ok i found in lib spi there was a change that needed to be made
from /dev/spidev2.0 to 0.0
i recompiled ran it now i get
segmentation fault
??

direk
Posts: 6
Joined: Thu Jul 26, 2012 11:23 am

Re: NRF24L01 RF Transceiver

Wed Oct 24, 2012 6:08 am

Now I am at work, but later this day I will send you my sources and compiled app for testing.

BTW, I am compiling in RPi directly.

raspberryfish
Posts: 16
Joined: Wed May 23, 2012 6:13 pm

Re: NRF24L01 RF Transceiver

Tue Oct 30, 2012 7:40 pm

Hello,

can u provide me your library as well? Would be very nice:)

thanks
Peter

direk
Posts: 6
Joined: Thu Jul 26, 2012 11:23 am

Re: NRF24L01 RF Transceiver

Wed Oct 31, 2012 4:15 pm

Hi!

I am attaching link to modified RF24 library and compiled bin. Please look on setup() in main.cpp - this is also modified. The same settings for RF24 module has to be used on second device (eg. arduino) to make connection.

Click: http://www.sendspace.com/file/6ixtda

raspberryfish
Posts: 16
Joined: Wed May 23, 2012 6:13 pm

Re: NRF24L01 RF Transceiver

Wed Oct 31, 2012 8:32 pm

Thanks,

i will give a try soon:)

raspberryfish
Posts: 16
Joined: Wed May 23, 2012 6:13 pm

Re: NRF24L01 RF Transceiver

Sat Nov 03, 2012 7:20 pm

One question: How can i compile this on my raspberry? I dont have Netbeans there.

thanks
Peter

direk
Posts: 6
Joined: Thu Jul 26, 2012 11:23 am

Re: NRF24L01 RF Transceiver

Tue Nov 06, 2012 5:47 pm

On console window go to folder with source code (with main.cpp and makefile) and type "make". If you have g++ installed it will be compiled.

rza.android
Posts: 3
Joined: Sun Oct 07, 2012 10:02 am

Re: NRF24L01 RF Transceiver

Wed Nov 07, 2012 9:52 pm

hi i finally got this all working and made a JNI version to send messages between Rpi and arduino.
It was my first JNI project :)

kermitas
Posts: 108
Joined: Thu Jan 26, 2012 11:49 am

Re: NRF24L01 RF Transceiver

Thu Nov 29, 2012 9:48 am

Hello,

I'm very happy that this subject exists !! :) :)

I want to connect RaspberryPi with nRF24L01+ via SPI and use it from Java program.

On the second side there will be max 6 receivers connected to Arduino.
(Arduino side should not be a problem for me since there are a lot of pages and at least two libraries.)

But I wanted to ask you about RaspberryPi+SPI (+Java). Can you point me to some starting point? Any interesting pages? Libraries?

(Speaking of RaspberryPi + nRF24L01+) For now:
- I have no idea how to use SPI from Java
- does existing libraries support Enhanced ShockBurst?
- does existing libraries support six-to-one (6:1) star network?

Thank you,
Arthur.

kermitas
Posts: 108
Joined: Thu Jan 26, 2012 11:49 am

Re: NRF24L01 RF Transceiver

Thu Nov 29, 2012 11:38 am

rza.android wrote:hi i finally got this all working and made a JNI version to send messages between Rpi and arduino.
It was my first JNI project :)
Did you read about Pi4J? http://pi4j.com :)

Here is thread about it http://www.raspberrypi.org/phpBB3/viewt ... 34&t=17992 .

PS: I placed a question about SPI support http://www.raspberrypi.org/phpBB3/viewt ... 04#p223704

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Sun Dec 16, 2012 9:20 am

I changed the RF24 library and SPI to have more flexability.

Code: Select all

// CE and CSN pins
//RF24 radio(8, 25);  //only CSN is NEEDED in RPI
RF24 radio("/dev/spidev0.1",8000000 , 25);  //spi device, spi speed and CSN,only CSN is NEEDED in RPI
the status did not work until I changed:

Code: Select all

  printf_P(PSTR("Data Rate\t = %S\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
into:

Code: Select all

  printf_P(PSTR("Data Rate\t = %s\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
Does anyone know why %S fails?

Would it be easy to create seperate libspi and librf24? I don't have much experience in library programming.

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Sun Dec 16, 2012 2:24 pm

https://github.com/gnulnulf/RF24 contains the library.

envagyok
Posts: 1
Joined: Tue Jan 01, 2013 8:03 pm

Re: NRF24L01 RF Transceiver

Tue Jan 01, 2013 8:08 pm

Can you help me, how can I connect iboard nRF24L01 Module to RPI? Which pins on module, which pins on RPI.

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Wed Jan 02, 2013 8:51 am

In my examples I used /dev/spidev0.0 and GPIO25
I have a model 1 rpi so you should check if the pins are on the same spot
nrf-vcc = rpi-3v3 (1)
nrf-gnd = rpi-gnd (6)
nrf-ce = rpi-ce0 (24)
nrf-csn = rpi-gpio25 (22)
nrf-sck = rpi-sckl (23)
nrf-mo = rpi-mosi (19)
nrf-mi = rpi-miso (21)

bertux
Posts: 6
Joined: Fri Jan 25, 2013 2:10 am

Re: NRF24L01 RF Transceiver

Fri Jan 25, 2013 2:48 am

Hi!
What Arduino version did you use? I can't compile anything listed on the repos above.
With some changes in other codes I can run on Arduino, but I don't know if that is correct.
The Rpi reply is "time out". But I don't know if the Arduino or Rpi is wrong.
Can someone give me a hand?

micheljansen
Posts: 2
Joined: Sat Jan 26, 2013 5:11 pm

Re: NRF24L01 RF Transceiver

Sat Jan 26, 2013 5:25 pm

I wired up the NRF24L01 to my Raspberry Pi according to the instructions of gnulnulf as follows:
nrf-vcc = rpi-3v3 (1)
nrf-gnd = rpi-gnd (6)
nrf-ce = rpi-ce0 (24)
nrf-csn = rpi-gpio25 (22)
nrf-sck = rpi-sckl (23)
nrf-mo = rpi-mosi (19)
nrf-mi = rpi-miso (21)
and compiled the rpi-version of the RF23 library from here: https://github.com/gnulnulf/RF24

So far so good: the "pingtest" program compiles, links and runs without segfaults (as root), but it doesn't behave as expected:

Code: Select all

STATUS		 = 0xff RX_DR=1 TX_DS=1 MAX_RT=1 RX_P_NO=7 TX_FULL=1
RX_ADDR_P0-1	 = 0xffffffffff 0xffffffffff
RX_ADDR_P2-5	 = 0xff 0x00 0x00 0x00
TX_ADDR		 = 0x0000000000
RX_PW_P0-6	 = 0xff 0xff 0xff 0xff 0xff 0xff
EN_AA		 = 0xff
EN_RXADDR	 = 0xff
RF_CH		 = 0x00
RF_SETUP	 = 0x00
CONFIG		 = 0x00
DYNPD/FEATURE	 = 0xff 0xff
Data Rate	 = 1MBPS
Model		 = nRF24L01
CRC Length	 = 16 bits
PA Power	 = PA_HIGH
Receiving... 4294967295 Sent response.
Receiving... 4294967295 Sent response.
Receiving... 4294967295 Sent response.
Receiving... 4294967295 Sent response.
Receiving... 4294967295 Sent response.
...
It seems that the communication between the Raspbery Pi and the nRF24l01 is not working as it should. All the flags are on and the addresses are not configured. Also, the initialisation in setup() appears to set a different data rate than is printed here. Then, when receiving, it always has data available, and it is always signed -1 / unsigned 2^32-1.

Any idea what's happening here? I tested the module on an Arduino and it seems to work fine there (but it doesn't have anything to talk to).

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Sat Jan 26, 2013 6:49 pm

Code: Select all

root@raspberrypi:/usr/src/rf24-gnulnulf/RF24/librf24-rpi/examples# export LD_LIBRARY_PATH=.
root@raspberrypi:/usr/src/rf24-gnulnulf/RF24/librf24-rpi/examples# ./pingtest
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xf0f0f0f0d2 0xf0f0f0f0e1
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR          = 0xf0f0f0f0d2
RX_PW_P0-6       = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA            = 0x3f
EN_RXADDR        = 0x03
RF_CH            = 0x4c
RF_SETUP         = 0x25
CONFIG           = 0x0f
DYNPD/FEATURE    = 0x3f 0x04
Data Rate        = 250KBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = LA_MED
Now sending length 4...Failed, response timed out.
I see we could have different hardware, as I have nRF24L01+ .
You can try my binaries if you like. What raspberry version do you have?

@Bertox I use Arduino 1.0.3. I'm not an arduino wizard or something but if you need more help let me know.

micheljansen
Posts: 2
Joined: Sat Jan 26, 2013 5:11 pm

Re: NRF24L01 RF Transceiver

Sat Jan 26, 2013 8:53 pm

gnulnulf wrote: I see we could have different hardware, as I have nRF24L01+ .
OK, I am mildly ashamed to report that I somehow managed to swap the MOSI and MISO pins, and only notice after checking three times... After wiring things correctly, mine is now also reported as an nRF24L01+.

Which brings me to the next problem: I managed to get my Raspberry Pi to talk to an Arduino successfully, but things are not behaving the way they should.

I am using the original "ping" program that came with the Arduino version of the RF24 library (the one that sends the time). The Rpi then reads that and echoes the message back to the sender.

In short, the Arduino send like this:

Code: Select all

unsigned long time = millis();
printf("Now sending %lu...",time);
bool ok = radio.write( &time, sizeof(unsigned long) );
    
if (ok)
  printf("ok...");
else
  printf("failed.\n\r");

// Now, continue listening
radio.startListening();

// Wait here until we get a response, or timeout (250ms)
unsigned long started_waiting_at = millis();
bool timeout = false;
while ( ! radio.available() && ! timeout )
  if (millis() - started_waiting_at > 1000 )
    timeout = true;

// Describe the results
if ( timeout ) {
  printf("Failed, response timed out.\n\r");
}
else {
  // Grab the response, compare, and send to debugging spew
  unsigned long got_time;
  radio.read( &got_time, sizeof(unsigned long) );

  // Spew it
  printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
}
And the Raspberry Pi just replies.

I can see the packets arrive on the Raspberry Pi and I can see the replies come back in on the Arduino, but this is the weird thing:

the write() command on the Arduino always returns false:
Now sending 1944608...failed.
Got response 1944608, round-trip delay: 110
Now sending 1945718...failed.
Got response 1945718, round-trip delay: 111
Now sending 1946829...failed.
Got response 1946829, round-trip delay: 110
Now sending 1947940...failed.
Got response 1947940, round-trip delay: 109
[/quite]

According to the documentation in RF24.h, this should indicate that the message was not successfully delivered (acknowledged). From what I can see, messages clearly do get delivered successfully, so why is write() still returning false? Are the acknowledgments not being sent? The documentation suggests that autoAck should be on by default, so what's going on here?

I set up both nodes like this:

Code: Select all

        radio.enableDynamicPayloads();
        //radio.setPayloadSize(8);
        radio.setRetries(15,15);
        radio.setDataRate(RF24_1MBPS);
        radio.setPALevel(RF24_PA_HIGH);
        //radio.setChannel(120);
        radio.setCRCLength(RF24_CRC_16);
I realise this is hardly a Raspberry Pi-specific problem, but perhaps one of you has bumped into this before and knows what's happening :)

Return to “HATs and other add-ons”