Uncategorized

nRF24 Discussion Notes

nRF24 Discussion Notes

 

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
Thu 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
Thu 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
Thu 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
Thu 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
Thu 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
Thu 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
Thu 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
Fri 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
Fri 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
Fri 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
Fri 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
Fri 15:59
Alright I understand this
tlfong01

tlfong01
2618
Fri 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
17 hours later…
tlfong01

tlfong01
2618
Sat 10:21
I am casually googling around to see what other experts talking about nRF24. I noticed one expert saying that “… it is not easy to tune the signal strength …”. I was wondering that should I set the transmitting power to maximum to ensure max reception? Reference: (1) [Cheap COTS (Commercial Off The Self) transceivers that work with Raspberry Pi? – Asked 2015 Viewed 924 times]:
raspberrypi.stackexchange.com/….
I also noticed that the nRF24 module is a 5+ year old product, and so should be mature and reliable, worth spending time on it (though the library is not perfect, and no longer supported by the original developer, but then it is more challenging than using a BettyFruit library and everything goes smoothly, spoiling you too lazy to learn.
7 hours later…
tlfong01

tlfong01
2618
Sat 17:26
I am testing two nrf24 modules at the same time, using the following /boot/config.txt, with 2 SPI buses and 5 Chip Selects. The following record is for your reference, in case you wish to use later. Cheers.
user image
3 hours later…
tlfong01

tlfong01
2618
Sat 20:00
Now I am testing the SPI two and three bytes loopback functions, which are used later to read and write nRF24 registers. You can search this forum using keywords “SPI”, “loopback” for newbie friendly Rpi3+ stretch test programs for both SPI1 and SPI2. I am using Rpi4B buster version now. I am using low SPI frequency of 100kHz, so I can use long wiring. Later I might increase to 1MHz. The is the waveform capture: imgur.com/gallery/aFVfLg2.
tlfong01

tlfong01
2618
Sat 20:19
user image
4 hours later…
StevenCellist

StevenCellist
yst 0:14
Of what I know, the signal strength shouldn’t be set to max when the radios are close to each other. The signal can be too strong, and minimum power should be able to work perfectly fine
9 hours later…
tlfong01

tlfong01
2618
yst 9:10
Ah, I never thought about that. I wrongly thought that the nRF24 if working as a receiver, is like my FM radio receiver, the strong the signal the better, because I can always use the volume knob to adjust any too strong signals received. Anyway, I need to pause a bit and google harder, to make sure I am not thinking other amateurish thoughts. On second thought, perhaps I can add a manual signal and volume adjust option to my python program. Cheers.
1 hour later…
tlfong01

tlfong01
2618
yst 10:20
@StevenCellist About your comment: “… I did get a warning on my B+ model actually about one of the pins already being in use, but it continued anyway …”, I vaguely remember that one of the reasons that you might get this kind of warning messages is that you are trying to set a GPIO pin to input or output mode, but that GPIO pin has already been setup earlier. So it is just a warning, nothing important. There seems to be a flag to disable this kind of warning, but again not that important.
By the way, I found that I need to use a GPIO pin to control the CE, module enable/disable pin for certain kind of Tx operation. And we may need another GPIO pin set to input mode to entertain the Interrupt status output of the nRF24 module. So now I need two pins x 4 for 4 modules of my project. I think I need to write a simple python GPIO only module to handle these 8 CE/Interrupt pins.
7 hours later…
tlfong01

tlfong01
2618
yst 17:19
Now I am going to assign GPIO pins for my 4 nRF24 modules. I looked at the pinout map and found there are not too many pins to go around, because the 6 SPI buses occupy quite a number of pins. So my first thought is to just use SPI1, SPI1, and forget SPI3 to SPI6. So I assign 1 GPIO pin for each module’s CE, and one more pin in pull down configuration, to share among all 4 modules.
The pin map is rather messy, even I am only looking at the SPI pins. I still need to entertain the 5 I2C buses and at least one UART/serial TxD, RxD. Indeed I cannot make end make and must make a big engineering trade off in using the pins.
user image
4 hours later…
tlfong01

tlfong01
2618
yst 21:28
I always wrongly thought that SPI0 has CE0, CE1, but SPI1 has only CE2, but no CE1. Now I found made a mistake, there is actually CE0 for SPI1, but no CE0. I don’t know why. Anyway, now I extracting the following pins/wires: SPI0 CE0, CE1 and SPI1 CE1, CE2. Together with Ground wire, each of SPI0, SPI1 has 6 wires, as show below.
user image
Please let me know if you guess why there is no CE0 for SPI1. This seems inconsistent.
tlfong01

tlfong01
2618
yst 22:12
user image
15 hours later…
tlfong01

tlfong01
2618
12:44
buster has just release another update with a faster Thonny. So I am taking a break here to do the updating. See you later. By the way, three questions: (1) Do you know what is TDD? (2) have you any experience in using python list and dictionary data structure in programming? and (3) Do you prefer OO than FP (Functional Programming)?
user image
tlfong01

tlfong01
2618
12:57
I hope you can also update your buster in time, so we can later compare our programs using the same versions of SpiDev, python, and Thonny. (1) Raspbian Buster Gets New Features in Big Update By Ash Puckett 7 hours ago New changes and lots of features!
tomshardware.com/news/…

(2) New Linux 5.5 – Supports Raspberry Pi 4! By yida 9 hours ago
seeedstudio.com/blog/2020/02/…

5 hours later…
StevenCellist

StevenCellist
11
17:28
@tlfong01 Isn’t pin 12 the CE0 for SPI1?
I didn’t know what TDD was but I looked it up and I see what it means
I do have experience with python lists, my exam two weeks ago made quite a bit of use of those
And I really prefer OOP over FP, so I can make changes much easier to my specific codes
I’ll be updating my Pis to the new version soon
On a side note: there’s really no need for me to entertain 6 radio’s.. lol. For my current plans I only need one per Pi. I won’t mind a code that’s ready to add a second but six would totally overkill for me 🙂
tlfong01

tlfong01
2618
@ StevenCellist: “Isn’t pin 12 the CE0 for SPI1?”, Oh my goodness, Thank you very much for pointing out my “Blind Spot”. I actually went through the Tom’s Hardware pin table three times, before giving up, with a conclusion that (1) Tom’s Hardware pinout table is buggy, (2) buster’s ls /dev/spi* is buggy, (3) me only cannot make any mistakes. So last night slept well. But to night I won’t sleep well, … 😦
StevenCellist

StevenCellist
11
Ahaha don’t worry bro! You have been doing some awesome work already and you don’t wanna know what kind of mistakes I have been making already.. like the time.sleep(100)
You should rest well
tlfong01

tlfong01
2618
17:49
I agree there is no need to have 6 RF transceivers. I only need one on either side. It is only for “swap/pairing/cross checking/testing” that I need two each side. But then later when I move the slave to my rooftop garden, I may need two on the rooftop, one standby in case of another break down.
I usually test four devices to make sure that even two devices are OK, I must be very sure that my list of two devices can 100% sure scale up to 4, 8, … 64 radios. Ah, I forgot to comment on your comments that why I bought 6.
StevenCellist
StevenCellist
Ahh okay, I see!
tlfong01

tlfong01
2618
I almost could not sleep well to night, because just now I made another careless but very severe mistake when trying flashing the new buster image. Let me show you my installation record, and then, … Ah dinner time, see you later.
user image
StevenCellist

StevenCellist
11
I can’t read Chinese but that ‘s an error I see! Oops!
It should be possible to do it via ‘sudo apt-get update’ and upgrade, right? Else I’ll have to wait another day
Have a nice meal!
tlfong01
tlfong01
18:06
Ah, you seem to be an impatient guy. OK, here is a tip: I tried to boot but I got the infamous twinkle, twinkle, twinkle, twinkle little green star! 🙂
StevenCellist
StevenCellist
Ohhh that isn’t gonna boot
Well I’m going to take a shower so I’ll be back too
3 hours later…
tlfong01

tlfong01
2618
21:10
Another tip: FAQ V0.1 of Using Win32Image Manager v1.0 to flash buster release 2020feb05 image on a 16GB SD Card – tlfong01 2020feb10hkt2107

Q1. If Win32Image Manager V1.0 gives error message when trying to flash a buster image, what should I do?
A1. Use SD Formatter V4.0 to “Overwrite mode” format the SD card (yes, “Quick format mode” won’t do), then the SD card will now be flashable.

Q2. If after SD Formatter V4.0 has “overwrite formatted” the previously Win32ImageManager unflashable SD card, it is now indeed flashable, but
what Windows 10 File Manager originally showed only one drive G:, now confusingly shows two drives G: and H:. What drive should I flash now then, G: or H:?

How come so confusing: one drive after SD Formatter V4.0 has “overwrite” formatted, becomes two drives? what is going on?

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