Top Stories / Tutorials

Off-The-Shelf Hacker: Showtime with a Linux Wearable

9 May 2018 9:29am, by

I’m feverishly prepping my steampunk conference badge (v5) for an upcoming tech talk at OSCON in July. My presentation covers badge build details, the various features and my thought processes surrounding the design. I’ll wear it as I walk around the conference, running a short “Dr. Torq” promo video, before the presentation.

A dramatic opening is a time-honored way of starting a session talk, particularly when it involves hardware. Making it memorable is important for a positive audience experience.

Go Huge or Go Home

The plan I came up with is to stand at the back of the room, dressed in my steampunk top hat, tweed jacket and paisley tie and greet attendees as they file in for the talk. At show time, I’ll walk to the front of the room, remove the badge, still running the video, from around my neck and plug it into the projector. After a quick reboot and a few inspirational words, we’ll launch into my show.

Do you think anybody will notice that the LibreOffice slides are running on the badge that I was just wearing?

Experience shows that there are lots of things that might go wrong, causing me to fumble around with the badge and hold up the whole operation. Not a positive way to captivate the audience.

I decided to use a little automation magic, morphing from badge to desktop mode, to head off erupting into a huge presentational fireball. You have to love Linux on a wearable.

Flip Between LCD and HDMI

The badge has a Raspberry Pi 2, a 3.5-inch color LCD touchscreen, some sensors and a steampunk-themed chassis and nameplate. You can plug a big screen or projector into the HDMI connector.

The most reliable way I’ve found to flip back and forth between the 3.5″ display and the HDMI port on a Raspberry Pi is to move a configuration file between directories and reboot.

For a long time, I used two small command-line scripts for the job. While looking at either the LCD or an HDMI attached monitor, I’d type in the appropriate command using the wireless keyboard and the badge would restart in the proper mode. It worked by copying the framebuffer config file (for the LCD) into and out of the /etc/X11 directory, then rebooting. Config file in the X11 directory for the LCD, no config file in the X11 directory for HDMI.

Here’s the code code.

sudo cp /home/pi/99-fbdev.conf /etc/X11/xorg.conf.d/
sudo shutdown -r now

And, here’s the code for

sudo mv /etc/X11/xorg.conf.d/99-fbdev.conf /home/pi
sudo shutdown -r now

They run from the command line as follows:

pi% ./



Of course, this approach has drawbacks. You look kind-of goofy carrying around a keyboard with a wearable Linux conference badge. Not only should it be headless (without a monitor), it should also be keyboardless when hanging from your neck.

What happens if I just want to shut the badge down and don’t have the keyboard handy? We don’t want to corrupt the SD-card on the Pi, by just pulling the plug.

Not only that, using the “-r”, reboot option doesn’t allow time to unplug or plug in the monitor before Linux starts back up again.

One-Button Solutions

A very practical solution is to use a couple of buttons to run the appropriate scripts. We should also change it to halt the system, with the “-h” option, so I have an opportunity to switch cables or just pack the badge for transport.

In the current configuration, the Raspberry Pi uses the SPI pins, plus GPIO pins #24 and #25 to control the LCD screen (SCK, MOSI, MISO, CE0, CE1). We might also use GPIO #18 for dimming the display. That still leaves 20 GPIO pins for possible button usage.

I chose GPIO #16 and GPIO #20 for my shutdown buttons. The buttons were wired from Ground to each respective pin through a 1K Ohm resistor. I used the built-in pull-up resistors in the Pi, so as not to have funny behavior due to floating (random voltage) pin readings.

Once the hardware pins were ready, I used a Python script to detect when a button was pushed.

Here’s the code.

import RPi.GPIO as GPIO
import time
import os


GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    # USB side button
    input_state16 = GPIO.input(16)
    # ultrasonic sensor side button
    input_state20 = GPIO.input(20)

    if input_state16 == True:
        print('Button 16 Pressed')
        os.system("sudo cp /home/pi/99-fbdev.conf /etc/X11/xorg.conf.d/")
	os.system("sudo shutdown -h now")
	# os.system("./")

    if input_state20 == True:
        print('Button 20 Pressed')
        os.system("sudo mv /etc/X11/xorg.conf.d/99-fbdev.conf /home/pi")
        os.system("sudo shutdown -h now")

GPIO.cleanup()          # clean up GPIO on CTRL+C exit

To make the scheme automatically work after a reboot, I added Python script execution to the /etc/rc.local file. You have to use sudo when editing the file since regular uses don’t have the proper permissions.

pi%  sudo vi /etc/rc.local

Here’s my /etc/rc.local file.

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multi-user 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.

python /home/pi/py-scripts/ &

exit 0

On bootup, the Python script loops forever in the background, waiting for one of the two buttons to be pushed.

Now when I walk to the front of the room and push the HDMI button, the badge will switch over to desktop mode. I’ll unplug the battery, plug in the projector and power up with a wall wart.

After my presentation, I’ll push the LCD button and the badge will revert to “walking around” (badge) mode. I’ll unplug the wall wart and projector. I’ll reposition the badge around my neck and power back up with the battery pack.

Next Steps

I’ve tested the LCD/HDMI switch process quite a few times, and it works very well. Of course, the procedure and timing will be fine-tuned in the dress rehearsals.

I’m thinking it might be good to automatically run the promo video on the 3.5 inch LCD screen when powering back up in badge mode.

Using buttons for the badge mode interface has a lot of possibilities. We aren’t limited to micro-switches. Would a pen and contact be useful? Don’t know. Or, how about magnetic reed switches. Would a multi-button wired pendant make sense? Maybe we could use that to control slides. We can sense the button presses in any number of ways using Python scripts or even the Processing language.

Go out and harness the power of Linux automation in your next wearable project.

A digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.