stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Tue Mar 19, 2013 3:42 pm

Dear Charles / gnulnulf,

I've merge both the gpio and bcm2835 into my fork and re-organize the folders accordingly..

librf24/*.cpp *.h Makefile
librf24/examples
librf24-bcm/*.cpp *.h Makefile
librf24-bcm/examples

Hope both of you will adopt this folder structure to prevent any confusion for future users of this libraries...

We will continue to test and improve the bcm2835 libs...

If both of you are ok, I will PUSH this to yr upstream and downstream repos...

Stanley
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Wed Mar 20, 2013 9:24 am

Stanley,

No problem at all for me, you can change the folder structure as you wish

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

Re: NRF24L01 RF Transceiver

Wed Mar 20, 2013 5:21 pm

is the bcm lib not always setting CE0 and CE1?
always setting the SPI_CE to custom would work for the nrf. Any GPIO would do then and maybe we should avoid using the CE0/CE1 in total to leave those for proper spi use.

if the bcm is working better we should completely drop the other one.
Both are working here and I like the idea of having classes for spi to have it compatible with other systems.

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Wed Mar 20, 2013 6:52 pm

gnulnulf,

bcm version can still use custom GPIO as CSN/Slave Select

So far the gpio version (or shd I call it the s/w based version), ALL the examples are working properly... CE0(/dev/spidev0.0) & GPIO25 for CE... but the bcm version, can communicate with the NRF, receiving a single ping/pong will caused the program to exit...

I can run both version on the same pinout and do any testing/debugging without switching between branches...
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Thu Mar 21, 2013 7:06 am

Hello Charley, Gnulnulf, Stanley,

I found your library for nrf24l01 quite helpful. I am able to read registers, set channel, datarate, all sems fine. Unfortunatly, it seems it is not compatible with the original library [1] .
In particular i run the following code on the sender, on channel 0x02 with 2MBPs:

Code: Select all

uint8_t status;
		do {
//			ktimer_wait(KTIMER_TICKS(500));

			status = nrf24l01_write_tx_payload(data, 32, true); //transmit encrypted byte and counter
			printf("Sent: %lu\n", counttest);

			//wait for the packet to be sent
			while( !(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active()) )
				;
			nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
			counttest++;
			data[0] = counttest & 0xFF;
			data[1] = (counttest>>8) & 0xFF;
			data[2] = (counttest>>16) & 0xFF;
			data[3] = (counttest>>24) & 0xFF;
		} while( 1 );

I have set up my raspberry with the following:

Code: Select all

SPI device	 = /dev/spidev0.0
SPI speed	 = 2000000
CE GPIO	 = 25
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	 = 0xe2 0xe3 0xf1 0xf2
TX_ADDR		 = 0xf0f0f0f0d2
RX_PW_P0-6	 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA		 = 0x3f
EN_RXADDR	 = 0x3f
RF_CH		 = 0x02
RF_SETUP	 = 0x0b
CONFIG		 = 0x0f
DYNPD/FEATURE	 = 0x00 0x04
Data Rate	 = 2MBPS
Model		 = nRF24L01+
CRC Length	 = 16 bits
PA Power	 = PA_LOW

Now if radio.available() gets true i want to print anything. I modified the pongtest.cpp:

Code: Select all

   
if ( radio.available() )
    {
     printf("radio is avaialable\n");
     [...]
but there is never a packet received, though sender constantly sends.
The sender is running in autoack. Currently have no JTAG to flash anything else to the sender.

Any hint is appreciated.

Greetings,

Adam

[1] http://www.diyembedded.com/tutorials/nr ... rial_4.zip

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Thu Mar 21, 2013 9:30 am

OK, I run the bcm library now, and get at least a positive radio.testCarrier(), but i never get any payload..

Code: Select all

        for(int k=1;k<128;k++){
        //      printf("listen on channel %d\n",k);
                radio.setChannel(k);
                radio.startListening();
                delayMicroseconds(128);
                radio.stopListening();
                if ( radio.testCarrier() ){
                        printf("carrier on channel %d\n",k);
                }
        radio.read( values, sizeof values );
        uint32_t counttest = values[0] + (values[1]<<8) + (values[2]<<16) + (values[3]<<24);
        if(counttest!=0){
                printf("Received: %lu\n", counttest);
        }
        for(int j=0; j<30; j++){
                if(values[j]!=0){
                        printf("v[%d]: %d\n",j, values[j]);
                }
        }
        }
Output:

Code: Select all

================ SPI Configuration ================
CSN Pin  	 = Custom GPIO8
CE Pin  	 = Custom GPIO25
Clock Speed	 = 256 KHz
================ NRF Configuration ================
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	 = 0xe2 0xe3 0xf1 0xf2
TX_ADDR		 = 0xf0f0f0f0d2
RX_PW_P0-6	 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA		 = 0x3f
EN_RXADDR	 = 0x3f
RF_CH		 = 0x02
RF_SETUP	 = 0x0f
CONFIG		 = 0x03
DYNPD/FEATURE	 = 0x00 0x04
Data Rate	 = 2MBPS
Model		 = nRF24L01+
CRC Length	 = Disabled
PA Power	 = PA_MAX
00000000000000001111111111111111
0123456789abcdef0123456789abcdef
carrier on channel 71
carrier on channel 23
carrier on channel 66
carrier on channel 62
carrier on channel 57
carrier on channel 49
carrier on channel 3
carrier on channel 43
carrier on channel 70
carrier on channel 71
carrier on channel 38
carrier on channel 73
carrier on channel 69
carrier on channel 3
carrier on channel 56
carrier on channel 2
carrier on channel 47
carrier on channel 75
carrier on channel 1
carrier on channel 41
carrier on channel 2
carrier on channel 36
carrier on channel 32
carrier on channel 75
carrier on channel 3
carrier on channel 26
carrier on channel 69
It seams there is a lot of noise. The NRF24L01 is next to a WLAN -router, maybe its too much noice to get any payload?

Greetings,

Adam

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Thu Mar 21, 2013 10:00 am

OK have rechecked. When sender is of no carriers are detected. That means, the output is caused by this single sender. The sender send constantly on channel2 a packet i posted in my first post.

So obviously the protocols are not compatible?

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Thu Mar 21, 2013 12:46 pm

ltune wrote:Hello Charley, Gnulnulf, Stanley,

I found your library for nrf24l01 quite helpful. I am able to read registers, set channel, datarate, all sems fine. Unfortunatly, it seems it is not compatible with the original library [1] .
[1] http://www.diyembedded.com/tutorials/nr ... rial_4.zip
What do you mean by original libs ? I've no idea about it..

This RPi uses the RF24 libs ported from Arduino to RPi... so any Arduino or RPi shd be able to talk to each other...

See here :- https://github.com/gnulnulf/RF24/network/ with all the available forks..

The librf24bcm still have some bugs to be fixed, pls use the librf24 libs ...
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Thu Mar 21, 2013 12:57 pm

Hi Stanley,

with original library i probably mean the one for LPC2148 from Brennen Ball he wrote back in 2006-2007 [1]. The problem is I need to be compliant with that protocol. I found the bcm2835.c in the bcm-lib and try to achieve correct low level communication. It is really a hell. I managed to run the read_register and write_register routines. Currently I am stuck in reading payload because you use a C++ call to "reinterpret_cast" , I cannot compile in simple C.

Thanks for help,

Adam


[1] http://blog.diyembedded.com/

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Thu Mar 21, 2013 6:38 pm

A few things I notice...

The RF24 libs does NOT use the IRQ pin on the nRF, are the sender running on NXP LPC2148 or Microchip PIC18F452 microcontrollers as per the blog ??

From the code below, if you issue radio.stopListening() you are putting it into TX mode and NOT in read mode...

If you look at my code at rpi-hub.cpp , the sequence is radio.stopListening(), radio.available() then radio.read()...

Pls read the nRF24L01 datasheet at page 23 on the different modes...

Code: Select all

                radio.startListening();
                delayMicroseconds(128);
                radio.stopListening();
                if ( radio.testCarrier() ){ 
                   printf("carrier on channel %d\n",k);
                }
        radio.read( values, sizeof values );
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Fri Mar 22, 2013 7:48 am

Hi Stanley,
are the sender running on NXP LPC2148 or Microchip PIC18F452 microcontrollers as per the blog ??
I would say so, you can see it in the code below. It listens on IRQ until it gets an interrupt:

Code: Select all

 //wait until a packet has been received
                while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()));

                nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
                nrf24l01_read_rx_payload(data, 2); //get the payload into data
But that is on the microcontroller (avs extrem board) site. The packets should be received.

What I wonder is, that my ender send constanly on channel 2 and the raspberry gets carrier sensing on different channel among the correct channel 2.

The problem is also, in my case, the available() method gets true about every 100,000th call.
I wonder maybe the probem is the protocol. On page 28 is packet with burst-mode. I suspect my sender is running without shockburst and on raspberry pi shockburst is enabled.

The sender is sending on channel 2 constanly an incremented integer. When raspberry things those are shock-burst register it will seldom get payload.

EDIT: I tried to run both enableDynamicPayload() and setPayloadSize(32), also tried autoAck with true and false. I have no clue why it does not work. They probably are simply incompatible.

Greetings,

Adam

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Wed Mar 27, 2013 8:18 am

Hi,

I notice that using the low level bcm2835.c functions I can read and write registers. (e.g. set channel or auto-ack). However, in your "receive_payload" method there is a C++ call (reinterpret_cast), as I mentioned in a previous post, I do not know how to write it in C. I was told when reading and writing registers works, payload is nothing different.

Thanks for help.

Adam

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Fri Mar 29, 2013 6:57 am

I notice that using the low level bcm2835.c functions I can read and write registers. (e.g. set channel or auto-ack). However, in your "receive_payload" method there is a C++ call (reinterpret_cast), as I mentioned in a previous post, I do not know how to write it in C. I was told when reading and writing registers works, payload is nothing different.
You might want to look at mirf libs for the AVR... they are written in C lang ...
http://www.tinkerer.eu/AVRLib/nRF24L01

This is one of the earlier nrf24l01 libs that was written a few years ago..
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

ltune
Posts: 7
Joined: Thu Mar 21, 2013 6:55 am

Re: NRF24L01 RF Transceiver

Fri Mar 29, 2013 7:34 pm

Hi Stanley,
You might want to look at mirf libs for the AVR... they are written in C lang ...
http://www.tinkerer.eu/AVRLib/nRF24L01

Thanks! I looked on that mrf code and compared with your RF24 lib and finally got it to work:

-Put CE high
-Put CSN low
-read payload
-put csn high
-put ce low

Now I get the data :D Happy Eastern!

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

Re: NRF24L01 RF Transceiver

Fri Mar 29, 2013 10:17 pm

and we've almost looped back to the portable RF24 lib :D

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Fri Mar 29, 2013 10:58 pm

ltune wrote:Hi Stanley,
Thanks! I looked on that mrf code and compared with your RF24 lib and finally got it to work:
Are you running the encryption examples on the "avs extrem board" with RPi ??

Pls post more details of yr projects once everything is running ok..
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

RexCortex
Posts: 1
Joined: Wed Apr 03, 2013 2:46 pm

Re: NRF24L01 RF Transceiver

Wed Apr 03, 2013 3:15 pm

Hi,

First of all, thank you for your effort in sharing both your code and knowledge on the NRF24.

I originally tested gnulnulf rpi library with success. But I have trouble getting communication with payload size < 32 (both between arduino<->arduino and arduino<->rpi) so I decided to have a look on github forks and found updated version from stanley.

Newer version of the lib gives me randomn sequence of consecutive 0's and 1's (guess it by looking at the debug informations and payload).

Correct output with older library:
Image

Incorrect output with newer library:
Image

I read that you changed something about GPIO pins, do I need to change wiring or do you have any idea?

Thank you

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Fri Apr 05, 2013 8:34 pm

RexCortex wrote:Hi,
I read that you changed something about GPIO pins, do I need to change wiring or do you have any idea?
I can hardly see yr screenshot, they are too tiny.. :D

For the latest GPIO codes ( librf24 ), make sure nRF-CSN = GPIO8 and nRF-CE = GPIO25 (if you do not modify the codes in the examples... )

I've got all the examples working for any combo of RPI/Arduino UNO as hub/nodes...

I've added a few performance improve made by Greg Copeland into the RPi version... http://maniacalbits.blogspot.com/2013/0 ... anced.html
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

gerg
Posts: 2
Joined: Fri Apr 05, 2013 9:03 pm

Re: NRF24L01 RF Transceiver

Fri Apr 05, 2013 9:13 pm

I saw some pingbacks from here so I thought I might offer some information on my fork and some general FYI.

Here's a blog entry on my fork: http://maniacalbits.blogspot.com/2013/0 ... -fork.html
The link to my fork is in the post, but I'll provide it again here: https://github.com/gcopeland/RF24

If you're using these radios, you'll likely also be interested in reviewing my other two blog articles on these guys.
http://maniacalbits.blogspot.com/2013/0 ... quire.html
http://maniacalbits.blogspot.com/2013/0 ... anced.html

Okay, with the shameless self promotion out of the way, I'll provide a bit of a cautionary tale. I don't know anything about the voltage regulator you guys are driving these radios, but the radios are fairly power and noise sensitive. This is especially true on the long range units (PA+LNA). On the Arduino forums, with mega2560's, people have noticed issues such as what was reported above. The only time I've ever see that is when the wiring was wrong, or when I was running on a mega2560 without the caps. I can't say its the same issue observed here, but it may be worth consideration.

Here's the Arduino Mega2560 thread: http://arduino.cc/forum/index.php/topic,82906.0.html

Basically, if you have two caps, you can test to see if this is an issue for you or not. One large cap to ensure the regulator is not browning out on your. The second, smaller cap, is to ensure you're filtering noise. Ideally both caps will be as close as is possible to the radio. I'm using a 22uF (ceramic) and 320uF (electrolytic) caps.

ffimon
Posts: 7
Joined: Tue Feb 19, 2013 9:55 pm

Re: NRF24L01 RF Transceiver

Sat Apr 06, 2013 8:49 pm

gerg wrote: I'm using a 22uF (ceramic) and 320uF (electrolytic) caps.

Seems an odd value for Ceramic ? 22uF

gerg
Posts: 2
Joined: Fri Apr 05, 2013 9:03 pm

Re: NRF24L01 RF Transceiver

Sat Apr 06, 2013 10:41 pm

Seems an odd value for Ceramic ? 22uF
Opps. Good catch there. Its actually a 22pF cap. I just happen to have it on another breadboard for a crystal on an ATMEGA8. So I re-purposed it for breadboard testing. Since I've started using the two caps, all of my mega2560 + rf24 module issues have gone away.

I wish I had a scope to see what kind of noise I'm looking at, but the caps seems to have been enough to make the radio happy. Which in turn makes me happy.

akinich
Posts: 3
Joined: Fri Apr 19, 2013 3:44 pm

Re: NRF24L01 RF Transceiver

Mon May 13, 2013 10:02 am

hi
i can see a lot of work is happening around here
im a total beginner when it comes to coding , i would like to know if there are any simple instructions to get communication working between the rpi and arduino ?
any idiot proof ways ?
thanks

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Mon May 13, 2013 10:54 am

akinich wrote:hi
i can see a lot of work is happening around here
im a total beginner when it comes to coding , i would like to know if there are any simple instructions to get communication working between the rpi and arduino ?
any idiot proof ways ?
thanks
http://arduino-for-beginners.blogspot.c ... es-to.html

You can blindly follow the instructions step by step without knowing what is going on behind the scene...

Stanley
Last edited by stanley on Mon May 13, 2013 9:20 pm, edited 1 time in total.
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

klalle
Posts: 1
Joined: Mon May 13, 2013 1:56 pm

Re: NRF24L01 RF Transceiver

Mon May 13, 2013 8:15 pm

I am new to raspberry pi and linux, but used to programming nrf24l01 and AVR....

I have successfully got the SPI to talk to the nrf following this guide:
http://arduino-for-beginners.blogspot.s ... es-to.html

and swapping the ce and csn pin...

Now wonder where the configuration file is, where i set the addresses, channels and so on?
Since i want to do more than just ping and pong with my rpi, it would be quite handy to know ;)

/kalle

akinich
Posts: 3
Joined: Fri Apr 19, 2013 3:44 pm

Re: NRF24L01 RF Transceiver

Tue May 14, 2013 7:05 pm

thanks for the guide
can i use the raspbian instead?

Return to “HATs and other add-ons”