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

Root privs and /dev/gpiomem #18

Open
sgparry opened this issue Feb 17, 2023 · 8 comments
Open

Root privs and /dev/gpiomem #18

sgparry opened this issue Feb 17, 2023 · 8 comments

Comments

@sgparry
Copy link

sgparry commented Feb 17, 2023

Hi,
Can pigpioj be used without root access on systems where gpiomem is correctly configured and the user has permissions?
Thanks
Stephen P.

@mattjlewis
Copy link
Owner

mattjlewis commented Feb 17, 2023

Yes - run the pigpiod daemon process on the Pi and connect to it via sockets. See this page: https://github.com/mattjlewis/pigpioj#sockets. Also discussed here with diozero: https://www.diozero.com/concepts/remotecontrol.html#pigpio

@sgparry
Copy link
Author

sgparry commented Feb 17, 2023

But can it be used without the daemon, via JNI? A lot of the python code out there nowadays is written to access via /dev/gpiomem (so called tinygpio, as seen in in the Rpi.GPIO library), which can be configured to work without needing root privileges...

@mattjlewis
Copy link
Owner

It can be used without the daemon, but because of the way pigpio is written it must have root access when using this JNI access method.
BTW diozero works perfectly well without root access as it accesses gpiomem / gpio chardev, etc.

@sgparry
Copy link
Author

sgparry commented Feb 17, 2023

Thanks for that reply... Cool, I was already using pigpio provider via diozero, so I assume you mean just use the core? To give some background, what I am trying to achieve to start with is to convert some Python code that drives some motors, via PWM on BCM pins 8 through 11. How do I convert the pin numbers in code? Can you point me to an example? Thanks

@mattjlewis
Copy link
Owner

mattjlewis commented Feb 18, 2023

You can use the diozero SystemInformation app to get information on GPIO names and physical PIN numbers. There’s also https://pinout.xyz

Regarding PWM output I would recommend configuring two of the Pi’s hardware PWM channels via a device tree overlay. If you need more than 2 then diozero can do software controlled PWM output. This obviously won’t be as stable as the hardware signal. This is where pigpio can be useful - it uses low level hardware features to do accurate PWM output on any pin, but needs root access to do so.

Can follow up with links and more examples later.

@sgparry
Copy link
Author

sgparry commented Feb 19, 2023 via email

@mattjlewis
Copy link
Owner

That is frustrating. If you have access to a scope you will be able to see how accurate the PWM signal is. Out of interest what board are you using? I have a scope and just about every Pi version so can do some tests for you.

From a very quick Google - this seems to be the source for RPi.GPIO: https://github.com/sarnold/RPi.GPIO

"Although hardware PWM is not available yet, software PWM is available to use on all channels."

It would appear that that library uses software PWM - I strongly suspect that diozero / Java would produce a more stable software PWM signal than in Python.

@sgparry
Copy link
Author

sgparry commented Feb 19, 2023 via email

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