Archives For March 2016

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

March 27, 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.

Update

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.

vote the bern

March 15, 2016

I voted today in the Democratic primary for Bernie Sanders. Why I did I wrote about the day before. Today was the day to “walk the walk.” I’m now curious to see how the candidates fare, both Republican and Democrat. I have no idea how the Republican side may vote, but on the Democratic side, all I can say is this: I hope that if Clinton does win, it’s by a far tighter margin than the polls indicate. The polls have been a mess this election season on both political parties, especially the Republican side. It’s going to be an interesting wait until the polls close…

Update

I’m deeply disappointed in, but not surprised by Clinton’s wins today, especially in Florida. I’m also not surprised by how Rubio got smoked by Trump. Because Rubio won’t run for re-election, there’s the possibility a Democrat might get elected as Senator. You never know.

And I was pleasantly surprised by Kasich’s win in Ohio. Kasich’s win is a solid smack upside Trump’s overcombed head. I’m hoping against hope that Kasich does become the Republican nominee, but that’s even less likely than Sander’s becoming the Democratic nominee.

feel the bern

March 14, 2016

I’m an independent, with a penchant to vote Democratic. I grew up in a Republican household in Atlanta, listening every Sunday to William F. Buckley on “Firing Line,” broadcast on the local PBS station (back when PBS was the only outlet for Buckley’s show, not commercial TV).

When I turned 18 in 1972 I followed my upbringing and voted for Richard Nixon. Two years later he was out and Gerald Ford was in. In 1976 I voted for Ford because I’d grown up in Georgia during the years Jimmy Carter was governor of Georgia and I had no desire to make him president, based on those experiences. I didn’t realize it at the time but I was beginning to vote based on merit, not politics. That’s why, in 1980, I believed the Reagan lie and voted Reagan. I tried to correct that mistake in 1984, and again in 1988. Finally, in 1992, I voted along with a very large majority for Bill Clinton, not because I was a Democrat, but because the elder Bush was such a lousy president.

In 1996 I voted again for Clinton, then Gore in 2000 and Kerry in 2004. Finally, in 2008 and again in 2012 I voted for what I thought was the better candidate for president. Compared to what the Republicans were offering (McCain/Palin in 2008 and Romney/Ryan in 2012) I fell into the same trap over and over again; voting for the lesser of two evils. I’ve not been particularly impressed with Obama, especially over the revelations of mass surveillance by the NSA, the incredibly harsh prosecution of whistleblowers under Obama’s former AG, Eric Holder, who prosecuted more cases than all previous presidents combined. I’m also angry over the push by the FBI in particular to weaken encryption, starting with the Apple iPhone, and continuing with any other use of strong encryption. The FBI and others keep waiving the bloody shirt of terrorism (and “lesser crimes”, such as child pornography), doing everything they can to dilute, if not outright destroy, the forth amendment’s protections. Of course, such constitutional weakenings have been occurring with all of the first five amendments, with the help of a Congress on both sides of the isle.

Which brings us to the 2016 elections and the horrible slate of candidates, especially those on the Republican side. So far the only surprising choice for me has been Bernie Sanders. He’s the only candidate who has spoken to any of the issues we need to address as a nation, many that were started under Reagan and given a significant boost under Bill Clinton, who in hindsight was a centrist Republican who was elected as a Democrat.

  • The political system is corrupt, awash from billions of dollars flowing into super PACs from major corporations and Wall Street and from there into major candidates in both parties. The Supreme Court’s Citizen United decision in 2010 was the final straw.
  • The real suppression of voting across the country at the state level as well as exteme suppression of First Amendment rights to assembly and protest, culminating in the militarize police confrontations with Occupy Wall Street in 2011. Orlando and Tallahassee were remarkably peaceful. The real ugly police brutality occurred in New York around Wall Street and Oakland California. My small video of the Orlando OWS march is above.
  • My fight, as a middle class husband and father, to hold my family and life together. I’ve watched my daughters and their boyfriends struggling to make a living, having a much harder time of it than I ever did when I was their age. My wife and I saved up for Florida pre-paid for both girls, starting when they were born, and it helped significantly when they both went off to state schools as undergraduates. Yet, when they graduated (both of them with honors), they struggled to find any kind of a meaningful job, and both started to take out school loans to go back to school and try to find something else that might help them land a meaningful job. Both girls now have school loans (the one thing we tried to avoid saddling both girls with), although their loans are much smaller than many of their contemporaries. I’ve watched my girls and their contemporaries struggle with incredible school debt and a lousy (deliberately so) work environment hell-bent on turning everyone into part timers with no benefits. Fortunately my children have started to turn a corner in their careers, but with nothing like the opportunities like I had (and foolishly wasted to be honest). I lay the blame for this at the feet of a capitalism gone out of control and corrupt, due to laws passed in particular during Bill Clinton’s two terms.
  • Sky rocketing health care costs, stagnant wages/less than full time employment, deep unemployment, refusal to invest in real infrastructure needs (bridges that fall down, highways full of potholes, big tax giveaways for corporations to build sports stadiums over where low-cost housing neighborhoods used to stand, etc, etc etc), and a whole litany of societal ills that are ignored by both so-called main stream Democrats as well as Republicans have led to this election cycle where a normal Democrat, running for president on classic, historic Democratic principals, is labeled as socialist by opponents on both the Republican side as well as the Democratic side. He’s not. Which just goes to prove in my book that there’s no difference between either party, that both parties have been thoroughly bought out by the same special interests (again major businesses and banks). They pretty much say and do the same things, only the Republicans are more virulent about it.

This year I’m voting Sanders, not just in the Florida primary, but in the general election if Sanders manages to win his party’s nomination. If Clinton wins the nomination I don’t know what I’ll do. With Hillary matched against any Republican you have the worst of all evils to run for president in quite a long time.

[1] The big difference between Clinton and Sanders
[2] Why Bernie is beating Hillary

This is the Cylon test I created for my original personal Raspberry Pi work over two years ago (seeĀ testing gpio with node.js and onoff, February 2014) except this time I executed it on the Raspberry Pi 3, not the original Raspberry Pi. In order to make clear what I did to run this from the RPi3 side, here’s what I installed on Arch Linux via pacman:

  • gcc
  • make
  • nodejs
  • npm

I was happy to see that the Arch Linux ARM repositories carried the latest node.js and npm, versions 5.8.0 and 3.8.1 respectively. I used npm to install a local copy of onoff. I needed gcc and make because npm builds part of onoff locally during installation.

This test actually uses the code I posted (and am reposting) back in March 2014. I’m going to use the i2c and port expanders for key input. But for testing the output I use the following simple code:

// cylon.js - JavaScript application to flash four LEDs in
// a 'cylon' like fashion from side to side.
// Requires node.js and onoff

var Gpio = require('onoff').Gpio,   // Instantiate the onoff.Gpio instance.
    led1 = new Gpio(17, 'out'),     // Export GPIO pin #17 as output.
    led2 = new Gpio(18, 'out'),     // Export GPIO pin #18 as output.
    led3 = new Gpio(27, 'out'),     // Export GPIO pin #27 as output.
    led4 = new Gpio(22, 'out'),     // Export GPIO pin #22 as output.
    iv1,                            // Function to be called periodically.
    shifter = 1,                    // Bit to shift back and forth.
    multiplier = 2;                 // Determines shift direction.

// This sets up the periodically called function.
// Function is called every 50 milliseconds (see end of setInterval(...)
// A single bit is shifted low to high, then high to low, and used via
// and AND mask, to either turn the LED on (bit is '1') or turn the LED
// off (bit is '0'). This single bit, moving back and forth across four
// bits, is used to turn on a single LED, giving the illusion of the LED
// moving back and forth, like the Cylon head visor in the original
// Battlestar Galactica series (which I personally found more enjoyable
// than the reboot).

iv1 = setInterval(function() {
    led1.writeSync(shifter & 1 ? 1 : 0); // 1 = on, 0 = off
    led2.writeSync(shifter & 2 ? 1 : 0);
    led3.writeSync(shifter & 4 ? 1 : 0);
    led4.writeSync(shifter & 8 ? 1 : 0);
    shifter *= multiplier;
    if (shifter > 4) multiplier = .5;
    if (shifter < 2) multiplier = 2;
}, 50);

// Stop blinking the LEDs and turn them off after 10 seconds.

setTimeout(function() {
    clearInterval(iv1); // Stop blinking
    led1.writeSync(0);  // Turn LED off.
    led1.unexport();    // Unexport GPIO and free resources
    led2.writeSync(0);  // Turn LED off.
    led2.unexport();    // Unexport GPIO and free resources
    led3.writeSync(0);  // Turn LED off.
    led3.unexport();    // Unexport GPIO and free resources
    led4.writeSync(0);  // Turn LED off.
    led4.unexport();    // Unexport GPIO and free resources
}, 10000);

With node.js and onoff installed type ‘sudo node cylon.js‘ at the prompt to execute.

The reason I’ve gone back to node.js is because the split that occurred nearly two years ago has been healed between the Node group and io.js, the fork. Things are back to a better state.

The video at the top was created using an Olympus E-M5 Elite and an M.Zuiko 12-40mm PRO zoom in manual focus mode, zoomed out to 40mm. The manual focus eliminates the constant and annoying in-and-out automatic refocusing of the first video I took of the Cylon lighting effect. The output was edited with iMovie on my iPad Air 2. Get used to the trippy little background music, as I’ll be using it on other similar technical videos in the future.

This post concludes my breaking-in of the new Raspberry Pi 3. It also is the start of a small break in RPi3 related work as I start heading back to my regular job. The next posts will be a bit more sophisticated and unique from any prior work.