running rpi3 applications that use gpio without being root

Raspberry Pi 3 Model BWhen I last wrote about using the Raspberry Pi 3’s GPIO pins, it was with my simple and silly cylon.js application (see “retesting gpio with node.js and onoff with the raspberry pi 3“). Every time I ran that application, or any other application that used the GPIO pins, I had to run as root or use sudo (to run as temporary root):

sudo node cylon.js

That kicked off the application and allowed me to flash those LEDs back and forth.

Turns out that there’s a straightforward way to do all this without root or rootly powers, using the granularity built into Linux. These are the straightforward steps to run GPIO applications as a regular user. Note that I’m using Arch Linux and the account is ‘alarm’. The following changes are made as root (su to root).

  1. As root create a new group called gpio (groupadd -f -r gpio)
  2. As root add the group to the alarm account (usermod -G gpio alarm)
  3. As root create a udev rules file at /dev/gpiomem in /etc/udev/rules.d/99-gpio.rules

The rules to be placed into the 99-gpio.rules file are:

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'"

Once all the group and account changes have been made and the rules have been added, reboot the Raspberry Pi.

The two key features to making this work are (1) the new group, gpio, and (2) the udev rules that allow anyone who is a member of the gpio group to access /dev/gpiomem, where the GPIO pins are individually accessed. With these changes in place I no longer have to run as root or type ‘sudo’ before any application that accesses the pins because the alarm account is now a member of the gpio group.

There may very well be an Arch Linux package that does all this for you automatically, but I haven’t found it yet.

easter 2016

Bo (on top) with his brother Luke

Growing up, Easter was a magical time every bit as important as Christmas and Halloween. That’s because my parents gave me and my siblings baskets full of artificial grass and enough candy to nearly give us all childhood diabetes. Or at least it seemed that way to a little guy with very big eyes. As I got older I was exposed to Christ’s story, his crucifixion and his resurrection (I’d already been heavily exposed to the reason behind Christmas with the heavily sanitized story of Mary, Joseph, and the little Baby Jesus).

Along with all the candy were stuffed bunnies, a few ducklings, and little baby chicks. I suppose the adults thought these were emblematic of pure innocence, which was an odd contrast to the bloody act of nailing a living human being to a Roman cross, and then leaving him to hang on that cross until he died from shock, heat, and blood loss. The Resurrection might have been good for Christ, but I can’t imagine being a witness to something as barbaric as a Roman crucifixion and the initial loss all those who were close to him and who loved him so.

Since I’m a Christian (not a very good one) I do believe in this. However, when I turn to the Bible I stick to the New Testament, what some translations of Mark 16:15 calls the “good news.” Too many fundamentalists insist on dredging up interpretations of the Old Testament to back their various and strange interpretations of “God’s word”, which seems to go at considerable odds with what I keep reading in the New Testament. It’s probably one of the reasons I tend to stay away from many churches these days.

As an older adult with two adult children, Easter now seems to come and go along with all the other holidays, which is to say quickly and with little consequence. Due to my society’s commercialization of all those holidays, away from their real reasons for observing them, I’ve just tuned a lot of it out, only noting when they show up because I happen to look on the calendar. I can’t eat the candy anymore without it causing weight gain and throwing my blood chemistry out of whack. And there’s a certain degree of guilt on my part in realizing that the chocolate used in today’s confections might very well be conflict chocolate, or chocolate harvested by child labor, or grown by less than environmentally green methods. Christmas and Easter have become so commercially corrupted.

That leaves me with the equivalent to plush doll bunnies, duckies, and chickens. I have six real living four-footed creatures, two of which grace the top of this blog entry. They are the Florida Gingersnaps, Bo (on top) and Luke (on the bottom), hugging each other while they nap in my home office chair. They’re going on six months, and yet they are still the cutest, kindest and mellowest two cats I’ve ever known. They are the replacements for Lucy, who died back in June of last year. I have wondered more than once if her spirit hasn’t at least touched theirs before hey were born back in October of last year. Every Easter (and just about every day) I’m reminded through them how precious life is, and how it’s balanced by both loss and gain. Interacting with them all is a lovely, calming effect, especially after a stressful day away from home out in the Real World with other humans.

And just to show that not much has changed in over 2000 years, I’ve gotten to see once again just how cruel and bloody man can be to his brothers and sisters in the name of God with the Belgium bombings.

If I didn’t have Bo and Luke and Annie and Ruby and Ellipse and Lulu, I don’t know how I’d live with myself. After all these years I’ve come to realize that even though a wife and children are important and precious, so too are the little creatures the Good Lord has put on this Earth before we even showed up. It’s these creatures, as well as humanity’s newborns and young children, that come closest to idilic Christian love and kindness. Which, as adults, we’re all too willing to leave bleeding and dying in the dirt, or nailed up somewhere to die exposed and alone.

The more I know of humanity, the more I love my animals.


While writing this a news story came out that a suicide bomber killed over 65 people in Lahor, Pakistan on Easter Sunday, many of them children.