posts tagged with the keyword ‘code’



I’ve been using Raspberry Pi single-board computers for video players for years now, and I’ve also used them as audio players, but I was missing a good way to use them as slide show devices… Until now.

I’ve used Screenly OSE for the MMPIS at Milwaukee Makerspace, and while Screenly is great for what it is (a network-connected, browser-controllable, digital signage device) sometimes you don’t want all the options and features and you don’t have a network. So I needed another solution.

I found fbi, “the Linux framebuffer imageviewer”, which can run at boot up and display a folder full of images at full screen with a configurable delay between changing images. Perfect!

Boot Volume

Now, there’s one more thing… If I’m going to put this somewhere that doesn’t have a network connection (like, in a museum) I want to be able to easily update the slides. The slides won’t be changing daily, but may be changing every month or so. For something like this it’s easy to store the images directly on the /boot volume, which is accessible on the SD card when you pop it in a Mac OS X or Windows computer.

You’ll notice a folder names “slides” and a file named “”, which do the hard work here. It’s actually ridiculous to call it “hard work” because it’s dead simple. The slides folder contains images which will be displayed in alphabetical order. (Sadly, my screen shot does not reflect this!) In an ideal world you’d name your images 0001.jpg, 0002.png, 0003.jpg, etc. Just name them in order, and they’ll display in order. Easy.


The SD card only has about 40MB of free space for you to put images on, but with JPG compression of photos, you can probably fit plenty of them. OK, so once you’ve got your folder full of images (which you can easily update on the SD card) you’ll need some way to run the script.

Typically I do a sudo nano /etc/rc.local and add what’s needed to run my script. In this case it’s the /bin/bash /boot/ & you see on line 20. Oh, don’t forget to set the Pi to auto-login at boot. Since it’s been added to recent versions of Raspbian you don’t even have to muck around anymore.

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"

/bin/bash /boot/ &

exit 0

So yeah, we’re all set… but you probably want to see the code in, right? This is it. Right here. Yes, it’s pretty much just two lines. Linux is like that sometimes… It’s not hard implementing something, it’s just hard finding out exactly how to implement something. It can be hard finding those two lines that you need! (The 20 may need adjustment. Longer may be better, but in my testing on a Raspberry Pi 2 Model B it worked well.)


sleep 20

fbi -a -t 6 --blend 200 --readahead --noverbose -T 1 /boot/slides/* >/dev/null 2>&1

There’s some parameters you can set, like -t 6 which sets each slide to display for 6 seconds, and the blend thing, which sort of works. Hey, it’s a slide show, okay!?

I’ll probably work on this more, but I was pleased to find a solution so I thought it was worth sharing.


Teensy++ 2.0 LED Pin

Yes, this post is actually titled “Teensy++ 2.0 LED Pin” because it’s really specific. This is the solution to a problem that took me a while to fix. Actually, it didn’t take a long time to fix, it just took a long time for me to figure it out and implement it. (Maybe it did take a long time for me to fix…)

Anyway, when using most pins on a Teensy++ 2.0 (and probably every other Teensy) with Arduino code, you may have an issue using the LED pin as an input, because it functions differently than all the other pins. You might say “Hey, just use another pin!” but the project I did required every single pin on the Teensy++ 2.0. (Yes, all 46 pins!)

The code is below. The LED pin is sort of treated opposite of how other pins are treated. You short it with +5v instead of ground, and swap the risingEdge and fallingEdge typically used with the bounce library.

// LEDPinButton

#include <Bounce.h>
Bounce buttonD6 = Bounce(6, 80); // LED Pin - tie to +5v instead of GND
Bounce buttonD7 = Bounce(7, 80); // Normal Pin - tie to GND
void setup() {
  pinMode(PIN_D6, INPUT);        // LED Pin - use INPUT not INPUT_PULLUP
  pinMode(PIN_D7, INPUT_PULLUP);
void loop() {
  // D6 - LED Pin - tie to +5v instead of GND
  // use risingEdge instead of fallingEdge
  // a
  if (buttonD6.risingEdge()) {
  if (buttonD6.fallingEdge()) {
  // D7 - Normal Pin - tie to GND
  // b
  if (buttonD7.fallingEdge()) {
  if (buttonD7.risingEdge()) {

You can also grab this code from github.


Banana Logo

I’m posting this because someone asked for it, and I aim to please… Here’s the Banana Pong code. I used code someone else wrote to bootstrap this thing, but there was no comment about who wrote it, and I didn’t make record of where I grabbed it, so… no attribution. Sorry! If it’s your code, let me know.

Have fun playing Banana Pong with your MaKey MaKey!

Note: The first ZIP file is the Processing source code. The second is a Mac OS X application. Since Processing has changed how it exports applications I can’t easily create versions for Windows and Linux like I did for the Apple Piano code. So if you want a Windows or Linux standalone version, you’ll need to grab the code and do it yourself. It should serve as a good starting point.



There’s been so much talk about learning to code lately… I figured I should provide some insight, as someone who has been writing code that computers can understand (sometimes) since the early years of the 1980s.

Writing code is fun! Well, sometimes. You know, on the rare occasions when your code actually works. Writing code can be fun, just like things blowing up can be fun… under the right circumstances. Fireworks on the fourth of July? Fun! Your car’s engine blowing up? Not fun! Don’t worry, your code will “blow up” on occasion, and you’ll have to fix it. Often this will happen at 2:30am.

Maybe writing code is fun like driving is fun. You know, a cross-country trip, 20 hours straight in a car with cranky, smelly people… that’s fun! Having things break for no reason and having to spend lots of time (and possibly money) fixing things? Fun!

I’m partially kidding, of course. Writing code can be fun, but it can also be terrible. You’re typing at a keyboard with the goal of telling a computer what to do. We really are slaves to the machine. Computers were supposed to help automate everything so we’d have more free time for leisurely activities like building robots, which of course require you to program a computer to make them work. It’s a vicious cycle!

But hey, you should write code. You should write code to solve problems. You could be awesome and release that code under an open source license so the next poor sucker doesn’t spend 10 hours solving the problem you already solved. Of course some people/companies/organizations believe that everyone should solve their own problem, so they won’t let you share your code, even if you wrote it on your own time… don’t work for them. Work for the betterment of humanity.

You should also write code for fun, real fun, enjoyment, for real! Write code that does something silly, or stupid, or amazing, or to play a prank on someone. Don’t lose sight of the fact that learning should be an enjoyable experience. Most programmers I know have a sense of humor. It’s probably a requirement for that line of work.

But… which language should you choose? Eh, it doesn’t matter. Start with the easy ones, perhaps a scripting language. It may be all you need. I’ve been using Perl for about 16 years, and I still use it all the time because it’s the fast and easy way for me to get things done. I like getting things done more than I like buzzwords or whatever the popular kids are using to write code.

So yeah, write some code… see if you like it. If you hate it, don’t write code. Find something else to do. The world always needs people to bake things. Baked goods are delicious and very enjoyable, and it’s extremely rare that someone complains that a loaf of bread just “stopped working” or somehow didn’t do what they wanted it to do.

Bake on, man… Bake on!


Makey Makey Apple Piano

I’m one of those people who say “I’ll publish that code later!” and then I get busy with other projects and never publish the code, so here’s me publishing the code.

So back in January I built the MaKey MaKey Apple Piano for one of Art Milwaukee‘s events that the Milwaukee Makerspace was involved in. And yeah, here’s the code!


I’ve provided the Processing sketch and related data files, as well as full applications (for multiple platforms) for those who don’t want to mess around with compiling sketches, and just want to download and run an application for their MaKey MaKey.

Could it use improvements? Of course it could! Feel free to make it better, and if you do, please share your changes with others.

« Older Entries |

buy the button:

Buy The Button

top recent artists: