• choose theme
  • Greenwich Mean Time GMT

    using /dev/gpiomem on archlinux arm

    imagine you have a raspberry pi running arch linux arm, and you want to use the python library RPi.GPIO.

    that requires a /dev/gpiomem device, which is a hacky /dev/mem derivative that allows you to access the gpio pins without being root. which is important if you want to also be able to access a normal user’s dbus session, or anything else where you’d like to not be root while running the python.

    arch linux arm uses raspberrypi’s kernel fork, but doesn’t set up the gpiomem device the way it’s needed for RPi.GPIO to work.

    Add a gpio user

    as root, create a gpio user

    groupadd gpio
    usermod -aG gpio alarm # alarm is the name of the default archlinuxarm user

    setup udev

    Make a file called /etc/udev/rules.d/pins.rules and put this in it:

    SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
    SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
    SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
    

    you may also wish to append this line, if you’re going to need spi access too:

    SUBSYSTEM=="spidev", GROUP="spi", MODE="0660"

    reboot

    reboot, run the python, no root,