InkyPhat Flotilla radio

I treated myself to a Pimoroni InkyPhat Raspberry Pi e-ink display – it’s small but good value compared with some other e-ink displays… and it has THREE colours: black, white – and red. It comes with some beautifully-designed examples such as a calendar, a local weather display and a badge-maker. Being an e-ink display, it retains its contents after the power goes and hence you can unplug it from the Pi and wear it!

Obviously the first thing I had to do was make a radio, so I tweaked my Flotilla radio so it only uses the rotary dial for volume and the 4-button touch panel to choose pre-set stations.

The display update is slow, I guess to ensure maximum quality – there’s none of the ghosting of old images I experienced in early e-book readers. It also forces you to listen to a few seconds of each station before changing channel. And I quite like the drama of the thing.

Making the artwork was a bit of a drag – you have to save images as PNG files with a very specific colour palette – 3 colours only and they must be in the right order. I hate GIMP at the best of times but it drove me mad as I kept getting images that looked ok on screen but swapped colours on the InkyPhat. Eventually it all came good.

I’m really looking forward to making more projects with this neat little colourful e-ink display.

Here’s the code – it assumes you have installed Flotilla and InkyPhat and needs Flotilla Touch and Dial modules. You will also need to have installed mpc and mpd and added 4 radio stations as described in my Flotilla radio project.

#!/usr/bin/env python

# simple internet radio with Flotilla and InkyPhat
# Script by Giles Booth x
# www.suppertime.co.uk/blogmywiki
# Always stop flotilla daemon before running Python with Flotilla
# with 'sudo service flotilla stop'

import os
import sys
import flotilla
import inkyphat
from PIL import Image, ImageFont

# Looks for the dock, and all of the modules we need
# attached to the dock so we can talk to them.

dock = flotilla.Client()
print("Client connected...")

while not dock.ready:
    pass

print("Finding modules...")
touch = dock.first(flotilla.Touch)
dial = dock.first(flotilla.Dial)

if touch is None or dial is None:
    print("Some Flotilla modules required were not found...")
    dock.stop()
    sys.exit(1)
else:
    print("Found. Running...")

os.system("mpc load")
dial_val = 0

inkyphat.set_image(Image.open("splash.png"))
inkyphat.show()

# Starts the loop going so it keeps working until we stop it
try:
    while True:

# volume control using dial
        new_dial_val = int(float(dial.data[0])/10.23)
        if new_dial_val != dial_val:
            dial_val = new_dial_val
            os.system("mpc volume " + str(dial_val))

# Looks for a Touch module and listens for an input

        if touch.one:
            os.system("mpc play 1")
            inkyphat.set_image(Image.open("logo-6music.png"))
            inkyphat.show()

        if touch.two:
            os.system("mpc play 2")
            inkyphat.set_image(Image.open("bbc-ws.png"))
            inkyphat.show()

        if touch.three:
            os.system("mpc play 3")
            inkyphat.set_image(Image.open("fip.png"))
            inkyphat.show()

        if touch.four:
            os.system("mpc play 4")
            inkyphat.set_image(Image.open("radio4.png"))
            inkyphat.show()

# This listens for a keyboard interrupt, which is Ctrl+C and can stop the program
except KeyboardInterrupt:
    os.system("mpc stop")
    inkyphat.paste(inkyphat.Image.new('P', (inkyphat.WIDTH, inkyphat.HEIGHT)))
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 36)
    print(dir(inkyphat.fonts))
    message = "goodbye"
    w, h = font.getsize(message)
    x = (inkyphat.WIDTH / 2) - (w / 2)
    y = (inkyphat.HEIGHT / 2) - (h / 2)
    inkyphat.text((x, y), message, inkyphat.RED, font)
    inkyphat.show()
    print("Stopping Flotilla...")
    dock.stop()

Here are the image files I made:

This entry was posted in Raspberry Pi and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>