Uncategorized

nRF24 project notes

StevenCellist
StevenCellist
Jan 24, 23:08
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
Wed 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
Wed 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
Wed 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
Wed 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
Wed 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
Wed 19:21
user image
2 hours later…
tlfong01

tlfong01
2618
Wed 21:17
user image
1 hour later…
StevenCellist
StevenCellist
Wed 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
yst 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
yst 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
yst 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.
1 hour later…
tlfong01

tlfong01
2618
yst 19:28
Now I am reading the nRF24 Library’s SPI setup method and found a big problem: SPI1 is NOT supported, module B is also NOT supported. I forgot what is the difference of SPI between Model A and Model B, but I will definitely be using Rpi4B (and perhaps also Rpi3B+ later. I remember the library is using a spidev compiled in its setup procedure. Since the library is NO longer supported by the author.
So I feel uncomfortable to use this old SPI method for Rpi Model A only, with the old complied spidev. My decision is to use Rpi4B buster (2019sep26 release)’s preinstalled SpiDev, which has many more (six, to be precise) SPI channels (or buses, I forgot which term I should use :))
user image
tlfong01

tlfong01
2618
yst 19:44
Rpi4B’s six SPI channels is too messy, and too easy to go wrong. So I think I better be humble and use only two of the six, ie, SPI0, SPI1. And with three CS pins, I can control 5 nRF24 modules. I will also be using python’s “list” and “dictionary” data structure. So it should be “easy” to later to scale up to all six SPI channels.
user image
3 hours later…
tlfong01

tlfong01
2618
yst 22:23
Now I am trying to build a minimal nrf24 library which consists of the very basic functions: (1) SPI setup, (2) nrf24 module configuration, (3) nrf24 register read write functions. With the above three basic functions, I can then config, and perform the nrf24 functions.
I am now do the top down design of the using the big library as a blueprint. The startup sections are in the top part of the following file: penzu.com/p/772fa292. Next step is reading the datasheet a couple of times and modify the template functions for nrf24.
First thing first is to read the block diagram of the nrf24 module.
user image
Then a brief description.
user image
Then a state diagram.
user image
The state diagram show TX mode and Rx mode. So I think I need to get a rough picture of what is TX and Rx modes.
user image
Then we need to check out the register map to see which registers to config, which to give commands etc. I think I should start with the config register, never mind other not so important registers.
user image
Then we need to read the command set to know how to load a message, how to send, how to receive etc etc.
user image
It is indeed very messy. Bed time. So I will call it a day. See you tomorrow.
StevenCellist

StevenCellist
11
yst 23:42
Whoa man, indeed this is a mess
I am so grateful for everything you are doing!!
I lost it when you started talking about the block diagram etc haha
I don’t know how you’re doing all this but thank you so much in advance! 🙂
10 hours later…
tlfong01

tlfong01
2618
9:58
Yes, even the nRF24 block diagram is hard to understand. But at least you must be not too lazy enough not to search the datasheet for meanings of terms like “PA”, “LNA”, GFSK” and so on, otherwise you will never catch up. Anyway, for now, you can just as I suggested earlier, sit back and watch how I am building a minimal nRF24 driver and library, … No hurry though, take your time. Cheers.
2 hours later…
tlfong01

tlfong01
2618
11:33
Now I am looking at the init method of the nRF24 library (full listing at nRF Learning Notes V0.6) penzu.com/p/303513ed The init method is basically doing two things: (1) Init SPI and GPIO assignment, (2) Configuration using 9 statements. So now I need to check out what those 9 statements are doing, and which registers, beside the Config register, need to be written:
user image
tlfong01

tlfong01
2618
11:47
Now I move on reading the “begin” method of the nrf24 class. I think the transmit.py is doing something like below: (1) create/instantiate an object of the nrf24 class. This newly created object is called “radio”. Then “radio.init” and “radio.begin” methods are called to do the initiation/setup job. Now I need to study the “begin” method and see how to do it using the functions (yes, no longer objects, all functions now) to do the corresponding “init” and “begin” tasks.
3 hours later…
tlfong01

tlfong01
2618
15:06
Now I read the nRF24 begin method and found it not that complicated, calling 6 functions and writing 3 registers. I guess the minimal driver must at least entertain these 3 registers. So I go check out these three registers.
user image
The three register to write are : “setup”, “dynamic playload”, and “current status”. I was confused why there is a “setup” register and not using the “config” register.
StevenCellist
StevenCellist
15:59
Alright I understand this
tlfong01

tlfong01
2618
16:57
Good. Now I quickly read the datasheet again, and picked a couple more registers to do the preliminary testing. I am thinking of using these basic registers to do config, command, and status control. I now appreciate the use of the state diagram, without that you might get lost during transitions from Tx mode ot Rx mode etc. The config register help to set up maximum power, the status register can check output. I am hoping to use the scope to check the output waveform.
user image
user image
user image

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.