0

I'm trying to use the Neopixel Adafruit library with the WS2812 strip. Everything works great however there is something that I have not been able to do.

I'm working on a project that requires several libraries to be implemented on one script, and to run the Neopixel library I have to use the sudo command in the terminal. I'm trying to avoid this because of streamlining but mainly because if I do use sudo, then my python versions won't be compatible with other libraries. At the end of the day, my goal is to be able to run a python script in Thonny by NOT having to type sudo in to the terminal every time. I'd like to be able to give Thonny root access, give a user complete root access, or something along those lines.

Thanks in advance.

Note I've tried to gksudo Thonny but it gives me a weird message and doesn't seem to give Thonny the root access I need it to have.

  • This question is too vague, but fundamentally insoluble. Python is an interpreted language, and Linux prohibits scripts from inheriting sudo permissions. It can be done in c or similar. – Milliways Mar 26 at 0:06
  • So these LEDs require PWM which is apparently only accessible using root access. However, from what you tell me, i cannot give this script root access. Is there anyway to run a script that requires root access without manually typing the "sudo python xxx.py" terminal command? – Andy Mar 26 at 0:53
  • Incidentally WS2812 DO NOT use PWM, see raspberrypi.stackexchange.com/a/26040/8697 – Milliways Mar 26 at 1:37
  • Interesting. So i've tried giving GPIO access using the chown root.gpio /dev/mem method and i'm still getting nothing. – Andy Mar 26 at 3:05
  • Although the signals are not PWM the Pi PWM hardware is used to generate them. The Pi PWM hardware can be programmed to provide a variety of different signals. You need sudo permissions to access the PWM registers. – joan Mar 26 at 8:06
0

give a user complete root access

Either login as root, or assign your user UID and GID of 0 in /etc/passwd.

give Thonny root access

Either Thonny is a binary (or has a binary wrapper) on which you can set the setuid bit with chmod u+s binary, or you can build such a wrapper yourself (example). The reasons why setuid won't work on scripts in most cases are described here. Note that there are programs which will refuse to run as root (tor and google-chrome to name a few), depending on the "weird message" you've seen that may be the case with Thonny as well.

In both cases, you create security holes, which is probably not relevant for a standalone LED strip controller, but it may become a problem if your RPi doubles as an HTTP/SSH server or is accessible to untrusted parties in other ways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.