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

Using pigpio without root #171

Closed
RankoR opened this issue Jun 20, 2023 · 1 comment
Closed

Using pigpio without root #171

RankoR opened this issue Jun 20, 2023 · 1 comment

Comments

@RankoR
Copy link

RankoR commented Jun 20, 2023

Hi, I'm trying to use your library with pigpio for native PWM support on Pi 4 B:

Linux raspberrypi 6.1.34-v8+ #1657 SMP PREEMPT Fri Jun 16 12:36:29 BST 2023 aarch64 GNU/Linux.

My user is in the gpio group:

uid=1000(rankor) gid=1000(rankor) groups=1000(rankor),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),104(input),106(render),108(netdev),995(docker),997(gpio),998(i2c),999(spi)

/dev/gpiomem has correct permissions:

crw-rw---- 1 root gpio 245, 0 Jun 20 01:17 /dev/gpiomem.

When I'm trying to run my program without root permissions, it fails to initialize PiGPIO:

Caused by: java.lang.RuntimeException: Error initialising pigpio (must be run as root!): -1
        at uk.pigpioj.PigpioJNI.<init>(PigpioJNI.java:53)
        at uk.pigpioj.PigpioJ.autoDetectedImplementation(PigpioJ.java:22)
        at com.diozero.internal.provider.pigpioj.PigpioJDeviceFactory.<init>(PigpioJDeviceFactory.java:84)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:780)

But when I run it with sudo, it works fine.

I prefer not to run programs as root when possible. Is there a way to run it as a usual user?

@mattjlewis
Copy link
Owner

pigpio when loaded as a shared library requires root access unfortunately. You can run using the sockets interface if need be. Note native PWM works with the built in device factory on 2 pins - I assume you need more than 2.

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

No branches or pull requests

2 participants