NRF24L01 with a Pi Pico

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
dnts
Posts: 2
Joined: Sun Apr 04, 2021 7:25 am

Re: NRF24L01 with a Pi Pico

Post by dnts » Sun Apr 04, 2021 10:10 am

on master

Code: Select all

        try:
            nrf.send(struct.pack("i", millis))
        except OSError:
           	I GET AN ERROR HERE
            pass
the slave is already in listening mode

huyle
Posts: 1
Joined: Fri Sep 03, 2021 8:52 am

Re: NRF24L01 with a Pi Pico

Post by huyle » Fri Sep 03, 2021 8:57 am

dnts wrote:
Sun Apr 04, 2021 10:10 am
on master

Code: Select all

        try:
            nrf.send(struct.pack("i", millis))
        except OSError:
           	I GET AN ERROR HERE
            pass
the slave is already in listening mode
Hi! i have the same problem with u when i use Pi pico, did u find out solution?! can u tell me? thank you!!

Chillmaz
Posts: 3
Joined: Mon Sep 13, 2021 9:43 am

Re: NRF24L01 with a Pi Pico

Post by Chillmaz » Mon Sep 13, 2021 9:47 am

how would a communication between a raspi 3 and pico look like?
i mean whats the configuration i need to edit aside pin adaptation

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: NRF24L01 with a Pi Pico

Post by pythoncoder » Mon Sep 13, 2021 5:20 pm

I think the code posted by @dnts has been "simplified" too far. Both the master and the slave need RX and TX pipes to be initialised as in the official test program. This is because NRF24L01's are 2-way devices. Transmissions are automatically checked so both master and slave must be able to transmit and receive.

I suggest you guys use the official test script.
Peter Hinch
Index to my micropython libraries.

cnmcdee
Posts: 12
Joined: Sat Sep 11, 2021 10:41 pm

Re: NRF24L01 with a Pi Pico

Post by cnmcdee » Tue Sep 21, 2021 11:02 pm

Welcome to the not-working NRF24L01 club.

The first thing I did was try to get it to read the internal registers inside it before trying to transmit anything. I always start there.

You can see in this thread people have trouble trying to read the registers via a MicroChip Pic code:
https://www.microchip.com/forums/m525133.aspx

The biggest thing to do is add lots of power supply caps to stabilize the bus because these nrf24L01's current dip on transmit - and it's enough to trip a reset on the talking chip.

Expect lots of failures, I buy them in 6 packs from various manufactures.

Also a lot of kit projects check them and check them again - they will say 3.3 volt then put out 5 V or not work at all, or you will get bung dead nrf24L01's.

[IF] you ever get them to work some were wrapping them in first saran-wrap then tin-foil to make them more rf isolated and getting a lot better performance.

cnmcdee
Posts: 12
Joined: Sat Sep 11, 2021 10:41 pm

Re: NRF24L01 with a Pi Pico

Post by cnmcdee » Tue Sep 21, 2021 11:10 pm

If anyone is ~super~ ambitious one could write their own bit-bang to these SPI specs starting on Page 19:

https://www.sparkfun.com/datasheets/Com ... ec_1_2.pdf

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: NRF24L01 with a Pi Pico

Post by pythoncoder » Wed Sep 22, 2021 8:25 am

I have done quite a lot with MicroPython and NRF24L01+, and have a project with four of these which has been running for several years. I also wrote this repo to simplify using them.

The key is to buy decent units. I use this one and this one. They actually work, unlike many cheaper ones. They don't need weird hacks with capacitors and a tinfoil hat is strictly optional...
Peter Hinch
Index to my micropython libraries.

Mystic
Posts: 14
Joined: Sun Dec 12, 2021 10:05 pm

Re: NRF24L01 with a Pi Pico

Post by Mystic » Sun Dec 12, 2021 10:38 pm

Hi guys,
I have just joined this great forum
I am trying to get two Picos working toguether using nrf24l01
I am getting some odd behaviour
Yes, these are some nrf24l01 from ebay that came in a packet of 10, however, I do not think the problem lies there because I have set them up on two Arduino nanos and they seem to communicate quite happily, and though many walls up to over 20 meters away
I have tried to switch a number of those nrf24l01 modules from those 10 onto the Picos a few times and the behaviour is always the same, so again it does not feel that these modules are at fault, otherwise I would suspect that the behaviour would change with different bad module?
I do take onboard the comments in this forum about buying good quality ones, and if that is what I need to do to resolve issues, I will do that.
Whatever I transmit, only a fraction of what I send get through.
Often I notice that a character is received, but the sender says the transmission has failed implying that it did not get the acknowledgement back ( I tried to change the timeout from 500 to 5000 in nrf24l01.py, but that made no difference)
I am using the nrf24l01.py library and the sample code from Kevin McAleer
I have tweaked the code a bit so that it does not stop when it gets a send error so as to allow it to continue running
https://github.com/kevinmcaleer/nRF24L0 ... in/main.py
I believe the nrf24l01 library is a copy of the Peter Hinch and it does seem so looking at both
I start the receiver and then start the transmitter
I have added 10 Microfarad capacitors on both receiver and transmitter as without those, no messages get through at all to the receiver (perhaps an indication that these module are poor as Peter suggested in his post)
I am powering the nrf24l01 module on both pico by their own separate 3.3 volt power supply with common ground as I have noted in various forums that the Picos might not have enough power on the 3.3 v pin for these modules. Also I will want to add a wifi module as some of my Picos will be used as a WiFi MQTT bridge between my local wifi net and rf net
I have tried lowering the transmit power from 3 to 1 as I have read that when close together these modules might not work well together at high power
I have tried to introduce wait statements in various places to hopefully give time for the modules to settle between transmission,
Nothing I have done so far has helped cured the issue
Hopefully someone here will identify what the issue could be
Many thanks for any help on this

To give you some idea of the pattern, I issued teh following commands in the python script

send(nrf, "a1")
sleep(3)
send(nrf, "b2")
sleep(3)
send(nrf, "c3")
sleep(3)
send(nrf, "d4")
sleep(3)

I get the following on the receive side

Initialising the nRF24L0+ Module
We have received data
a
We have received data
b
We have received data
c
We have received data
d
We have received data
a
We have received data
1
We have received data
b
We have received data
2
We have received data
c
We have received data
d
We have received data
a
We have received data
b
We have received data
c
We have received data
3
We have received data
d

I get the following on the transmit side
Note that the extra _ character is what I append to each message being sent as an eol character

Initialising the nRF24L0+ Module
sending message (incl eol) - a1_
send sending character a
send Sorry message not sent
send sending character 1
send Sorry message not sent
send sending character _
send Sorry message not sent
sending message (incl eol) - b2_
send sending character b
send Sorry message not sent
send sending character 2
send Sorry message not sent
send sending character _
send Sorry message not sent
sending message (incl eol) - c3_
send sending character c
send Sorry message not sent
send sending character 3
send message 3 sent
send sending character _
send message _ sent
sending message (incl eol) - d4_
send sending character d
send Sorry message not sent
send sending character 4
send message 4 sent
send sending character _
send message _ sent
sending message (incl eol) - a1_
send sending character a
send message a sent
send sending character 1
send message 1 sent
send sending character _
send Sorry message not sent
sending message (incl eol) - b2_
send sending character b
send message b sent
send sending character 2
send message 2 sent
send sending character _
send Sorry message not sent
sending message (incl eol) - c3_
send sending character c
send Sorry message not sent
send sending character 3
send Sorry message not sent
send sending character _
send message _ sent
sending message (incl eol) - d4_
send sending character d
send Sorry message not sent
send sending character 4
send message 4 sent
send sending character _
send message _ sent
sending message (incl eol) - a1_
send sending character a
send Sorry message not sent
send sending character 1
send message 1 sent
send sending character _
send message _ sent
sending message (incl eol) - b2_
send sending character b
send Sorry message not sent
send sending character 2
send message 2 sent
send sending character _
send message _ sent
sending message (incl eol) - c3_
send sending character c
send message c sent
send sending character 3
send message 3 sent
send sending character _
send message _ sent
sending message (incl eol) - d4_
send sending character d
send Sorry message not sent
send sending character 4
send Sorry message not sent
send sending character _
send Sorry message not sent

Mystic
Posts: 14
Joined: Sun Dec 12, 2021 10:05 pm

Re: NRF24L01 with a Pi Pico

Post by Mystic » Sun Dec 12, 2021 11:28 pm

Hi Guys,
I also meant to add the following
As suggested by Peter in one of his posts to use his nrf24l01test.py script from his Github page, I did do so
I had to add the following as mentioned by Patmin at coffeebreakpoint
https://coffeebreakpoint.com/micropytho ... y-pi-pico/
Perhaps this should also be added to teh file on github for otyer people looking at using Picos for this

elif usys.platform == "rp2": # PI PICO
cfg = {"spi": 0, "miso": 4, "mosi": 7, "sck": 6, "csn": 14, "ce": 17}

The pattern of issues is similar but not quite the same
It seems that all data is received and response sent, but the sender timed out on twaiting for the response ?

Receiver shows the following with default setting in nrf24l01test.py
I did try and increase _SLAVE_SEND_DELAY = const(100) on receiver (ie from 10 to 100) but that did not help either

If I swap the slave and master function around, then the slave receives nothing at all
I then changed both nrf24l01 modules for different ones and I still get the same symptoms
I am wondering if there is an issue with the wiring as one is on a breadboard and one is on a breakout board
I will try and make them the same tomorrow to compare

NRF24L01 test module loaded
NRF24L01 pinout for test:
CE on 17
CSN on 14
SCK on 6
MISO on 4
MOSI on 7
run nrf24l01test.slave() on slave, then nrf24l01test.master() on master
NRF24L01 slave mode, waiting for packets... (ctrl-C to stop)
received: 3271471 1
sent response
received: 3271983 2
sent response
received: 3272487 4
sent response
received: 3273012 8
sent response
received: 3273537 1
sent response
received: 3274062 2
sent response
received: 3274587 4
sent response
received: 3275112 8
sent response
received: 3275616 1
sent response
received: 3276141 2
sent response
received: 3276666 4
sent response
received: 3277190 8
sent response
received: 3277715 1
sent response
received: 3278240 2
sent response
received: 3278752 4
sent response
received: 3279277 8
sent response


Sender shows

NRF24L01 test module loaded
NRF24L01 pinout for test:
CE on 17
CSN on 14
SCK on 6
MISO on 4
MOSI on 7
run nrf24l01test.slave() on slave, then nrf24l01test.master() on master
NRF24L01 master mode, sending 16 packets...
sending: 3271471 1
failed, response timed out
sending: 3271983 2
failed, response timed out
sending: 3272487 4
failed, response timed out
sending: 3273012 8
failed, response timed out
sending: 3273537 1
failed, response timed out
sending: 3274062 2
failed, response timed out
sending: 3274587 4
failed, response timed out
sending: 3275112 8
failed, response timed out
sending: 3275616 1
failed, response timed out
sending: 3276141 2
failed, response timed out
sending: 3276666 4
failed, response timed out
sending: 3277190 8
failed, response timed out
sending: 3277715 1
failed, response timed out
sending: 3278240 2
failed, response timed out
sending: 3278752 4
failed, response timed out
sending: 3279277 8
failed, response timed out
master finished sending; successes=0, failures=16

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: NRF24L01 with a Pi Pico

Post by pythoncoder » Mon Dec 13, 2021 10:54 am

My starting point in all work with the NRF24L01 is to run the official test script with the official driver. That works "out of the box" with Pyboard, ESP8266 and ESP32 and enables hardware to be verified.

Pico is not yet supported, but it should only involve adding an elif clause here with pin numbers etc.
Peter Hinch
Index to my micropython libraries.

Post Reply