Lockdown project 2 – wooden Pi Camera

So after reading this article about building your own camera with a Raspberry Pi 4 by Becca Farsace from The Verge I was sold. It was still (sort of) lockdown, I had waaay too much Raspberri Pi stuff. So i went about making my own.

First off I got the core components.

  • Raspberry PI 3A+ (already owned)
  • Raspberry Pi camera module
  • C-Mount lenses (Pentax 25mm, Raspberry Pi 6mm Wide Angle Lens)
  • Puck.js button (to remotely control the device – essentially the shutter release button)

I then tried to get a suitable case, I first bought a couple of second hand broken camera bodies off of eBay, an old Pentax film camera, but it was too small to house the Pi, then a Olympus underwater camera housing which very nearly worked after hacking at it, but I couldn’t then screw the lenses in! Finally I decided I needed to make the case. So bought some 3mm plywood…..

Et voila.

View of camera from the front

Now for the programming, I am a web developer, but my craft is HTML, CSS, Javascript so not really a l33t python dev. So this was mostly trial and error, oh and a shit load of googling (a.k.a. The Web Developer’s Handbook ™ ® ©)

I use rmate because I *still* can’t use VI/nano

The first file is the command we want to run, based around raspistill, well use this later. So I created a file called camera.sh which will take the photo and save it to an Apache server instance to you can remotely access it, e.g. http://192.168.0.*

#!/bin/bash

# Unix time and date filename
sudo raspistill -f -ts -o /var/www/html/photos/PI_CAM_%d.jpg

Now to set up the Puck.js button, we can use the web based IDE to flash code the device, this code (below) will allow the Puck.js button to act like a bluetooth keyboard key, e.g. F7, (note the Puck needs to be paired with the Pi)

//For Puck.js 8b1e

var kb = require("ble_hid_keyboard");
NRF.setServices(undefined, { hid : kb.report });

//F7 key - https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
function btnPressed() {
  ledBlink();
  NRF.sendHIDReport([0,0,64], function() {
    NRF.sendHIDReport([0,0,0]);
  });
}

// trigger btnPressed whenever the button is pressed
// consider repeat:false
setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50});
function ledBlink() {
  LED3.write(true);
  setTimeout(function() {
    LED3.write(false);
  }, 250);
}

Now we need to set up a multimedia keyboard daemon that can intercept the Puck.js button click (which for our purposes is going to act as a bluetooth keyboard – a one key keyboard). I found something called esekeyd and here are the various commands to get that firing

sudo apt-get install esekeyd
sudo keytest /dev/input/event1

// sudo learnkeys /etc/esekeyd.conf /dev/input/event1
// where eventX == result from above, e.g. event1

sudo learnkeys /etc/esekeyd.conf /dev/input/event1

// Press F7 (), esekeyd will create the configuration file you need (esekeyd.conf). You then need to edit it with your editor of choice. You’ll see a line like this: `#F7(press):` Delete the #, and add your desired command directly after the : (no spaces!). Your new line might look something like this:

F7(press):/home/pi/camera.sh

// Make sure the sh file is executable

chmod +x camera.sh

// Now let's set up the config
touch esekeyd.conf
rmate esekeyd.conf
sudo cp esekeyd.conf /etc/esekeyd.conf

//run the file
sudo esekeyd /etc/esekeyd.conf /dev/input/event1

//to run on startup
sudo nano /home/pi/.bashrc
sudo esekeyd /etc/esekeyd.conf /dev/input/event1

//or
mkdir -p ~/.config/autostart
cd /home/pi/Desktop
touch terminal.desktop 
rmate terminal.desktop
sudo cp terminal.desktop ~/.config/autostart

This file, terminal.desktop, will launch terminal and the esekeyd service so the camera is ready to take clicks from the button however this didn’t work for me, terminal opens up but I get an error ‘Failed to open /dev/input/event1 (Permission denied)’ I think this is because bluetooth hasn’t enabled yet, I dunno.

[Desktop Entry]
Version=1.0
Name=Test        
Comment=Test the terminal running a command inside it
Exec=/usr/bin/lxterminal -e "bash -c 'sudo esekeyd /etc/esekeyd.conf /dev/input/event1;$SHELL'"
Icon=utilities-terminal
Terminal=false
Type=Application
Categories=Application;

And there we have it a (mostly) working camera. Here is it:

And here is a time-lapses I took with the wooden pi Camera.

And some of the camera in action / build process

View of camera mounted to balcony
Me building the wooden case

Hackercise bike

During lockdown I was fortunate enough to have continued work building websites, in-fact due to Covid-19 various organisations needed to pivot focus I was busier than usual. So although I didn’t suddenly find myself with loads of time on my hands there was still plenty as I wasn’t going out or travelling to an office.

And on that part of not travelling, I really missed my daily cycle into my office space. It was only 2 miles each way but with lockdown I really started to feel the lack of that daily exercise.

So I emergency purchased an exercise bike – a ‘Roger Black Gold Folding Magnetic Exercise Bike’ for £109 from Argos a week before lockdown (we all knew it was coming right).

During the early stages of lockdown it was a real boon. But I still missed the feel of my bile as well as the ability to track my ride. The Argos one very much didn’t have these capabilities. As such the Hackercise bike was born. I bought or repurposed the the following.

  • Bike tape
  • Garmin Speed Sensor 2 (key to tracking distance)
  • Garmin Cadence Sensor (optional)
  • Garmin out front mount
  • Garmin 520+ Edge bike computer

Now the Speed sensor is meant to go on a proper bike, and the one I bought had a flywheel, I tried to see if I could attach the sensor to it in some way, but there was no good place to do so. So I attached it to the pedal crank. I read somewhere that if you then give the Garmin Edge a fake wheel circumference that you could trick it into thinking it’s a real bike. Anyway, I did so and using the existing speed sensor that came with the bike I was able to calibrate the sensor with the wheel circumference at a massive 4.85 meters. But what the hell, I had an accurate(ish) reading.

It was on.

That sorted I removed the foam padding from the bars, removed the existing computer (basic LCD) – tapped up the bars, and added the mount. It actually felt like a real bike! And I was able to record my rides!

The project had two purposes, firstly a little focus during some pretty dark times, and secondly it also allowed me to exercise more which then helped with purpose one.

And it worked! Here’s a Strava activity from the Hackercise bike.

And some photos, the first one is the original setup.

2020 2019 2017 2016 2014 2013 2012 2011 2010 2009 2008 2007 2006 2005 2004