James West

May include blinky lights. And cocktails.

Tag: Raspberry Pi (page 2 of 2)

Building a K9 toy

We have a young Doctor Who fan in the house. His bedroom door is painted to resemble the TARDIS and my original #SuperSecretProject was a TARDIS console that sits on Edward’s desk. For #SuperSecretProject2 I decided to make a toy K9. Definitely a toy, and not a replica prop; I wanted Edward to be able to play with his K9 without worrying about bumps and scrapes, and I understand the limits of my time, patience, and most of all skill.


I wanted K9 to be able to be driven around by remote control, to play some sounds from the TV show and for his red eye panel to light up.

Acrylic sheets

Excitingly it all started with sheets of acrylic bought off the internet. You can get this cut to size in all kinds of colours, so obviously I chose grey (and one transparent red sheet). I got 3mm thick sheets, cut to A4 size. I remember cutting Perspex in design lessons at school with a hack saw and spending ages sanding the edges to a smooth finish, but that was over 30 years ago and the internet suggested scoring the acrylic and then snapping it like tiles. I’ve never actually cut tiles, but get the idea and gave it a go.

Trimming acrylic

Nine times out of ten this worked really well, and as I’d deliberately over-ordered I wasn’t worried about the odd miss-snap. The deeper I scored the better this worked, with ten passes of my Stanley knife seeming to be enough to ensure success. I made paper templates and transferred the measurements to the acrylic, which comes with a paper sheet covering each side making it easy to mark up, and protecting the surface from finger prints and tool marks.

K9s main body is made from four trapezoids hot-glued together, with strips of acrylic inside the corners to hopefully reinforce the joints and make it more rigid. Before I built any more of the structure I needed to stuff it with the gubbins that would make the robot dog bark and run.

So I sketched out a schematic of the circuitry, ordered some more stuff off the internet and started coding. I planned to use a Raspberry Pi Zero W for the brains (built in blue-tooth was going to be helpful for connecting to the Wii Mote), a Speaker pHat from Pimoroni to allow the sounds to be played and the motors and motor controller from a CamJam Edukit 3 I’d previously bought. I added one red and one blue LED, as well as a big arcade button, all of which I soldered to a Protozero board sandwiched between the Raspberry Pi and Speaker pHat.

Power for the motors would come from four AA batteries, with the Raspberry Pi getting juice from a USB powerbank, with a Micro USB extension mounted on the back panel of K9 so he can be easily charged up in between adventures.

The red LED was to be mounted behind the transparent red Perspex of K9’s eyes, and the blue one was planned to go alongside a button on his back. The button would trigger playback of the sounds I’d chosen to include in the project.

I’d previously coded a robot with the CamJam kit using RPI.GPIO, but this time decided to use GPIOZero which has brilliantly simple motor and robot recipes built in. It’s also really easy to program buttons, so K9s audio would be easy to do too. While I was doing the coding I realised it would also be easy to make the A button on the Wii Mote trigger sounds remotely, so I added that option too. The code is on Github if you want to look – K9’s blue LED flashes when he’s ready to pair with the Wii Mote and he says “Affirmative” when the pairing is complete and the blue LED goes steady.

I got a prototype assembly of the hardware and software going with very few tweaks, which I was pleased about.

K9 prototype

Next I had to squeeze everything into the body. This was harder than I’d expected because I’d built the body without really thinking about how much I’d have to stuff in there, or how I was going to mount it. But with a bit of patience and lots of hot-glue I got most of the innards located and was able to test drive K9 without his head or back in position. This was very comforting moment, because I was now almost certain that I’d be able to complete the project.

The head was too complex a shape for me to make quickly and easily in acrylic, so when I found a pack of five white A4 sheets of foam board at The Works for £3 I was delighted. I began by sketching head shapes and then making paper templates I transferred onto the boards before cutting with a knife. I had some grey spray paint left over from something else which wasn’t a bad match for the body, so applied a couple of coats and then hot-glued four of the pieces together. I’d drilled a hole in the front of K9’s body to pass through the wires for the red LED and made another in the base of his skull. I used a short corner section of black drain pipe for the neck, threaded the wires through and glued the neck onto the body. Then I soldered the LED (and a resistor, of course) to the wires and glued the rest of the head together before sticking it onto the top of the neck.

The arcade button and blue LED were pushed through holes in K9’s back and also soldered to their respective wires before glueing the back onto the top of the body.

This picture shows the mess of wires and parts inside K9.

K9 internals

Shopping list:

Stuff I already had in my maker box:

Doing a larger project like this is fun because it has really got me to do some problem solving and has made me work with materials I’ve not used before (or not for a very long time).

Do let me know what you think in the comments – how would you do it differently, or what would you like to build as a robot?

Raspberry Pi camera

Avenue evening

I do like a timelapse.

I recently subscribed to The MagPi magazine, and as a welcome gift received a Raspberry Pi Zero W, official Raspberry Pi case, camera connector cable and a few other bits and pieces. I already had a Raspberry Pi camera module knocking around, and as the case comes with a front that has a hole pre-cut for the camera, this gave me the perfect excuse to lash them all together.

Here’s a full list of parts used in the project:

  • Raspberry Pi Zero
  • Official Raspberry Pi Zero Case with camera connector
  • Camera module
  • ProtoZero board
  • Pimoroni Blinkt!
  • Male GPIO header
  • Female GPIO header
  • Right angle GPIO header
  • 3 tactile buttons
  • Hook up wire
  • Suction cups

I wanted to use buttons to trigger the starting and stopping of the timelapse, and to be able to take a single image, and planned at first to solder wires onto the back of the Pi Zero and hot glue some small buttons onto the case. Then I thought it’d be nice to also include an LED to show if the camera was on or doing something. (Everything is better with LEDs, right?)

This started to seem a little messy, but I remembered that in one of my boxes of bits I’ve a few ProtoZero boards from a Kickstarter a while ago. These are neat Raspberry Pi Zero sized boards with GPIO breakouts and lanes of breadboard-type sockets for components.

Raspberry Pi camera

The Raspberry Pi case comes with different fronts you can swap out. One is plain, with no openings, one has an opening for the GPIO pins and one has a hole and mounting points for the camera module. I needed to use this one, but it meant I had to solder a female header onto the back of the Pi Zero and connect the ProtoZero board onto that upside down. I added a right angle GPIO header to the ProtoZero board which let me add a Pimoroni Blinkt! for lots of LEDs, instead of just one.

Raspberry Pi camera

I was surprised, and relieved, when this rather hacky set up worked and my first attempt at running some code for the camera actually translated button presses into action.

Despite lots of trying, and lots of bad code, I’ve not been able to work out how to make a button interrupt a process and reset the Pi ready for another event, so I changed plans slightly and now have one button to take a single still image, one to start a half hour long capture of 120 images for a short timelapse and the third button to keep on taking pictures for a timelapse until your inelegantly pull the power out.

The Blinkt! lights shine white on booting up to show the camera is ready. When you take a single photo they flash red then reset to white. During a timelapse they display a column of lights counting up to the next image capture and flash red when a photo is being taken, so you’ve some idea when the next picture is due.


To put the timelapse together I FTP into the Pi, copy the images onto my MacBook and use iMovie to make them into a video.

The code is on GitHub – please comment if you can see improvements or have any ideas for me. I’m not a coder and would love to hear your suggestions. I found the GPIO Zero documentation to be really helpful, especially the recipes, and Alex Ellis‘ blog post was inspiring.

Finally, to secure the case to a window Frederick Vandebosch came up with this case mod just in time, so I ordered some suction cups off eBay and got cracking with my craft knife.

I’m really pleased with how this has turned out – even though it doesn’t have the functionality I intended when I started out I think the project has turned out really well.

Raspberry Pi internet radio

Last week I finished making my second Raspberry Pi powered internet radio.

Raspberry Pi Radio

Here’s a list of the hardware I used.

  • Raspberry Pi Zero
  • Pimoroni Speaker pHat amp
  • Protozero prototyping board
  • Adafruit 7 segment display backpack
  • 4 ohm 3 watt speaker, two buttons and a potentiometer from my box of bits and pieces
  • USB wifi adapter (if only there was a Pi Zero with wireless built in…)
  • Muji photo frame

The radio is a development of one I made a year ago, which borrowed heavily from the many internet radios Giles Booth has made.

I prototyped the hardware by stringing everything together with croc-clips and a breadboard. I removed the small speaker from the Speaker pHat and soldered some solid core wires onto the pads to hook-up the bigger speaker.

Raspberry Pi Radio

The code is based on Giles’, but I’ve modified it to use GPIO Zero and have added a second button which shuts the Pi down. The program runs clock.py as a subprocess, which is Adafruit’s code to display a clock on the 7 seg.


import time
import os
import subprocess
import sys
from gpiozero import Button
from subprocess import check_call

pid = subprocess.Popen([sys.executable, "clock.py"])

def shutdown():
   check_call(['sudo', 'poweroff'])

shutdown_btn = Button(17, hold_time=3)
shutdown_btn.when_held = shutdown

# pause()

button = Button(23)

# set station to 5 live
station = 5

os.system("mpc play " + str(station))

while True:
  station += 1
  # Assumes there are 7 stations
  if station > 7:
     station = 1
  os.system("mpc play "  + str(station))
  # pause to debounce - is quite long as found the buttons quite bouncy

You can also find the code on GitHub.

Once I was happy it all worked as expected I drew a template of the Muji photo frame on graph paper to get the layout of the components right and mark up where I would need to drill holes. The small holes weren’t any trouble, and were easily made in the two layers of the frame with my Dremel set to low speed. The larger holes were more of a problem and I destroyed one frame before discovering that masonry drill bits seemed to work better than any other I had. As bits of Perspex splintered around me I was glad to be wearing safety glasses! The back sheet needed a window cutting out of it for the 7 segment display to poke through. Again my Dremel was the best tool I had for this, and I managed to get a reasonably tidy hole cut.

I spray painted the back of the top sheet of acrylic white and mounted everything on it before doing the soldering. Finally I hot glued the 7 segment display into place.

This is the triple-deck arrangement of boards with the Speaker-pHat at the bottom, Protozero in the middle and Raspberry Pi Zero on top.

Speaker-pHat, Protozero and Raspberry Pi Zero triple stack

There are more photos here.

I’ve a few ideas for future modifications:

  • Work out how to get the VU meter on the front of the Speaker pHat pumping
  • Or use the LEDs to indicate which station I’m listening to
  • Make it tweet whenever I change stations (can I code it to only tweet after a station has been streaming for ten seconds so it doesn’t go crazy when I change from 5 live to Radio 2?)

eInk Twitter display

Last year I made this Twitter display using a Raspberry Pi Zero and a PaPiRus eInk display.

I loaded the code to GitHub and it’s recently been merged with the main demo code that PiSupply provides for their customers, which I was pretty excited about.

Christmas Celebrations – chocolate box LEDs with music

Nothing says “Christmas” like a box of Celebrations – especially one that plays Christmassy music and is lit with LEDs.


I’ve finished the code so that it now randomly chooses one of fifteen snippets from different Christmas songs to play while the LEDs gently pulse. With the addition of some jumper wires you can now choose from several sets of Poundland LEDs in different styles and colours.

Merry Christmas LEDs
Christmas Celebrations

If you want to look at the code, here it is:

Christmas celebration lights

At the end of my previous post I set a list of potential improvements to the Little Box of Horrors I’d made for Halloween.

This is the list..

  • At the moment it plays the same sound every time the button is pressed, but it’d be nice to play a random selection from a playlist of sounds
  • The lights could flicker and flash while the sound plays instead of being constantly on
  • If the sounds are of varying lengths the lights should only be on for as long as each sound plays
  • The lights and sounds could be swapped for Christmas or other gaudily celebrated occasions
  • Spray paint and decorate the box to be a bit less chocolate-boxy
  • Re-write it in gpiozero

Earlier this week I’d a pleasant afternoon cutting and soldering wires. I cut the connections between the Raspberry Pi and the LEDs and soldered jumper wires on so they’re now swappable.


Jumper wires

I also returned to Poundland and got a couple of packs of Christmas LEDs. As with the Halloween lights I cut the battery boxes off and soldered jumper wires to the ends, taking care to use red or black jumpers to indicate the polarity of the connections. Now I can choose Christmas or Halloween lights for the box.

Having had fun with hardware I thought I’d better have another go at the code, so I’ve re-written it in GPIO Zero, and discovered as a bonus that it’s really easy to control the LEDs with PWM so you can make them gently pulse on and off.

So in a couple of sessions I’ve crossed three items off my list!

  • At the moment it plays the same sound every time the button is pressed, but it’d be nice to play a random selection from a playlist of sounds
  • The lights could flicker and flash while the sound plays instead of being constantly on
  • If the sounds are of varying lengths the lights should only be on for as long as each sound plays
  • The lights and sounds could be swapped for Christmas or other gaudily celebrated occasions
  • Spray paint and decorate the box to be a bit less chocolate-boxy
  • Re-write it in gpiozero

Here’s the code:

Little box of horrors – Halloween hacking with pound shop LED lights

Inspired by Les Pounder’s hacking, I spent a quid on some LED pumpkin lights and thought I’d make something fun for the trick-or-treaters this year. I wanted the lights to come on and a spooky sound effect to play when a button is pressed on my little box of horrors.

Halloween lights

As Les suggested I removed the battery box from the LEDs, and then extended the wires with some hook up wire. I also found and edited some nice spooky sfx, which I saved onto the Zero.

The Raspberry Pi Zero has no audio output, so I added a pHAT DAC from Pimoroni; remembering to use extended headers so I could later add a ProtoZero board to tidily solder the wires onto.

Halloween lights

For the first prototype I connected the LEDs to a GPIO pin and the ground pin and started by writing some code that just made them come on and then go off again after a few seconds. Next I added a button which switched the lights on. Finally I used Pygame mixer to play the audio file at the same time as the lights come on.

The code looks like this:

# Import Python libraries
import RPi.GPIO as GPIO
import time
import pygame
# Set the GPIO caming convention
# Set the GPIO pins for button input and LED output
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.OUT)
while True:
if(GPIO.input(3) ==0):
GPIO.output(24, GPIO.HIGH)
time.sleep (10)
GPIO.output(24, GPIO.LOW)

I went back to my favourite Instructable on launching Python scripts at startup and then set about cramming it all – including USB powered speakers and a USB power bank – into a Celebrations box that I’d kept because it looked useful. I drilled a small hole in the side to pass the LED’s wires through, and a big hole in the lid for an arcade button. It’s a bit of a squeeze to get to the lid on, but it all just about fits in.

Halloween lights

There are plenty of things I could do to make this better. For instance…

  • At the moment it plays the same sound every time the button is pressed, but it’d be nice to play a random selection from a playlist of sounds
  • The lights could flicker and flash while the sound plays instead of being constantly on
  • If the sounds are of varying lengths the lights should only be on for as long as each sound plays
  • The lights and sounds could be swapped for Christmas or other gaudily celebrated occasions
  • Spray paint and decorate the box to be a bit less chocolate-boxy
  • Re-write it in gpiozero
Newer posts »

© 2019 James West

Theme by Anders NorénUp ↑