jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.78k stars 622 forks source link

Using GPIO 18 requires sudo permissions #396

Open szafranski opened 4 years ago

szafranski commented 4 years ago

Without sudo I get on Rapsberry Pi 3b+ an error like this:

Can't open /dev/mem: Operation not permitted.

Any safe solutions?

Thanks!

szafranski commented 4 years ago

Using GPIO 10 (SPI) works without sudo. What can be an issue with GPIO 18?

penfold42 commented 4 years ago

It uses PWM and there’s no way to access the PWM hardware as non-root

szafranski commented 4 years ago

So pwm neede sudo and spi doesn’t right? Is there any way to change those permissions than?

Wiadomość napisana przez penfold42 notifications@github.com w dniu 08.04.2020, o godz. 01:24:

 It uses PWM and there’s no way to access the PWM hardware as non-root

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

penfold42 commented 4 years ago

Correct

And unless/until the kernel exposes a PWM driver to user space, no you need root

szafranski commented 4 years ago

But if I just use shell script with simple:

gpio -g mode 12 pwm gpio -g pwm 12 1024

It runs without sudo. How is that possible?

W dniu śr., 8.04.2020 o 13:43 penfold42 notifications@github.com napisał(a):

Correct

And unless/until the kernel exposes a PWM driver to user space, no you need root

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-610910075, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFUHCACJBQFX6CBHJ2IO5YLRLRPOHANCNFSM4LYSAWAA .

penfold42 commented 4 years ago

That’s only setting the pin to a fixed pwm value.

Driving 1 wire leds hits the hardware directly to rapidly send the pulse codes to meet the tight timing requirements

szafranski commented 4 years ago

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

jgarff commented 4 years ago

That will likely not work for the following reasons:

This is why there aren't already GPIO based bitbanging solutions, and also why it requires root. You need hardware assist to make it work properly. You either need to use Pi built in hardware (PWM + DMA) or another RTOS type uC like a arduino via USB.

On Thu, Apr 9, 2020 at 9:26 AM szafranski notifications@github.com wrote:

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611589976, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55G5ZOFAF2DAQU52JKFLRLXSKRANCNFSM4LYSAWAA .

szafranski commented 4 years ago

I’m am designing a PCB for quite large group of people. I would like to use pin 18 due to phisical placement cause everything else is „nearby” like uart and i2c. Is there ANY walaround like changing permissions or sth?

Thanks for all responses!

W dniu czw., 9.04.2020 o 17:57 Jeremy Garff notifications@github.com napisał(a):

That will likely not work for the following reasons:

  • The frequency may be too low using bitbanging on a GPIO.
  • The Linux scheduler will swap out the task thereby causing too much jitter in the output waveform.

This is why there aren't already GPIO based bitbanging solutions, and also why it requires root. You need hardware assist to make it work properly. You either need to use Pi built in hardware (PWM + DMA) or another RTOS type uC like a arduino via USB.

On Thu, Apr 9, 2020 at 9:26 AM szafranski notifications@github.com wrote:

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611589976 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACB55G5ZOFAF2DAQU52JKFLRLXSKRANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611606392, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFUHCACSZWVDQJVDDCLPISTRLXV57ANCNFSM4LYSAWAA .

jgarff commented 4 years ago

Unfortunately, not without sacrificing security. Changing the user/group on /dev/mem for example is a possibility, but is not recommended.

On Thu, Apr 9, 2020 at 10:01 AM szafranski notifications@github.com wrote:

I’m am designing a PCB for quite large group of people. I would like to use pin 18 due to phisical placement cause everything else is „nearby” like uart and i2c. Is there ANY walaround like changing permissions or sth?

Thanks for all responses!

W dniu czw., 9.04.2020 o 17:57 Jeremy Garff notifications@github.com napisał(a):

That will likely not work for the following reasons:

  • The frequency may be too low using bitbanging on a GPIO.
  • The Linux scheduler will swap out the task thereby causing too much jitter in the output waveform.

This is why there aren't already GPIO based bitbanging solutions, and also why it requires root. You need hardware assist to make it work properly. You either need to use Pi built in hardware (PWM + DMA) or another RTOS type uC like a arduino via USB.

On Thu, Apr 9, 2020 at 9:26 AM szafranski notifications@github.com wrote:

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611589976 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ACB55G5ZOFAF2DAQU52JKFLRLXSKRANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611606392 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AFUHCACSZWVDQJVDDCLPISTRLXV57ANCNFSM4LYSAWAA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611608480, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55G72MN3HETEJPTVQW7LRLXWMFANCNFSM4LYSAWAA .

szafranski commented 4 years ago

I would like to keep dev/mem as it is. Any possible alternative? Like changing to some part of it?

W dniu czw., 9.04.2020 o 18:30 Jeremy Garff notifications@github.com napisał(a):

Unfortunately, not without sacrificing security. Changing the user/group on /dev/mem for example is a possibility, but is not recommended.

On Thu, Apr 9, 2020 at 10:01 AM szafranski notifications@github.com wrote:

I’m am designing a PCB for quite large group of people. I would like to use pin 18 due to phisical placement cause everything else is „nearby” like uart and i2c. Is there ANY walaround like changing permissions or sth?

Thanks for all responses!

W dniu czw., 9.04.2020 o 17:57 Jeremy Garff notifications@github.com napisał(a):

That will likely not work for the following reasons:

  • The frequency may be too low using bitbanging on a GPIO.
  • The Linux scheduler will swap out the task thereby causing too much jitter in the output waveform.

This is why there aren't already GPIO based bitbanging solutions, and also why it requires root. You need hardware assist to make it work properly. You either need to use Pi built in hardware (PWM + DMA) or another RTOS type uC like a arduino via USB.

On Thu, Apr 9, 2020 at 9:26 AM szafranski notifications@github.com wrote:

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611589976 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ACB55G5ZOFAF2DAQU52JKFLRLXSKRANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611606392 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AFUHCACSZWVDQJVDDCLPISTRLXV57ANCNFSM4LYSAWAA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611608480 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACB55G72MN3HETEJPTVQW7LRLXWMFANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611623063, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFUHCABKJJEHXLG46ADK4I3RLXZZDANCNFSM4LYSAWAA .

jgarff commented 4 years ago

Sorry, no.

On Thu, Apr 9, 2020 at 10:42 AM szafranski notifications@github.com wrote:

I would like to keep dev/mem as it is. Any possible alternative? Like changing to some part of it?

W dniu czw., 9.04.2020 o 18:30 Jeremy Garff notifications@github.com napisał(a):

Unfortunately, not without sacrificing security. Changing the user/group on /dev/mem for example is a possibility, but is not recommended.

On Thu, Apr 9, 2020 at 10:01 AM szafranski notifications@github.com wrote:

I’m am designing a PCB for quite large group of people. I would like to use pin 18 due to phisical placement cause everything else is „nearby” like uart and i2c. Is there ANY walaround like changing permissions or sth?

Thanks for all responses!

W dniu czw., 9.04.2020 o 17:57 Jeremy Garff notifications@github.com napisał(a):

That will likely not work for the following reasons:

  • The frequency may be too low using bitbanging on a GPIO.
  • The Linux scheduler will swap out the task thereby causing too much jitter in the output waveform.

This is why there aren't already GPIO based bitbanging solutions, and also why it requires root. You need hardware assist to make it work properly. You either need to use Pi built in hardware (PWM + DMA) or another RTOS type uC like a arduino via USB.

On Thu, Apr 9, 2020 at 9:26 AM szafranski notifications@github.com wrote:

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611589976 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ACB55G5ZOFAF2DAQU52JKFLRLXSKRANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611606392 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AFUHCACSZWVDQJVDDCLPISTRLXV57ANCNFSM4LYSAWAA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611608480 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ACB55G72MN3HETEJPTVQW7LRLXWMFANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611623063 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AFUHCABKJJEHXLG46ADK4I3RLXZZDANCNFSM4LYSAWAA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611629042, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55GZ437737SVHM7RGD2DRLX3HXANCNFSM4LYSAWAA .

szafranski commented 4 years ago

Thank you, that library is awesome anyways. What would be the closest pin that can be used on Raspberry pi 3b+ than?

Cheers

W dniu czw., 9.04.2020 o 18:44 Jeremy Garff notifications@github.com napisał(a):

Sorry, no.

On Thu, Apr 9, 2020 at 10:42 AM szafranski notifications@github.com wrote:

I would like to keep dev/mem as it is. Any possible alternative? Like changing to some part of it?

W dniu czw., 9.04.2020 o 18:30 Jeremy Garff notifications@github.com napisał(a):

Unfortunately, not without sacrificing security. Changing the user/group on /dev/mem for example is a possibility, but is not recommended.

On Thu, Apr 9, 2020 at 10:01 AM szafranski notifications@github.com wrote:

I’m am designing a PCB for quite large group of people. I would like to use pin 18 due to phisical placement cause everything else is „nearby” like uart and i2c. Is there ANY walaround like changing permissions or sth?

Thanks for all responses!

W dniu czw., 9.04.2020 o 17:57 Jeremy Garff < notifications@github.com> napisał(a):

That will likely not work for the following reasons:

  • The frequency may be too low using bitbanging on a GPIO.
  • The Linux scheduler will swap out the task thereby causing too much jitter in the output waveform.

This is why there aren't already GPIO based bitbanging solutions, and also why it requires root. You need hardware assist to make it work properly. You either need to use Pi built in hardware (PWM + DMA) or another RTOS type uC like a arduino via USB.

On Thu, Apr 9, 2020 at 9:26 AM szafranski < notifications@github.com> wrote:

So is there some threshold frequency value above which U have to use sudo? Of course I can make some for loops etc and change pwm in a script without sudo so I am curious how it works.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <

https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611589976

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ACB55G5ZOFAF2DAQU52JKFLRLXSKRANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611606392 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AFUHCACSZWVDQJVDDCLPISTRLXV57ANCNFSM4LYSAWAA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611608480 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ACB55G72MN3HETEJPTVQW7LRLXWMFANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611623063 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AFUHCABKJJEHXLG46ADK4I3RLXZZDANCNFSM4LYSAWAA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611629042 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACB55GZ437737SVHM7RGD2DRLX3HXANCNFSM4LYSAWAA

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/396#issuecomment-611630097, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFUHCAGCNNVL3FFTJ3O4XJLRLX3PZANCNFSM4LYSAWAA .

szafranski commented 4 years ago

Don’t have to be pwm pin. Just closest to uart and i2c.

fmatray commented 4 years ago

Hello, I would like to create a plugin for mopidy to add leds cause we all love colorful things :-) The only pin not used by the pirate audio hat is the 12 but I don't want to run mopidy as root.