Wednesday 22 July 2015

This time, it even looks like Perl!

I said before that my first attempt to get controlling the Raspberry Pi's GPIO pins from Perl looked ugly.  This time, I've added some methods to my JKLMwiringPi package, in an attempt to make the program look more like Perl.

Raspberry Pi Flavoured Shenanigans

The raspberry Pi folks make so much mention of Python that you might think support for other languages might be wanting.

I certainly had difficulty persuading Perl to control the GPIO pins.  I tried using the Perl bindings to WiringPi, but it seems that the underlying WiringPi library has changed since the Perl wrapper stuff was written, and now it either doesn't work, or segfaults.  The actual C library is fine, as I proved to myself during my testing phase; but I'm always a little bit wary of stuff going on fire when I try to program it in C.

I might redo it myself, if nobody else does, but I really wanted to get my Raspberry Pi up and running as quickly as possible.

Fortunately, there's a trick we can use:  Inline::C.  This is a Perl module that does some high-level magic and lets you call functions in a C library as though they were Perl functions.

Here's my version of a "Knight Rider" display using eight LEDs:

Easiest Raspberry Pi fix ever!

I thought I had killed my brand new Raspberry Pi 2, which was showing just a steady power light and that was it -- just like the state the machine is in after typing $ sudo poweroff and before disconnecting the power pack.  The mouse sensor was unlit, and the CAPS LOCK and num lock lights on the keyboard were dead.

However, it turned out to be a false alarm.

I disconnected the Internet, HDMI, keyboard and mouse cables, leaving only the GPIO connections  (which there were a lot of, and I really did not fancy disconnecting them unnecessarily).  Then, on a whim, I decided to try powering it up again -- and this time, I noticed the "disk" activity light flashing, and the lights on the Internet socket also flashed briefly.

Encouraged by this, I tried reconnecting just the keyboard, and noticed the caps lock and num lock lights were working. So I tried logging in blind  (it's not all that difficult, actually; remember that ctrl+U erases everything you typed since the last time you pressed Return, so you don't even have to remember how many times you need to press backspace)  and running my little test program.

And it worked!

So I shut it down cleanly; reconnected the mouse, Internet and TV; and powered it again.  And was back in business, just in time for Pi Day  (22/7)!