Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RF24 without sudo / root access? #194

Closed
n8henrie opened this issue Jan 15, 2016 · 9 comments
Closed

RF24 without sudo / root access? #194

n8henrie opened this issue Jan 15, 2016 · 9 comments
Assignees

Comments

@n8henrie
Copy link

I am interested in using the RF24 library on my Raspberry Pi without running as root / sudo, especially since I have a number of other processes (webapps, home automation daemons, etc.) that I'd love to be able to trigger sending or receiving through my NRF24L01+.

Even though I hardly know any c++, I've tried editing BCM2835 to use the new /dev/gpiomem interface instead of /dev/mem, and my efforts over a couple weeks have been totally fruitless. (see also: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/bcm2835/ThGy-PVslE8/9coKpQTlCgAJ). I'm guessing that it may be a wasted effort because RF24 requires SPI, which is not supported by /dev/gpiomem. Can anybody tell me if this is the case?

If so, is there another good way to accomplish this? Perhaps by somehow using the wiringPi SPI library?

Or should I just do some setuid magic and give permissions to the daemon user in question? Any other suggestions? Thanks in advance.

@pmochocki
Copy link

Is this what you are looking for: Driving LED stripes as non-root user?

Best Regards
Piotr

@n8henrie
Copy link
Author

Thanks for the response --

I had tried that months ago and didn't have any luck. I just tried again and still wasn't having any luck and was in the process of replying as such, and I just realized that I never logged out and back in again after adding myself to the spi group. Doh!

Seems to be working great now.

If any others come across this thread, my steps on a Raspberry Pi 2 were:

  1. Edit RF24/utility/BBB/spi.cpp and install RF24 for spidev use as per the existing TMRh20 Docs
  2. Edit /boot/config.txt and make sure dtparam=spi=on is present and not commented
  3. Add your user to the spi group (requires logout to take effect): sudo usermod -a -G spi $(whoami)
  4. Reboot

If having issues, you should be able to verify permissions on your spi devices and your group membership:

$ ls -l /dev/spi*
crw-rw---- 1 root spi 153, 0 Jan 18 13:20 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Jan 18 13:20 /dev/spidev0.1

$  grep spi /etc/group
spi: # Look for your username in this line

@yasriady
Copy link

hello mz-fuzzy,

I followed your guidance about RF24 with non root, but still out any luck (http://quick2wire.com/non-root-access-to-spi-on-the-pi/).

When I run the program as non root account, yield "Segmentation fault".
Do you have any idea? Pls help.

/Dedy Yasriady

@noeldum
Copy link

noeldum commented Mar 31, 2017

Also getting segfault if not using sudo.

Thanks for the steps n8henrie. What should be edited exactly in spi.cpp?
I compiled RF24 with

./configure --driver=SPIDEV
sudo make install -B

@noeldum
Copy link

noeldum commented Apr 4, 2017

Going back to this one again. I beleive I have all it needs for allowing my pi user to use the spi. Still getting segfault however.

pi@raspberrypi:~ $ ls -l /dev/spidev0.*
crw-rw---- 1 root spi 153, 0 Apr  4 14:17 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Apr  4 14:17 /dev/spidev0.1
pi@raspberrypi:~ $ grep spi /etc/group
spi:x:999:pi

I strongly suspect the issue is maybe somewhere else than just spi device permissions. I tried even making pi the owner of the /dev/spidev0.*.

Any ideas?

@n8henrie
Copy link
Author

n8henrie commented Apr 5, 2017

Have you logged in and logged out since adding yourself to the spi group? That was my issue.

@noeldum
Copy link

noeldum commented Apr 6, 2017

Thanks Henrie. Yes I did restart the rpi many times. No luck. I don't get it!

without sudo the program runs up to when it meets that line in spi.cpp

22 setDataMode(settings.dmode);

Not sure where to look now. My os is Raspbian Jessie.

@n8henrie
Copy link
Author

Can you provide more context and information?

  • The script you're trying to run
  • The exact command you're running

@svenbw
Copy link

svenbw commented Apr 16, 2017

On my platform the segmentation fault is thrown by vsprintf. Stepping into the code shows that the error occurs when writing to /sys/class/gpio if there are no user rights to that folder.
You can create a gpio group, add yourself to that group and modify the rights of that folder. That should solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants