OSError: nRF24L01+ Hardware not responding

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
foonghanyao
Posts: 2
Joined: Sat Apr 02, 2022 8:45 am

OSError: nRF24L01+ Hardware not responding

Post by foonghanyao » Sat Apr 02, 2022 9:11 am

Hi, I am getting the an "OSError: nRF24L01+ Hardware not responding" on my raspberrypi Pico with a nrf24l01+PA+LNA

My main.py code is as below:

Code: Select all

from nrf24l01 import NRF24L01
from machine import SPI, Pin
from time import sleep
import struct

csn = Pin(14, mode=Pin.OUT, value=1) # Chip Select Not
ce = Pin(17, mode=Pin.OUT, value=0)  # Chip Enable
led = Pin(25, Pin.OUT)               # Onboard LED
payload_size = 20


role = "receive"

if role == "send":
    send_pipe = b"\xe1\xf0\xf0\xf0\xf0"
    receive_pipe = b"\xd2\xf0\xf0\xf0\xf0"
else:
    send_pipe = b"\xd2\xf0\xf0\xf0\xf0"
    receive_pipe = b"\xe1\xf0\xf0\xf0\xf0"

def setup():
    print("Initialising the nRF24L0+ Module")
    nrf = NRF24L01(SPI(0), csn, ce, payload_size=payload_size)
    nrf.open_tx_pipe(send_pipe)
    nrf.open_rx_pipe(1, receive_pipe)
    nrf.start_listening()
    return nrf

def flash_led(times:int=None):
    ''' Flashed the built in LED the number of times defined in the times parameter '''
    for _ in range(times):
        led.value(1)
        sleep(0.01)
        led.value(0)
        sleep(0.01)

def send(nrf, msg):
    print("sending message.", msg)
    nrf.stop_listening()
    for n in range(len(msg)):
        try:
            encoded_string = msg[n].encode()
            byte_array = bytearray(encoded_string)
            buf = struct.pack("s", byte_array)
            nrf.send(buf)
            # print(role,"message",msg[n],"sent")
            flash_led(1)
        except OSError:
            print(role,"Sorry message not sent")
    nrf.send("\n")
    nrf.start_listening()

# main code loop
flash_led(1)
nrf = setup()
nrf.start_listening()
msg_string = ""

while True:
    msg = ""
    if role == "send":
        send(nrf, "Yello world")
        send(nrf, "Test")
    else:
        # Check for Messages
        if nrf.any():
            package = nrf.recv()          
            message = struct.unpack("s",package)
            msg = message[0].decode()
            flash_led(1)

            # Check for the new line character
            if (msg == "\n") and (len(msg_string) <= 20):
                print("full message",msg_string, msg)
                msg_string = ""
            else:
                if len(msg_string) <= 20:
                    msg_string = msg_string + msg
                else:
                    msg_string = ""

I am using the driver from this link: https://github.com/micropython/micropyt ... rf24l01.py

My transmitter's main.py code is the same except for the role being set to "send". It too is having the same error.

Traceback:
Initialising the nRF24L0+ Module
Traceback (most recent call last):
File "<stdin>", line 58, in <module>
File "<stdin>", line 26, in setup
File "nrf24l01.py", line 75, in __init__
OSError: nRF24L01+ Hardware not responding

Jumper connections are:
GND to i/o 38
VCC to 3v3(OUT)
ce to GP 17
csn to GP 14
MOSI GP 4
sck GP 6
MISO GP 7


Any ideas as to where i could have gone wrong? New to Raspberrypi Pico here.

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

Re: OSError: nRF24L01+ Hardware not responding

Post by pythoncoder » Sat Apr 02, 2022 10:00 am

Two comments.

Line 75 of the driver is this one so the traceback doesn't look right. Have you got the latest code?

Secondly, my first port of call would be to run the official test with the other end of the link also running that code. Once you get that running you'll know your hardware is correct.
Peter Hinch
Index to my micropython libraries.

foonghanyao
Posts: 2
Joined: Sat Apr 02, 2022 8:45 am

Re: OSError: nRF24L01+ Hardware not responding

Post by foonghanyao » Sat Apr 02, 2022 4:46 pm

My line 75 is line 78 in the driver link you sent me. I deleted the first 3 lines of comments.

I managed to make it work with the help if a post you commented ion, viewtopic.php?f=21&t=9939.
The problem was in my jumper wiring. my MISO, and MOSI connections were mixed up.

Anyway, thank you for your comment. It lead me into running the test script. :D

Post Reply