Uncategorized

nRF24 learning notes

Q: Rpi SPI nRF24L01+ 2.4GHz Transceiver Module Send Message to Arduino Problem

StevenCellistI have recently bought two nRF24L01+ radio chips for communication between my Raspberry Pi and Arduino. I will be solely using this from Raspberry towards Arduino. The tutorial I followed: circuitdigest.com/…

StevenCellist
StevenCellist
Figured my Arduino gives that output even while the Raspberry is turned off…
Also figured that my wireless mouse and keyboard might be interfering but unplugging and turning off those didn’t make any difference
tlfong01

tlfong01
2618
Hi @StevenCellist, Welcome and nice to meet you. Ah, let me see. If Arduino gives same output even Rpi is turned off, then Arduino is not receiving anything or just rubbish from Rpi, and so the problem is perhaps on the Rpi side. Let us start doing troubleshooting the Rpi side: (1) Make sure the SPI software and hardware wiring is OK, by doing SPI loop back. (2) Make sure nRF24L01 is working, by pinging, ie, read config register 0x00 should read 0x80. Of course you can skip (1) and just do (2) If you read 0x80 from nRF24L01’s register 0x00, then SPI is OK. / to continue, …
(3) Read the tutorial “Wireless RF Communication using nRF24L01 Module -Abhiemanyu Pandit 2019aug01, circuitdigest.com/microcontroller-projects/…, (4) Run the tutorial’s python program for Rpi. The statement “radio.printDetails()” should print the “details” does it?
References: (1) nrf24l01 Features – components101 components101.com/wireless/nrf24l01-pinout-features-datashee‌​t (2) nRF24L01+ Single Chip 2.4GHz Transceiver Product Specification v1.0 – Nordic 2008 components101.com/sites/default/files/component_datasheet/…
Ref (1) says the following: “The nRF24L01 module is a bit tricky to use especially since there are many cloned versions in the market. If you are having any problem with getting it work, try adding a 10uF and 0.1uF capacitor in parallel to the Vcc and Ground pins. Also make sure the 3.3V supply is clean and does not have any noise coupled in it.”
Then read the GitHub for the bad news: only for “virtual GPIO”, no longer supported. nRF24L01 Python Library – BLavery/lib_nrf24 2018 may V0.3 beta, no longer being maintained by the original author github.com/BLavery/lib_nrf24 For Raspberry Pi and virtual-GPIO. NRF24: strictly 3.3V supply!! Although logic pins are 5V tolerant.
Docs says the following: “This is BETA only so far. Everything has worked earlier, send, receive, including two RF24 on one host, and including RPI, virtual-GPIO and regular arduino sketch, all talking to each other. But recent testing has been only LIBRARY plus “example-nrf24-pair.py” on virtual-GPIO, so other parts are yet to be re-verified.”
# StevenCellist, So are you using “Virtual GPIO”? Have you found any updated program NOT using virtual GPIO? The Rpi python program looks not that hard. Perhaps you can rewrite it not using virtual GPIO. PS – I NEVER heard of “virtual GPIO”, so I asked.
I visited GiHub and found it was 5 years old, tweaked from the BegaBone program. So I don’t think it worth your time playing with a Non rpi hardware compatible, tweaked program and NO LONGER supported. Find an updated Rpi program and let me know. Thanks and cheers.
Just now I searched this forum for “nRF24L01” and found 100+ posts. I skimmed and found the follow best for troubleshooting: “Major trouble with nRF24L01+ controllers and the RF24 library – Asked 5 years ago Viewed 8k times” (1) raspberrypi.stackexchange.com/questions/23441/…. Many of the 100+ posts above had not answers, but this very good one by @jhallard summarized the causes of trouble and also gave a good recommendation for testing.
As I said earlier, I have done the following last evening: (1) Used SPI loop back test to make sure that SPI wiring is working, (2) Use a one line python statement to read the nRF24L01’s config register at address 0x00 and read successfully the default POR contents of 0x80. Next step is to try any tutorial but NOT your recommended one, for the reasons I gave above. In case you read the the above post @jhallardand and wish to try another tutorial recommend there, and still have problem,s I am happy to reproduce your setup, and see if I overlooked any other causes of trouble. Cheers.
If you read the 100+ old posts on nRF25L01, you might find there a couple of traps for newbies, including the following: (1) If you started your project with 5V Arduino and any Arduino compatible nRF24 modules, you might forget that Rpi is 3V3 only and power for Rpi is indeed 5V, but be WARNED that the nRF24 module for Rpi (but not for Arduino) might not have any 5V to 3V3 step down regulator, so you MUST use 3V3 power for the module, otherwise your nRF24 might FRY IMMEDIATELY!
(This is the reason I suggest you to loopback test SPI and ping (read nRF24 config register to make sure your nRF24 is not fried). (2) As pointed out earlier, there are quite a lot of different nRF25 modules on the market, some have 8 Bit connector, some 12 bit, mine tested OK for Rpi4B has 9 pins, including the antenna pin!, So you to very carefully compare and contrast the version you have to make sure you have wired correctly, beside using 0.1uF, 1/10uF to bypass the power supply fi your nRF is a low quality one without any regulator or bypass/decoupling caps.
Your module, if cheapy module from eBay might not have the necessary pull up resistors on module. For example, the interrupt pin or select module send/or receive mode, if no default pull up/downs, left floating, might be wrongly set to receive mode, instead of send mode which is what you want. Otherwise your nRF might not send, even your program is correct. (3) Some modules have confusing labels CEn, CSn, selectCE etc which might be Arduino friendly, but mislead you to wrongly use the hardwired nrF sen/receive mode pin for the SPI chip slect pin.
You might like to show us a picture of you module showing the SPI and send/receive mode pin and interrupt pin wiring, and I can compare your wiring with mine ( pin version) which has been tested OK. Cheers.
One more thing. I noticed that your question says you are using the “Plus Model” (nrf24L01+, with the “+’ at the end.) If you are using the following + model, then you need to be very careful: “NRF24L01+ 2.4G ATMEGA48 wireless data transmission module + NRF24L01 arduino compatible US$3.50” fr.aliexpress.com/item/1976744557.html. ANOTHER WARNING: The module power supply is 5V, but there is NO wrong polarity protection, meaning that if you supply power with the wrong polarity, the module will get very hot and might fry in less than one minute.
StevenCellist

StevenCellist
11
That’s a lot of stuff to work through.. thanks for all the recommendations! Unfortunately I have two test for university coming up next week, so I won’t have any time till something like Wednesday. I will let you know once I’m working on it again! And thanks for all the information provided!!
Quick confirmation that I indeed am using the + version, shop link: tinytronics.nl/shop/nl/communicatie/rf/… (I am Dutch). Is it recommended to also buy the Adapter Board? tinytronics.nl/shop/nl/communicatie/rf/…
tlfong01

tlfong01
2618
Ah, take your time. We can pause for a couple of days, and resume after your exams. Ah, I don’t know nothing about the nRF24 adapter board, I guess it is for Arduino, but only 50% sure. Perhaps you go study for you exam now, and me in the mean time leisurely google around. Good luck to your exam and cheers.
Just now I had a quick look of the adapter thing. I now guess is just a stupid 8 pin to 5 pin or 6 pin conversion board. My three or four modules are straight connectors with 6 or 9 or more pins. Need to check out later. Cheers.
3 hours later…
StevenCellist

StevenCellist
11
Jan 24, 22:20
Okay I just did a loopback
I got ‘0E 00 00 00 …’ as result. (… filled with 00’s)
STATUS = 0x07 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=3 TX_FULL=1
RX_ADDR_P0-1 = 0xf0f0f8f8f0 0xe1e1e1e1e1
RX_ADDR_P2-5 = 0xe1 0xe2 0xe2 0xe3
TX_ADDR = 0xf0f0f8f8f0
RX_PW_P0-6 = 0x04 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x1f
EN_RXADDR = 0x01
RF_CH = 0x3b
RF_SETUP = 0x00
CONFIG = 0x06
DYNPD/FEATURE = 0x0f 0x03
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN
Result of print details
I do not really have a clue of the CONFIG is what you’re looking for while trying to read 0x80 from the 0x00 register
tlfong01

tlfong01
2618
Jan 24, 22:51
Ah, I am sorry to have misled you to try the spi lookback and then read the config register. This test is only a preliminary test or troubleshooting tool to make sure your SPI hardware/software setup is OK, and reading module’s config register is sort of ping ing it. But now your python program can print the module registers as you just listed, there is no need to do the spi loopback and read config.
And we can now look into what the python program is doing and if we can try to do some troubleshooting. But I think you need to prepare for your exam now, so I should not bother you by suggesting any plan now. See you after your exam! Good luck. Cheers.
StevenCellist

StevenCellist
11
Nah I need something to do instead of studying sometimes.. I’ve got one more hour right now
I do not yet have any capacitors myself, but I just need any communication; reliability is only once I know they are communicating
StevenCellist

StevenCellist
11
Jan 24, 23:32
Alright I’ve just used the ‘scanner’ sketch from the library provided on Arduino
Here’s the result:
RF24/examples/scanner/
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xe7e7e7e7e7 0xe0e0f1f1e0
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xe7e7e7e7e7
RX_PW_P0-6 = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x00
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x01
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MIN
000000000000000011111111111111112222222222222222333333333333333344444444444444445555555555555555666666666666666677777777777777

(see full text)

Now somewhere after 16 lines into the scanner procedure, you can see two lines only filled with zeros. That’s where I unplugged the nRF module from the Pi, but I connected it only 7 lines from the bottom again
18 hours later…
tlfong01

tlfong01
2618
Jan 25, 17:44
Sorry, I have no Arduino on hand to test the “scanner” sketch. But I have a question on the performance of the Arduino sketch. Please first confirm the test setup is as summarized below. (1) First setup Arduino and run the receive message sketch, which is an infinite loop waiting for message from Rpi, and prints the message at the serial monitor, and also the message “Turning off radio”,
(2) Then setup Rpi and run the its “send message” python program, as often as you like. Now every time you run the Rpi send message, only if Arduino side got the Rpi message, then it will print the received message, then the “Turning off radio”.
No if Rpi sends message “Hi” three times, and only if Arduino receives “Hi” every time, it will print the “Hi” on the serial terminal, then followed by “Turning off radio”. This is the part I don’t understand.
To debug, I would suggest to insert the following confirmation message something like, “Serial.println(“yes, I got the message”) BEFORE the statement. “Serial.println(receivedMessage)” This way, even if Arduino gets an empty message, it will still print the “yes, I got the message”, before the “Turning off radio”. I guess this is also your question. I am just making a quick and dirty, brainstorming reply. Nothing urgent to reply now, perhaps only after you exam.
By the way, I tried to google for a more up to date nRF24L01 python library, but no luck, I only found similar libraries forked from the same source, Brian Lavery Oct 2014. Perhaps I should google harder, but it is unlikely I could find more useful things, as this nRF24L01 library stuff has been non active for a couple of years, and all the original or forking authors said they don’t support their libraries any more, and that a couple of thins not yet tested, so it is discouraging, 😦
So I will pause for now, and perhaps see your opinion after your exam. By the way, I studied the python library github.com/BLavery/lib_nrf24/… and found it not that complicated. Perhaps in the long run, I would buy a new version of nRF24L0-1+ (my modules in hand are very old!)
One more thing, if I am going to fork/modify the BLavery library, perhaps I would consider two Rpi python program, one send message, another receiver message. Then I can use two Rpi’s , or one Rpi controlling two nRF24 at the same, time, one using Spi0.0, the other Spi1.0 say. But that is a long term project, at least not for these couple of months. Cheers.
1 hour later…
tlfong01

tlfong01
2618
Jan 25, 19:16
By the way, a good reference for Pi to Pi nRF24L01 is the #13 Tutorial by Module143: (1) Rpi3 Tutorial 13 – Pi to Pi Python Communication with NRF24L01+ – Module 143 Sushant Narang 216jun13
invent.module143.com/…

(2) Rpi3 Tutorial 14 – Pi to Arduino Python Communication with NRF24L01+ – Sushant Narang Module 143 2016jun14
invent.module143.com/….

(see full text)

The Module143 Tutorial #13 has two nRF24L01 demo python programs, one for transmit, another for receive. So I guess it is easier to test both transmit and receive using two or just Rpi’s, without bothering Arduino. By the way, I am curious to know why you start with Pi and Arduino, but not Pi to Pi?
tlfong01

tlfong01
2618
Jan 25, 19:36
And now I have saved the BLavery RF24L01 Library and Demo Porgram listing for future reference: BLavery/lib_nrf24 program listing Brian Lavery Oct 2014 v0.1

penzu link: penzu.com/p/23fef382.

tlfong01

tlfong01
2618
Jan 25, 20:36
As I said earlier, I do not have an Arduino in hand to test the nRF24L01 receiving mode, so I am thinking of using Rpi to test the receiver. A more ambitious goal is to use one Rpi running in multi-processing/multi-threading mode, one transmitter and one receiver. Another thing is to use a scope to display the no modulation carrier waveform, to see how to change the nRF24 options to get the highest output power, as shown in the following picture: (sorry, cannot upload, will try later, :()
user image
The above picture is one of the many summary screen captures of my datasheet reading summary. I am compiling a gallery of those pictures perhaps I might show you later. These pictures help refreshing my memory of datasheet reading.
tlfong01
tlfong01
Jan 25, 20:56
There you are, my datasheet reading summary: penzu.com/p/fb5096a7.
tlfong01

tlfong01
2618
Jan 25, 21:08
And skimming the above pictures, I have summarized the following setting for maximum power output: For troubleshooting, set max power (1) air data rate 250kbps, (2) SPI 100kHz, (3) Tx Setting PwrUp = 1, PrimRx = 0, CE input pin = 1,
(4) Check received power detector (Reg 9, bit 0), (5) max power setup RF-PWR = 11 0dBm (6) Config reg setup bit 1 pwr_up = 1, PRIM_RX = 0.
tlfong01

tlfong01
2618
Jan 25, 21:27
Now I am reading more carefully the Transmit and Receive python programs, both for Rpi. I found it easier to understand what is going on each side, if both program are written in Rpi python, because there is many sections in common, and in the first transmit program, the mirroring parts are commented out, so it should be easy to compare and contrast the two programs. I still find the listening part confusing. So I need to read the library now, which is much longer than the demo programs.
tlfong01

tlfong01
2618
Jan 25, 21:54
Now I have read the nRF24L01 library in python. I am happy to find that the program is very well structured, and self documented, so it is easy to do any maintenance or modification. Earlier I said that I am not interested to use this library which is no longer maintained by the original author, and not all features are tested. Now I have changed my mind, because now I think that this library seems well developed, and so it is a good idea to play with it.
@StevenCellist @StevenCellist, as I said earlier, I think it is worth my time to test without Arduino, but just use two Rpi’s, one to transmit, the other to receive. And everything goes well, we can try one Rpi, two multi-processing functions, one transmit, another receive. But I am tied up with other toy projects and would not be able to start playing now.
So if you are using my suggested one Rpi two python programs, I am interested to join in. Nothing urgent, no need to reply, until you finish your exam. So see you on Wednesday or later. Cheers.
2 days later…
tlfong01

tlfong01
2618
Jan 27, 13:46
I read your sendMessage.py program a second time, and guess it is doing the following three things: (1) setup the nRF24 module, and print what has been setup, (2) Send the message “Hi” only cone, (3) Change to listener mode and listen for only 2 seconds, and print “time out” if not receiving acknowledgement from Arduino?
Now I think we can do the following to troubleshoot: (a) Instead of sending message just once, we can repeatedly send the same message every 4 seconds, and see if Arduino can get the message, (b) Instead of setting only two seconds time out, of course we can set longer, say, two minutes time out, so to give more chances for Arduino to respond.
1 day later…
StevenCellist

StevenCellist
11
Jan 28, 17:27
Alright I aced my first exam yesterday and mnext exam on Friday is Python programming.. so no worries about that one!
I am trying to set up a second raspberry right now, but I am out of SD cards so I hope I can fix one of the broken ones
1 day later…
tlfong01

tlfong01
2618
Jan 29, 19:09
How nice you aced one exam, and next one is a piece of cake for you. So next step is continue troubleshooting. I have already ordered the new version of the module (only
¥7 a piece): item.taobao.com/…. I guess my toy would arrive before this weekend. Then we can cross check each other’s setup and testing, sort of “pairing programming/development) and make troubleshooting more efficient.
StevenCellist

StevenCellist
11
Jan 29, 19:31
Wow that’s so nice of you!!
I managed to recover the SD card so I might be booting the second Pi up tonight, and I’ll see if I can have them communicate
I have been installing PiHole yesterday, so I didn’t manage to test the radio
3 days later…
tlfong01

tlfong01
2618
Sat 13:12
My toys departed just now. I hope they will arrive tomorrow.
user image
6 hours later…
StevenCellist
StevenCellist
Sat 19:01
Awesome! I can’t read Japanese or Chinese or whatever that is, but I guess you ordered 6 of them? You’re definitely going for it lol!
2 days later…
StevenCellist

StevenCellist
11
Tue 6:25
Heyy
I’ve finally got my second Pi running
I tested the following tutorial: invent.module143.com/…
and I used the scripts for ‘Transmit’ and ‘Receive’
Printing the radio details does give me the proper stuff, i.e. non-0xff values
But still, it didn’t give me any communication
10 hours later…
tlfong01

tlfong01
Tue 16:40
Let us first look at the send message program: penzu.com/p/0eeb0578. So did you received the messages “no payload received”, NOT “radio turned off”, … Please confirm if I understood your situation correctly.
5 hours later…
tlfong01

tlfong01
2618
Tue 21:32
While reading transmit.py and receive.py, I found in Tutorial 13 there are two more programs called Master.py and Slave.pi. These master and slaves seem similar to the old transmit and receive programs. Do you know where are the descriptions for them? I have updated my learning notes to include them: penzu.com/p/3979e91f
5 hours later…
StevenCellist

StevenCellist
11
yst 2:33
My output was something like:
Received: []
Translating the receivedMessage into unicode characters
Loaded payload reply of [1]
And those three lines continuously looped
Those lines looped insanely fast, I couldn’t even find my radio.printdetails() after the program ran for one second
I’m 95% sure the output on the other Pi was: No payload received
7 hours later…
tlfong01

tlfong01
2618
yst 9:19
@StevenCellist Well, if the while loop runs too fast for your eyes, then of course you can slow it down by sleeping longer. And the radio.print details only print once after configuration and before the while loop. So after the printdetails, it is the while loop that causes trouble. I think we need to look at the python library to see if we can isolate some relevant sections to narrow down the trouble making guy.
8 hours later…
StevenCellist

StevenCellist
11
yst 17:37
Oh I understand why my time.sleep(100) seemed to stop the program.. In Arduino, the delay is in milliseconds so I thought 100 ms would be a good delay, but I now remember that in Python that would be 100 seconds hahah
I thought my program didn’t function anymore when I added the delay
Have you tried using the radios yourself yet? I am curious if you have the same problem
tlfong01

tlfong01
2618
Ha, so you have made some progress. My toys only arrived yesterday. I have not open the package yet. Usually I need to make a test plan before trying it, might take a couple of days, so in the mean time you very likely find more careless mistakes. I have not played this nRF24 before. My only experience is RF12 which is 433MHz. So I need to read the datasheet before I read the programs.
Now I have inserted the python library into my learning notes below. I skimmed it and found it, as I mentioned some days ago, very structured, so it should be “easy” to do some troubleshooting. This file now has the python library full listing at the beginning. penzu.com/p/3979e91f
StevenCellist

StevenCellist
11
yst 18:06
My understanding of libraries is still very small so I don’t expect myself to find anything that could cause the trouble but I will read through it when I have some spare time
I did get a warning on my B+ model actually about one of the pins already being in use, but it continued anyway
Which seemed very odd to me since I do not have any other program running
The connector to one of my screens broke two days ago by the way, so it’s gotten a little difficult for me to program them simultaneously. Might take a bit long sometimes to do something
tlfong01

tlfong01
2618
yst 18:53
Ah, usually libraries created by the hackers and developers are newbie scary, very messy, and in C/C++ and need to be complied. But if it is a python library, then it is usually 10 times easier to hack. Anyway, don’t bother to look at the library for now. Let me take some time to study it and let you know later what I think about it. By the way, I remember the nRF24 GitHub says how to set up for SPI, using source code.
This is what I am worrying, because my Rpi4B has spidev already built in the os, so using the GitHub’s spidev setup instructions might crash something. Anyway, I will not tried it. One more thing, I guess you are using two Rpi’s. I am a lazy guy and my test plan is as follows: (1) test first nRF24 module on SPI0.0, send mode, (2) test second nRF24 module on SPI1.0 receive mode,
(3) test both modules “at the same time”, sequentially (looping), or concurrently (multi-threading multi-processsing). If no luck in (3) then I will try (4) using two Rpi’s. It is a over-ambitious project, so I have only 50% confidence! 😦 PS – Don’t try hard to catch up me, I would prefer you to just watch what I am doing, and perhaps ask question along or later. I am going very slowly now, so you need to be patient! 🙂
tlfong01

tlfong01
2618
yst 19:21
user image
2 hours later…
tlfong01

tlfong01
2618
yst 21:17
user image
1 hour later…
StevenCellist
StevenCellist
yst 22:26
That’s cool! I have used multiple spidevs before so I should be able to quite follow it but we’ll see
18 hours later…
tlfong01

tlfong01
2618
16:44
Good. My first thought was to start with single SPI bus, to make it more newbie friendly. On second thought I would start with multiple SPI buses. Now I have soldered a dual nRF24 module board, and open/short tests are OK. Next step is to try to ping the modules.
user image
1 hour later…
tlfong01

tlfong01
2618
17:59
Now I am tidying up my old SPI signal routing lego board to test the two nRF24 modules.
user image
tlfong01

tlfong01
2618
18:27
Now I looking at the nRF24 library more closely, version 0.5 of nRF24 learning notes: penzu.com/public/09bf5314. There are a couple of reasons: I hope to: (1) Modify the big library to make a smaller and simplified version, for easy troubleshooting, (2) Modify some basic functions to make them more newbie friendly.
(3) Modify some special functions such as SPI, send/receive functions to make them more flexible for future applications. Now I need to first read the datasheet to understand how to read the nRF24 registers, how to config, initialize etc.
tlfong01

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.