[fpc-pascal] Access GPIO pins on RPi2 without root?
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Thu Oct 8 21:48:54 CEST 2015
Bo Berglund wrote:
> On Thu, 08 Oct 2015 13:15:10 +0000, Mark Morgan Lloyd
> <markMLl.fpc-pascal at telemetry.co.uk> wrote:
>
>>> You access the GPIOs via the kernel's sysfs interface. The files are
>>> all under /sys/class/gpio. I'd be pretty amazed if your distro doesn't
>>> already have a udev rule to set a certain group for those files. You
>>> probably just have to add your user to that group.
>> Yes, it's the gpio group. I worked through the first couple of steps as
>> described on the Lazarus wiki page manually (i.e. using echo from the
>> command line), so can confirm that it's broadly accurate as of Raspbian
>> "Wheezy".
> Did you mean this page:
> http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#5._PiGpio_Low-level_native_pascal_unit_.28GPIO_control_instead_of_wiringPi_c_library.29
>
> It contains a unit PiGpio for the Broadcom chip on the original Pi.
> Is this some the fpc wrapper that handles what has been described in
> this thread so an fpc program can actually read and write the GPIO
> pins?
>
> It seems easy enough to use were it not for the discussion here
> talking about modifying user permissions on Linux to make the program
> run...
>
> This is what I see in the gpio dir:
> root at rpi2b-wheezy:/sys/class/gpio# ls -la
> total 0
> drwxrwx--- 2 root gpio 0 Jan 1 1970 .
> drwxr-xr-x 44 root root 0 Oct 8 20:38 ..
> -rwxrwx--- 1 root gpio 4096 Jan 1 1970 export
> lrwxrwxrwx 1 root gpio 0 Jan 1 1970 gpiochip0 ->
> ./../devices/soc/3f200000.gpio/gpio/gpiochip0
> -rwxrwx--- 1 root gpio 4096 Jan 1 1970 unexport
Do not, under any circumstances, try to fiddle with the permission of
those files/directories. Instead, add the gpio group to your normal user
(as I have already said).
Jonas has already asked us to discuss this elsewhere, i.e. either the
fpc-other or lazarus-other mailing list, and I really do not want to
upset the list managers by going into basic unix management or into
things which are specific to managing the RPi.
Having said that, by analogy if you want to drive one of the serial
ports on a Linux system you usually end up adding the dialout group to
your normal user ID. If you aren't prepared to discuss this in one of
the more general MLs, then I suggest researching that and then extending
what you learn to adding the gpio group to your normal user.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list