0

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])[0]
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])[0]

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.

14
  • 1
    Please don't present only links to understand your problem. Most of us will not follow it because to much effort.. Explain what's the problem by yourself so we can understand it only from the question. Please take the short Tour and visit the Help Center to get an idea how things work here.
    – Ingo
    Apr 21, 2020 at 9:14
  • 1
    @Ingo I've really tried to do that, I explicitly stated the errors I am getting, and I summarized the post I linked to, saying what is relevant from it. I put the code from the library I linked in this post as well. I really think everything is in this post - can you be more specific about what I could've done differently?
    – sideways8
    Apr 22, 2020 at 0:45
  • 1
    @tlfong01 Yes, I know the error is from the python code in the library. I am only using python in this project. I tried printing the information that the get_status method needs to return, but then the print statement throws the same error; Bad file descriptor. Where can I find more information about spidev.xfer2 ? The spidev library I have is github.com/Gadgetoid/py-spidev, and I don't know what I should look for in this library to solve this issue.
    – sideways8
    Apr 22, 2020 at 2:17
  • 1
    I tried the SPI loopback test from Appendix E of the post you linked. I get all zeroes. I'm not sure what I should be getting. Should MOSI be connected to MISO? I am using the recv.py program.
    – sideways8
    Apr 22, 2020 at 16:23
  • 1
    I've looked into the PyPi spidev manual (though I am using Gadgetoid's py-spidev, as per the tutorial). I can't find out what spidev.xfer2 is supposed to return. The NRF24.NOP value is just 0xFF. If I try to print (self.spidev.xfer2([NRF24.NOP])) (ie without the accessor to get the 0 element) the output prints nothing, and the error is still thrown by this print statement, not the return statement that follows.
    – sideways8
    Apr 22, 2020 at 16:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.