Building an Epaper Badge with a Raspberry PI Zero

jon heise
Coinmonks
5 min readJul 8, 2018

--

I’ve been wanting to build an electronic badge for Defcon for the past few year, this year I finally did it. Unfortunately during the build I did not keep an actual log, so this will be missing images at key portions. This overview assumes the reader has prior experience with soldering, python, linux, and the raspberry pi.

Parts List

Other Parts and Tools

  • Soldering Iron
  • Soldering helping hands
  • Solder
  • USB micro cable
  • USB battery
  • MicroSD card
  • Some means of writing to a MicroSD card

Install Header Pins

The Pi Zero usually comes without the header pins installed, so the first step is to solder the pins on.

Install ButtonShim

Now with the pins installed, flip the Pi over and solder the ButtonShim on. Make sure to leave the top of the pins clean since the E-Ink screen needs to go above this.

Install Raspberry Pi Zero Case

Only install the bottom half of the case, the screen won’t fit with the top half installed.

Install E-In Screen

Take screen, put on to of header pins, press down.

Download and Install Raspbian

Download the latest version of Raspbian, there are other distros, they should all work equally, I choose Raspbian. Additionally since I used a zero I setup wifi and ssh for remote access.

Download Waveshare Dependencies

Based on https://www.waveshare.com/wiki/Pioneer600#Libraries_Installation_for_RPi first install the necessary packages, under the latest version of raspbian all of the libraries they mention are available at packages in os repository.

Download ButtonShim Dependencies

The team at Pimoroni makes this step very very easy, run the following

This installs the python buttonshim library which provides decor

Enable interfaces

Run the raspi-config command, then select Interfacing options, then enable SPI I2C Serial

afterwards reboot your Pi

Testing the Hardware

First check the screen, download the waveshare demo from https://www.waveshare.com/wiki/File:2.13inch-e-paper-hat-b-code.7z

Unzip the archive, navigate to the raspberry pi demo, run the demo, if everything worked the screen should cycle through some images

Next check the buttonshim, download the demo code from https://github.com/pimoroni/button-shim/blob/master/examples/rainbow.py

run that, hit some buttons, watch the led change colors.

Installing the Badge Code

Assuming all hardware is functioning as expected, its time to either write your own badge code, or install the code I wrote.

Download https://github.com/jheise/ebadge/blob/master/badge.py into the same directory as the demo code for the epaper screen, there are a number of libraries that are not accessible system wide and this is the fastest way to make use of them.

Next run `sudo mkdir -p /var/badge/images`, /var/badge is where all data for the badge is stored. Using your text editor of choice open /var/badge/slogans.txt, this is a tab separated file holding all the text that gets displayed on the badge, lines need to be written as follows:

“DISOBEY <TAB> [scale|static|any] <TAB> [centered|static|any]”

In the above example, the first field is the slogan to display; the next field determines if the text should be scaled, not scaled, or randomly chosen; the final field determines if text should be centered, always start left justified, or randomly chose. Additionally lines can be commented out by making the first character in the string “#”.

Once slogans are ready its time to add some images, images for the screen must be in the form of bitmaps with a resolution of 104 x 212, images also must use only black and white as the image acts as a mask for what pixels to flip. The image loading function in script will only load images to black and white, but the screen is fully capable of loading two separate bitmaps that match together to make a three color image. Place any image you’ve made in /var/badge/images

Give the script a quick test run, make sure at least one slogan and one image loads before moving on.

Starting the Badge Script at Launch

There are plenty of ways of handling this, this was the method I used because I had no interest in dealing with init scripts or systemd or whatever means raspbian is using to launch things at boot

First move the python directory from the demo, where you downloaded the badge script to, move that /var/badge along with the rest of the files

With your favorite text editor open /home/pi/launcher.sh, write the following

Make the script executable and then add it to root’s crontab with the following

Now reboot and see if it works.

Bonus Points: Using the USB Gadget Mode of the Pi Zero

By now the badge should be powering up and changing text and images without human interaction, but when you want to change slogans or add images you either need a network connection or to pop the sd card out and write to it directly. Fortunately the raspberry pi zero can also act as a mass storage device, with this set up you just need to plug the badge into a computer and edit any code, text, or images your want over usb. These directions have been adapted from https://www.raspberrypi.org/magpi/pi-zero-w-smart-usb-flash-drive/

First move /var/badge to /var/badge.bak, the new partition is going to be mounted at /var/badge.

Next we need to allocate some space for the new part, put a file system on it, and create the mount point

Now make the entry in /etc/fstab with your favorite text editor

Mount the partition back and copy the contents of /var/badge.bak into the new version

To actually turn on the USB mass storage functionality a few different modules need to be enabled.

First enable the USB overlay driver, open /boot/config.txt with your favorite text editor, and at the bottom add

then open /etc/modules and add the following to the bottom

Now to actually make the partition available on USB, add this line into /etc/rc.local, this line needs to go above exit 0 at the end of the file

Now plug the pi directly into a computer and see if it mounts. I’ve only tested this on Ubuntu 18.04 Desktop edition and MacOS, I’m not certain if there will be issues under Windows

--

--