I am using BLavery’s lib_nrf24 library with an nRF24L01 module on my pi running Octopi (it’s pretty much rasbpian for the purposes here, AFAIK – here is the result of the os-release command).
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
I am able to setup the radio according to this tutorial, but the code that waits for the radio to receive data;
while not radio.available(0): time.sleep(1/100)
throws an OSError (errno 9) Bad file descriptor. Here is the full error traceback:
Traceback (most recent call last): File "main.py", line 72, in <module> main() File "main.py", line 18, in main while not radio.available(0): File "/home/pi/smarthome/lib_nrf24.py", line 506, in available status = self.get_status() File "/home/pi/smarthome/lib_nrf24.py", line 293, in get_status return self.spidev.xfer2([NRF24.NOP]) OSError: [Errno 9] Bad file descriptor
I found this stackoverflow post about what OSError is and means, but I’m not sure how this would help me figure out what is going on in the lib_nrf24 library, and how to make it work so the radio behaves normally.
The post says that this error can be thrown if a file is opened, and closed elsewhere so the current environment thinks it is still open, and throws this error when it tries to close the file. The implicating code in the library is just a return statement;
def get_status(self): return self.spidev.xfer2([NRF24.NOP])
And I’m not learning anything more from looking at the available method that calls the get_status
def available(self, pipe_num=None): if not pipe_num: pipe_num =  status = self.get_status() result = False ...
I’ve searched for any posts that mention both the lib_nrf24 library and any of ‘OSError’ ‘errno 9’ or ‘Bad file descriptor’ and come up with zero hits for the intersection of these two issues.
I realize on the lib_nrf24 github page it says the library is out of support as of May 2018. Am I out of luck? I couldn’t find a more recent python library for these rf modules. The only other approach I have seen is to figure out how to use the c++ boost libraries to use the tmrh20 library… but I’ve looked at that and couldn’t figure it out.