HeAdLeSs
Posts: 17
Joined: Wed Oct 15, 2014 12:18 pm
Location: Cyprus
Contact: Website

+nRF24L01 with Python3

Fri Mar 02, 2018 8:20 pm

Hello together.

I have a problem with the +nRF24L01. I don't get it working.
It was working before already... but not anymore. I don't know what have changed. I even installed a new system today... but still not working. Actually the last thing must be Python3.

Anyway, maybe someone has the big hint or knows even the problem.

Here is my (test) script:

Code: Select all

import RPi.GPIO as GPIO
from libs.lib_nrf24 import NRF24
import time
import spidev
from time import gmtime, strftime
pipes = [[0xf0, 0xf0, 0xf0, 0xf0, 0xe1], [0xf0, 0xf0, 0xf0, 0xf0, 0xd2]]
gpio_pin = 22
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
print(spidev.SpiDev())
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, gpio_pin)
radio.enableDynamicPayloads()
radio.setRetries(15, 15)
radio.setPayloadSize(32)
radio.setChannel(20)
radio.setDataRate(NRF24.BR_250KBPS)
radio.setPALevel(NRF24.PA_LOW)
radio.setCRCLength(NRF24.CRC_8)
radio.setAutoAck(1)
radio.openWritingPipe(pipes[1])
radio.openReadingPipe(1, pipes[0])
radio.enableAckPayload()
radio.printDetails()
radio.stopListening()
print("Payload size: " + str(radio.getPayloadSize()))
buf = bytes("4|1|255|255|255|255|127|0|0|0", "UTF-8")
# send a packet to receiver
radio.write(buf)
# did it return with a payload?
pipe = [0]
radio.startListening()
timeout_counter = 0
timeout = False
while not radio.available(pipe):
    time.sleep(10000 / 1000000.0)
    if timeout_counter == 100:
        timout = True
        break
    else:
        timeout_counter += 1
if timeout == True:
    print("timeout")
else:
    recv_buffer = []
    radio.read(recv_buffer, radio.getDynamicPayloadSize())
    recv = ""
    for c in recv_buffer:
        recv += chr(c)
    print(recv)
And the output:

Code: Select all

pi@RPI2:~/bob2 $ sudo python3 test8.py
STATUS = 0x03 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=1
RX_ADDR_P0-1 = 0xfefefefefe 0xfefefefefc

RX_ADDR_P2-5 =
0xf8
0xf9
0xf9
0xf9


TX_ADDR =
0xfefefefefe

RX_PW_P0-6 =
0x0c
0x0c
0x00
0x00
0x00
0x00


EN_AA = 0x0f
EN_RXADDR = 0x00
RF_CH = 0x07
RF_SETUP = 0x03
CONFIG = 0x03

DYNPD/FEATURE =
0x03
0x01

Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_LOW
It looks like the script is recognizing the hardware. But it's not taking the settings (see Data Rate or PA Power or the Pipes).

I don't know anymore. Does Anyone has the +nRF24L01 working?

At the moment it is on a RPi2 with Raspbian Stretch Lite.

Please help. I really need it working again.

Return to “Python”