Receiving radio packets with NRF24L01

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
User avatar
deshipu
Posts: 925
Joined: Thu May 28, 2015 5:54 pm

Receiving radio packets with NRF24L01

Postby deshipu » Thu Mar 09, 2017 12:03 am

I've been trying to get a Micro:bit to communicate with an NRF24L01 module, connected to an ESP8266. As far as I can tell, they both are using the same proprietary Nordic protocol. With some help from a friend, we figured out the paramaters that *should* work:

Code: Select all

payload size = 32 bytes
channel = 7 (2.4Ghz + 7 * 1Mhz)
crc length = 2 bytes (also made sure the polynomial and initial value
match) data rate = 1M
address+group = b'ubit\x00'


And then I sat down and wrote some code that uses them (using the NRF24L01 driver ported to ESP8288 avialable here: https://github.com/deshipu/micropython/ ... rf24l01.py):

Code: Select all

import nrf24l01
from machine import SPI, Pin

radio = nrf24l01.NRF24L01(SPI(1), cs=Pin(15), ce=Pin(16),
                          channel=7, payload_size=32)
radio.set_crc(2)
radio.set_channel(7)
radio.set_power_speed(nrf24l01.POWER_3, nrf24l01.SPEED_1M)
radio.open_rx_pipe(0, b'ubit\x00')
radio.start_listening()
while True:
    if radio.any():
        print(radio.recv())


Unfortunately, that only works in theory. I have been unable to receive any messages sent with a micro:bit with this, though I can receive messages sent with another NRF24L01 module set to the same settings. I pretty much ran out of ideas about what else I could try.

Any suggestions welcome.

User avatar
deshipu
Posts: 925
Joined: Thu May 28, 2015 5:54 pm

Re: Receiving radio packets with NRF24L01

Postby deshipu » Fri Mar 10, 2017 1:07 am

Tonight I made some progress. By using code similar to the above, but with disabled CRC, and by spamming thousands of "abcdefgh" messages on the Micro:bit side, I managed to receive the following data:

Code: Select all

b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xea[j\x19}le|\x94\xeb\xda\xc8\xa5\xbe\xe7\xf1\x7f\x7f\xadt\xba'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xf5&$\x86\xdc~\x9b\x17=V\xa8}H+\xb4{\x92\x8ee\xb8\x0f'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xf6nE4\xcdOG\x17\xb6|Rh\xee\x08\xba\x9d\xd0\x8b,J\xe4'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xf5\xeeB\xbc\x82\xaa[v\xea\xa1y9\x9b\xe9\xd6\xa2]lR\xf6\xdc'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xf6\xaf\xc5\x17y\xe3\xb8w\x1b;63{\x1c\xca\xaf\xf0\x9e\x11[\xa1'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xf8\xdfj\xb7k\xb0\x98\x1aZ\x9d\xd4\x05\x94\x94\xd6\xb7-(\x92\xc1M'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xffwz\x8eZ\xefRZ\xf6\xaa\xf7P\xaf[\x1d\xfc)i\xd9\xa9U'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xffr\x97\x8d\xb67\x8b\xa9\xfbzH\xad!\xd6\x15.\xaa\xa6+Z\t-'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xfc\xb7\xdb\xe8\xdfWZm\xb5K\xb3\xbaY9\xdd\xb3\xd0\xaa\xfeK\xbf'
b'\xcb1\n\xfdL\xf4\x11\x9c\x97j\xff\xed\xbd\x11\xa4\xa3T\xba\xca\xb6\x9a\xd4\xefM}I\x9b\xd4\xad\xb8\xee\xaa'


As you can see, this is complete garbage. However, it is regular in a way -- it always starts with the same characters, and then they become more and more different. Also, from thousands of messages, only those few got through.

From this I *suspect*, that my NRF24L01 modules (Chinese clones, of course) don't use exactly the same data rate as the NRF51822 chip on the Micro:bit, and as a result of the differences in their clocks the data gets corrupted. Occasionally they will align enough to get the address bytes correct, and then I will see a message, but of course the bits will lose alignment quickly afterwards, so the actual data is corrupted. This would also explain why the modules see each other without any problems -- they are both from the same source and probably have the same fault. I will try experimenting with different modules when i get them.

User avatar
mcauser
Posts: 132
Joined: Mon Jun 15, 2015 8:03 am

Re: Receiving radio packets with NRF24L01

Postby mcauser » Mon Mar 13, 2017 2:34 am

http://hackaday.com/2015/02/23/nordic-n ... l-vs-fake/
https://forum.mysensors.org/topic/1153/ ... e-emerging
Pretty sure ALL of my NRF24L01+'s are fakes!
I bought a few nRF905s (433-915MHz) and they all seem to be legit and reliable.

On close inspection of the chip markings on boards from the same provider, if the printed text moves around between modules, they are most likely fakes.

There doesn't seem to be a solid method for checking if a nRF24L01 is fake or not.
Some have claimed reading the registers can reveal fakes:
https://devzone.nordicsemi.com/question ... r-if-fake/

Perhaps first try testing your nRF24s using a pair of Arduinos, using maniacbug's RF24 library.
https://github.com/maniacbug/RF24

I updated nrf24l01.py to use the machine syntax and am able to communicate between two ESP8266s.
Haven't tried a nRF24L01 to nRF51822 yet.
https://github.com/mcauser/micropython/commits/nrf24l01

The nRF51822 doesn't have hardware ShockBurst (nor do some of the fake nRF24L01+'s).
Both the nRF51822 and nRF24L01 can communicate using the "Nordic Gazell 2.4g protocol stack", assuming both chips are legit.

If the nRF24L01 is auto-ACKing, you may run into issues when sending nRF51 to nRF24.
Try setting the nRF24L01 in backwards compatibility mode. The Nordic Developer Zone has a few related articles:
https://devzone.nordicsemi.com/question ... thout-ack/
https://devzone.nordicsemi.com/index.ph ... o-nrf24l01

User avatar
pythoncoder
Posts: 1381
Joined: Fri Jul 18, 2014 8:01 am

Re: Receiving radio packets with NRF24L01

Postby pythoncoder » Mon Mar 13, 2017 7:46 am

@mcauser Thanks for that interesting and informative post, I didn't realise the market was awash with dodgy chips. I bought some cheap modules from a supplier I considered reputable, and found they had very limited range and didn't work on all channels. They ended up in the bin.

Sparkfun units (product code 1405) work perfectly for me. A little expensive, but I place some value on my time.
Peter Hinch

User avatar
deshipu
Posts: 925
Joined: Thu May 28, 2015 5:54 pm

Re: Receiving radio packets with NRF24L01

Postby deshipu » Mon Mar 13, 2017 9:26 am

Thanks. As you can see, I'm using the absolutely dumbest and least magical mode here: no CRC, no ACKs, fixed payload size, etc. As far as I understand, that should give me anything that starts with the correct address.

During the weekend I tested with 2 more pairs of NRF24L01 modules from different sources, and I'm getting similar results -- they can communicate with each other fine (within the same pair), but communicating with the Micro:bit, or even with a module from a different pair, has the effect of only getting one or two messages out of 1000, and garbled.


Return to “The micro:bit”

Who is online

Users browsing this forum: No registered users and 2 guests