Similar to the Raspberry Pi, GPIO pins on the PINE64 can be controlled through sysfs. You can refer to my previous post which goes into the concept in detail, and the C# code remains the same for the PINE64. However, with the longsleep Ubuntu image, root access is required to control the GPIO pins. You will need to grant the necessary permissions in order to be able to control GPIO pins as a normal user.
Granting user permissions
We’ll assume that we want to be able to control the pins as the default ubuntu user. Follow these steps to grant the necessary permissions.
- Create a user group called gpio.
groupadd gpio
- Add the ubuntu user to the gpio group.
useradd -G gpio ubuntu
- Add a udev rule to run chown on the sysfs files. The chown command will set group ownership to the gpio group. Adding the udev rule will run the chown command automatically whenever you export a pin. Create a file called
99-com.rules
in/etc/dev/rules.d
and paste the following contents.1SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; chown -R root:gpio /sys/devices/soc.0/1c20800.pinctrl/gpio && chmod -R 770 /sys/devices/soc.0/1c20800.pinctrl/gpio; chown -R root:gpio /sys/devices/soc.0/1f02c00.pinctrl/gpio && chmod -R 770 /sys/devices/soc.0/1f02c00.pinctrl/gpio'"
Physical pin to GPIO number mapping
I took some time to test the physical pins on the PINEĀ in order to determine the sysfs gpio numbers and came up with this table. As an example, physical pin 22 on the Pi 2 pinout corresponds to/sys/class/gpio/gpio79
.Pin # GPIO # Pi 2 pinout 3 227 5 226 8 32 10 33 11 71 12 72 13 233 15 76 16 77 18 78 19 64 21 65 22 79 23 66 24 67 26 231 27 361 28 360 29 229 31 230 32 68 33 69 35 73 36 70 37 80 38 74 40 75 Euler pinout 7 363 10 232 11 35 12 36 13 37 15 38 16 39 18 100 19 98 21 99 22 101 23 97 24 96 26 102 27 34 28 103 29 40 30 41 Exp pinout 2 359 7 40 8 41