Wrestling side effects on skis, in space.

Nrf24 on raspberry pi

NRF24, Raspberry PI & event handling, part 2

As mentioned in a previous post, I added support for callbacks on events triggered by the card, and rewrote the C++ port of the RF24 library into plain C in the process. The library is now on github.

After some discussion with @mvidner, I went the easy way and did not use threads, as only one pin needs to be polled.

The process of getting these 'user space IRQs' working boils down to:

  1. connecting the nRF's pin 8 to a free gpioX pin on the raspberry pi. I used GPIO7 (pin 4 on the BCM). The GPIO pin numbering can be pretty confusing, by the way.

  2. Echoing "falling" into /sys/class/gpio/gpioX/edge

  3. Call poll() on /sys/class/gpio/gpioX/value

The code does this via helpers in gpio.c.

Whenever an IRQ is triggered, the card writes into it's STATUS register info about the event and its origin. The library reads it and updates a radio 'status' struct accordingly. User callback can check this struct and can act based on that, so there's no need to fiddle with the low level stuff. Afterwards, the status is reset.

I still have to get batteries and boxes for all the nodes, but otherwise, it looks like this project is almost finished. The sketch for reporting the node data is here. Together with the libnrf24 library and the picasso framework, they should form a complete solution.

So now onto the Arduino roguelike thing, yay!


View or post comments