James West

May include blinky lights. And cocktails.

Page 2 of 2

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.

Timelapsing

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.

Corpse Reviver no. 2

This weekend we stayed at Stow House, just by Aysgarth Falls in the Yorkshire Dales. We have history with the place, having been back several times since our wedding reception there in 2000.

In the last few years Stow House (built in the 1870s for Reverend Stow who was Rural Dean of Wensleydale and a keen photographer) has been brilliantly refurbished by Sarah and Phil Bucknall who aim to provide beautiful rooms, excellent service and punch-packing cocktails. On Saturday before we went out for dinner, Sarah made us one of those cocktails and it certainly lived up to the mission statement. Rather than offering a full cocktail menu, Sarah asks what you like as a base for your drink and then suggests something for you. We went with gin, and Sarah offered us the Corpse Reviver No. 2, adding that it was one of the drinks made by Harry Craddock at the Savoy, and recorded in his Savoy Cocktail Handbook.

The recipe requires equal measures of gin, lemon juice, Cointreau, and vermouth to be shaken with ice and strained into a glass that’s had a rinse of absinthe. Lots of the recipes online specify Kina Lillet – as used in James Bond’s Vesper – for the vermouth, but that’s not available now so I reckon you can use whatever you’ve got in the cabinet. If you’re short of absinthe I expect you could get away with using pastis for an anise flavoured rinse.

Sarah’s Corpse Revivers were delicious, with an orange-and-lemonyness not unlike Inamoratas. It’s a refreshing drink that we’ll definitely be mixing at home, but I’m not sure I’ve the strength of constitution to drink it as a hair-of-the-dog.

Boozy book safe

There are loads of guides for making book safes on the internet and all the ones I looked at are pretty similar. The main ingredient is a book thick enough to hide your stuff.

Book safe

I had pretty specific requirements; I wanted to be able to store a drinks measure and a small bottle, so I went for my six novel James Bond anthology (when I did @bondsbooze I bought them all individually so I don’t feel any guilt about gluing the pages together and hacking a big hole through them).

We went away for the week recently and I was able to squirrel the measure and a bottle full of sugar syrup into our luggage, but I could have easily snuck a couple of miniatures in there. I think Q would approve.

I’ve broken my radio!

I’ve been trying to add new features to the radio in my previous post.

It’s meant to display the current time on the 7 segment display unless you push the button to change station. Then it displays the number of the new station from the playlist (Radio 1 is 1, Radio 2 is 2… you get the idea) for a few seconds then return to showing the clock. The clock runs as a subprocess called by Popen and I can get it to stop to allow the radio to show the new station, but then I can’t re-start the process. The code is here on GitHub, with the related config.py and is repeated below.

It’s line 42 that reads config.proc_Popen that’s got me baffled. If you’ve any clever ideas please leave a comment.

#!/usr/bin/python

import time
import datetime
import os
import config
import subprocess
from time import sleep
from gpiozero import Button
from speakerphat import clear, show, set_led
from signal import pause
from subprocess import check_call

def shutdown():
    config.proc_Popen.kill()
    os.system("mpc stop")
    clear()
    config.segment.clear()
    config.segment.write_display()
    check_call(['sudo', 'poweroff'])

def retune():
    config.station += 1
    # Assumes there are 7 stations
    if config.station > 7:
        config.station = 1
    os.system("mpc play "  + str(config.station))
    # updates the Speaker pHat LEDs to show the station
    clear()
    for x in range(config.station):
        set_led(x,180)
    show()
    # stops the clock subprocess and shows the station on the 7 seg  
    config.proc_Popen.kill()
    config.segment.clear()
    config.segment.write_display()
    config.segment.set_digit(3,config.station)
    config.segment.write_display()
    time.sleep(4.0)
    config.segment.clear()
    config.segment.write_display()
    config.proc_Popen # This is the bit that's got me baffled.

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

retune_btn = Button(23)
retune_btn.when_pressed = retune

# starts clock.py
config.proc_Popen

# sets the Speaker pHat LEDS to indicate the station
clear()
for x in range(config.station):
    set_led(x,128)
show()
os.system("mpc play " + str(config.station))
pause()

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.

#!/usr/bin/python

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:
  button.wait_for_press()
  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
  time.sleep(1.0)

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?)

Inamorata

My mother-in-law read Veronica Henry’s “A Night on the Orient Express” which includes a recipe for a cocktail called the Inamorata. Knowing that we like a cocktail, she passed this on we’ve been regularly enjoying these ever since. The ingredients are inspired by the journey from London through Paris onto Venice.

  • 25ml lemon juice
  • 50 ml London dry gin
  • 25 ml Cointreau
  • Prosecco

The lemon juice, gin and Cointreau are shaken with ice cubes, strained into a glass and topped up with prosecco. It’s a delicious and refreshing drink that has entirely dishonourable intentions, and if you risk a second one it will try to take advantage of you.

Inamorata

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.

Untitled

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
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# 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)
pygame.mixer.init()
pygame.mixer.load(Laugh.wav)
while True:
if(GPIO.input(3) ==0):
GPIO.output(24, GPIO.HIGH)
pygame.mixer.music.play()
time.sleep (10)
GPIO.output(24, GPIO.LOW)
GPIO.cleanup

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 »

© 2018 James West

Theme by Anders NorenUp ↑