2

I compiled the rpi_ws281x Library and the neopixel python wrapper following the instructions on https://learn.adafruit.com/neopixels-on-raspberry-pi/software

Link broken try https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel

The strandtest.py works using PWM on GPIO18 but requires sudo.

I am planning to give my grandson a Pi3 and a short ledstrip and would like to avoid sudo.

I understand that suid won't work with python scripts, but am at a loss for any solution.

I wonder if any Pi user can suggest anything to avoid the need for sudo

  • There's a thread on StackOverflow that discusses an approach, but it may be unacceptable from a security standpoint. I suppose you could embed the password in an environment variable, but that offers little or nothing to address the security issue. But mostly, I'm curious as to why you don't want to introduce your grandson to sudo? – Seamus Jun 18 '18 at 21:43
2

I've had some success running neopixels from pin 10 without sudo, but the results are unreliable - it seems there's some kind of interference or timing issue. It only works most of the time, and sometimes the LEDs change spontaneously. So at this point, I have to assume that it can't be done reliably. Pin 10 doesn't work right and the other pins supported in the neopixel library all require sudo.

For what it's worth, here are the steps I used to get neopixels up and kind of running on pin 10:

  1. physically move LED connection to BCM10/MOSI/physical pin 19
  2. change pin in code accordingly (board.D10)
  3. enable SPI interface through raspi-config. To do this non-interactively you can use sudo raspi-config nonint do_spi 0.
  4. run the program as pi user without sudo

Again, on my pi 3 B+, this yielded unreliable results and I wouldn't recommend it. Please comment / edit if you find a way to make it more reliable!

  • Confirmed, this works - great solution! – Bachi May 25 at 18:31
  • 1
    A few hours later: No, it didn't work on my Pi Zero. The 16 Neopixel ring showed erratic behaviour, couldn't get it to work properly. Changing back to PWM on D18 and sudo and it works flawlessly, so I must assume there's some timing issue with the Pi Zero and D10. – Bachi May 25 at 22:22
  • Shucks. I was never able to get reliable results on pin 10 either, but forgot about updating this answer since I moved on to a different non-neopixel system. I've updated it now since it's clear that it's not just me; thanks for the info. – waterproof May 27 at 3:16
1

suid won't work with python scripts

Make a setuid wrapper. There are lots of examples in Google, basically you make a small C program which runs setuid(0); system("/your/script");, and set the suid bit on that binary.

1

I managed to successfully run neopixel without root using this: https://github.com/joosteto/ws2812-spi.

Before I had to:

  1. move LED connection to physical pin 19
  2. add my user to spi group
  3. enable SPI interface through raspi-config
pip3 install spidev
# we will need single function from it
wget https://raw.githubusercontent.com/joosteto/ws2812-spi/master/ws2812.py
import spidev
import ws2812


spi = spidev.SpiDev()
spi.open(0,0)
# cyan
ws2812.write2812(spi, [[10,0,10]])
# off
ws2812.write2812(spi, [[0,0,0]])
# green
ws2812.write2812(spi, [[10,0,0]])
# very bright green
ws2812.write2812(spi, [[255,0,0]])

UPD: if it behaves strangely, try to modify spi.xfer(tx, int(4/1.05e-6)) part in ws2812.py functions. int(4/1.05e-6) is a Hz value for SPI.
On my Raspberry Pi 3B+ v1.2 int(4 / 1.25e-6) (standard for write2812_numpy4()) did not work and int(4/1.05e-6) (default for write2812_pylist4()) worked just fine.

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.