Why spidev.SpiDev() is creating an error on RPi 4b?
16:10 19 Mar 2026

everyone !

I have two RPi 4b boards and two NRF24L01 PA modules.
The goal is to connect two Raspberry Pi 4b boards via NRF to send and receive signals.
I am trying to follow this atricle.

I only changed from lib_nrf24 import NRF24 to this from nrf24 import NRF24 as, I believe, "lib_nrf24" is not supported anymore, so I am replacing it with the "nrf24" library.

Also, I checked to see if SPI is enabled via typing ls /dev/spi* in the command line and I am getting /dev/spidev0.0 /dev/spidev0.1 which, if I am not mistaken, means that SPI is enabled.

Yet, I am getting the following error:

Traceback (most recent call last):
  File "/home/Desktop/Code/Radio_Remote_Control_Sender_v1.py", line 16, in 
    radio = NRF24(GPIO, spidev.SpiDev())
  File "/home/Desktop/Code/lib/python3.13/site-packages/nrf24/nrf24.py", line 238, in __init__
    assert 0 <= ce <= 31
TypeError: '<=' not supported between instances of 'int' and 'SpiDev'

As far as I undestand, the spidev.SpiDev() doesn't return an integer and that is the reason of my error ?

Any ideas how I could solve it ?

Here is the code itself:

import RPi.GPIO as GPIO
import time
import spidev
from nrf24 import NRF24

GPIO.setmode(GPIO.BCM)

pipes = [[0xE0, 0xE0, 0xF1, 0xF1, 0xE0], [0xF1, 0xF1, 0xF0, 0xF0, 0xE0]]

# Use the gpio pins
radio = NRF24(GPIO, spidev.SpiDev())

#Start the radio with the CE pin (GPIO08) and the CSN pin (GPIO25).
radio.begin(0, 25)

#Change the power levels to minimal, the channel address to 76, the data rate to 1 Mbps, and the payload size to 32 bits.
radio.setPALevel(NRF24.PA_MIN)
radio.setChannel(0x76)
radio.setDataRate(NRF24.BR_1MBPS)
radio.setPayloadSize(32)

#Set acknowledgement as true
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()

#Start the data writing process by opening the pipes and displaying some nRF24l01 basics.
radio.openWritingPipe(pipes[0])
radio.printDetails()

#Get message ready to send as a string.
sendMessage = list("Hi, there!")  
while len(sendMessage) < 32:
    sendMessage.append(0)

while True:
    start = time.time()      
    radio.write(sendMessage)   
    print("Sent the message: {}".format(sendMessage))  
    radio.startListening()

    while not radio.available(0):
        time.sleep(1/100)
        if time.time()-start>2:
            print("Timed out.")
            break
    
    radio.stopListening()
    time.sleep(3)

Thanks in advance for any tips and recommendations.

python python-3.x raspberry-pi raspberry-pi4 nrf-connect