Thursday 15 December 2022

Slack/Whatsapp controlled colour-changing and morse code Christmas lights

Several years ago I made some Christmas lights that could be controlled via Slack and WhatsApp, and every year since I find that I need to update the interface to these platforms to account for the changes that they make during the year. 

Usability updates

This year whilst I was doing that, I took the opportunity to add a few new features and simplify the interface.

Now it responds to some key words – all, top, bottom, half, alternate, led, and allows the user to specify certain colours by word and all colours by hex code.

Additionally I refined the serial interface to speed things up.

Moving to a single-board computer

For my home implementation of this, previously I would just run a USB extension lead from my desktop. 

I have now migrated the code to a PCDuino2 single board computer. This is a 1Ghz Allwinner A10 chip SBC, which also contains Arduino pin headers.

The board is discontinued (I bought this one from Maplin years ago during their closing down sale), and as a result there is little in the way of official repositories or archives for the Ubuntu variant distribution that it runs. Plus it looks like there’s some sketchiness around the official firmwares around the allwinner chip that powers it.

I found a version of Armbian linux for this platform and burnt it to a micro SD card.
This allowed me to get the PCDuino to boot to Armbian.

Unfortunately it looks like there is no real support for installing Armbian to the NAND storage which is on the PCDuino. However, leaving it on the micro SD has some advantages such as easily being able to image and back up the install.

Then it was simply a case of connecting it to the network and updating it, enabling SSHD for ease of maintenance going forward, and installing required tools for the Christmas lights server (JDK and Arduino).

As the PCDuino is not a typical Arduino development board it needs its own board definition to be used with the Arduino IDE, so for now I decided to continue using an externally connected Arduino.


Implementing morse code

One of the downsides to the set up the I currently have is that the serial data transmission can be disrupted by the update process transferring data from the Arduino to the lights.

The changes I have made reduce the amount of data that is transmitted via serial and so minimize the problem.

However there is additional functionality that I wish to add that will require further data to be transmitted – that is to have a set of lights which flash similarly to regular Christmas lights, but instead of a standard or random pattern, they blink out morse code, based on a message input from the control application.

Rather than cram more functionality into the WS2812 lights that I am currently using, I plan to leave them be and use a regular set of plain white fairy lights for this. Typically I have always decorated our Christmas trees with a multi colours set and a plain white set, so this fits with what I would typically do anyway.

The lights I used are powered from 3xAA batteries (4.5v), which can easily be substituted for USB and powered from a USB hub. To toggle their on and off state, I have used an optocoupler which will be toggled from the PCDuinos GPIO pins.

The ‘arduino-style’ pins of the PCDuino board can be reached in be linux file system via GPIO – similar to the way I toggled an output pin on the frequency switch project.

Seeing is this makes it quite easy to simply toggle a pin on and off, I should be able to use this for the morse code without having to depend on the rather outdated and no longer supported PCDuino board definitions.

Finding the pin reference

A ‘gotcha’ about using the sysfs GPIO interface is that the pin numbers as they may have silk screened on the board do not necessarily correlate to the pin numbers in the file system.

The first thing to do is figure out what the pin identifier would be. In this instance, I found some config files for the PCDuino on GitHub.

There lists the PCDuinos GPIO pins and there corresponding identifier, summarised below.


I’d decided to use GPIO 8, so the relevant ID is H10

The Sunxi wiki demonstrates how to calculate the relevant GPIO number from that ID

(position of letter in alphabet - 1) * 32 + pin number

so with H10, H is the 8th letter so

(8-1)*32 + 10 = 234

So with that number calculated, we can export the pin with

echo 234 > /sys/class/gpio/export

which will make ‘gpio234’ available under /sys/class/gpio.

From there we can make it an output, and change the ownership so of it’s value file so that a regular user can write to it.

echo out > /sys/class/gpio/gpio234/direction

chown -R ant:ant /sys/class/gpio/gpio234/value

Then to switch the lights on,

echo 1 > /sys/class/gpio/gpio234/value


echo 0 > /sys/class/gpio/gpio234/value

to turn them off

A demo video is below, and as usual the source is available on GitHub.

Merry Christmas!



Saturday 15 October 2022

Treadmill Videogame Controller

Like a lot of people, I spend a lot of time trying to balance the need for exercise and fitness with the desire to sit on the couch and play video games.

So I figured why not combine the two.

To start with I picked up a treadmill – this one is a manual treadmill as I want its movement to be dictated by my running, not by some electric motor.

There is a small control panel on the treadmill which provides some statistics. It is completely optional and not required to use the treadmill. It gets it’s power from a separate battery supply.

Although this is not particularly useful to me, it does indicate there is some type of encoder in the treadmill assembly to measure these values. Before even taking the treadmill part I can surmise that this is most likely either a magnet and reed switch assembly, a hall effect sensor, or a rotary encoder.

Once I got the treadmill, I could see a simple 2-wire lead from the base of the unit through to the control panel, connected with a 3.5mm jack.

I breadboarded a small breakout so that I could connect the oscilloscope and see what kind of signal was being passed.

This revealed that there’s 2.5v being sent down the line (tip of jack is positive), and that the signal would transition between high and low as the treadmill was used, and the frequency would increase as the speed increases.

In it’s most basic form, if we can translate those state transitions to key presses, that should work.

There was however a whole lot of noise in the signal which seemed to be caused by resonance in the treadmill frame, as there would be severe jumps simply by my touching it.

Initial Implementation

An initial attempt to use an Arduino and have the signal trigger interrupts wasn’t successful due to the noise, and filtering attempts became quickly time consuming.

The requirement for the filtering and the requirement for it to be an input device led me to a MakeyMakey development board.

This board is advertised as an educational toy, that allows users to turn anything into a key. In order to do this it provides a significant amount of signal processing and filtering. So in other words, exactly what I’m looking for.

This means that very little is required on the software side, as the Makey Makey presents inputs to the computer the same as a keyboard would, and applications generally will not notice any difference.

By simply connecting a crocodile clip from the tip of the 3.5mm jack to an ‘key’ on the Makey Makey, and connecting the body of the jack to the ground of it, that is already enough to get some response. Every pulse sent by the treadmill gets interpreted as a key press and release by the Makey Makey.


The only problem with that is with the treadmill in normal operation, the pulses (and therefore keypresses) are so quick that they do not translate real world movement into equivalent in-game movement.

With the treadmill running, the red marks show the time that the key is pressed. The two ‘bursts’ of movement on the treadmill appear as a total of 14 short keypresses.


Instead, either the rapid tap causes the character to barely move, or if the treadmill stops when the signal is high, the character runs at full speed without needing any further movement on the treadmill.


The treadmill stopped when the signal is high – making it look like the key is held down indefinitely, even though the user is not running


What I want to do is to bring the game input more “in step” (ha) with the movement of the treadmill, so that the same two bursts of treadmill movement would look more like the following:


The two bursts of activity are represented as two longer keypresses, as if the key were held down for the time the treadmill is moving

To do this, I forked the source repository of the Makey Makey project, and made some edits.

The changes are mostly in the updateInputStates function, and focus on the ‘right’ key on the Makey Makey, as I will be using a side-scroller game to test.


To demonstrate what this change does, below are two screenshots which represent a few seconds of continuous running on the treadmill.
The first is with the treadmill connected to the “Up” key, which is unaffected by the code changes. The input is shown as repeated press and release events.
The second is with the treadmill connected to the “Right” key, which is the one that I have changed.
The impact is shown any as press events, up until the point that the treadmill stops. This is the same as if the key were held down.

The test code is based on KeyEventDemo – the only change is that I removed the KeyTyped event as it is not relevant to this exercise.


Unfortunately there is no way of determining the treadmills direction of travel as it was obviously not designed for that, but in a game I may want to change direction.

What I have done is a workaround for now is I have made the same change for the left key as I did for the right and have wired the treadmill to the Makey Makey like so:

This means by simply flicking the switch I can change direction. In a subsequent moment of inspiration I swapped the switch for a pair of reed switches and a magnet attached to one of the cross-fit handlebars that are on the treadmill - allowing for the direction to be controlled with the left lever.

I have also wired a simple momentary switch to the space key to allow my character to jump.

For now this whole contraption is held together by screw terminals and crocodile clips as it is only a prototype and is a platform I want to expand on in future.

The Game

For this initial experiment I wanted to use a game where input is limited, as a proof of concept.

To keep with the theme of running and speed Sonic the Hedgehog seemed like a suitable choice.

I will be running this on a PC with a Sega Genesis/Mega Drive emulator.

Please note the various copyright and legal complexities around the use of emulators and ROMs - the short version is that you should not use ROMs of games you don't own.

I actually own two copies of the game - an original Mega Drive cartridge, and a PC version as part of the "Sega Mega Collection Plus". It's just that the Mega Drive emulated ROM is easier to interface with.

The end result:


Sunday 21 August 2022

Singer sewing machine table

The finished product



The Beginning

This old Singer sewing machine belonged to my grandparents, and then spent years left in my parents garage until I got interested in leather work and took it, wondering if it might be usable for that.

Although the machine itself seems mechanically sound the electronics seem to be trashed.

Using it trips the circuit breaker, the belt from the motor to the machine was hanging together by a thread, so all in all, not very successful.

To begin with, I removed all the electrical pieces - the machine can still be hand-operated without them, and I wanted to make use of it, so I could always return to those later.

I'd seen similar sewing machine models that were part of a table or cabinet set-up, with cast iron legs and treadle operated.

I'm told that this machine originally used to have one, back when it was my grandparents', but they have since been lost to the sands of time.

I was hoping to be able to recreate that, but it seems they are rather sought-after by trendy people turning them into side tables, which has pushed the price up considerably.

So, instead of going for an accurate restoration, I opted for an 'inspired by' build. 

The base of the machine is quite thick, due to the mechanical workings underneath the machine, but for using it on a worktop, the step can be quite annoying, so my idea was to make a butcher-block style surface, which the machine can be recessed into.

I opted to build my own butcher block from pallet wood, to keep costs down, and to give myself an excuse to buy a planer/thicknesser (still worked out cheaper than just buying a butcher block!)


I'd aimed for a maximum dimensions of 100cm x 50cm table surface, in order to fit the space I'd allocated for putting the table in my home.

The bulk of the butcher block construction is simply, plane, thickness, trim, glue, clamp, wait, repeat.

Rather than build one solid block and cut the recess for the sewing machine in, I decided to build the block in four different sections - full-length front and back sections, and then two shorter side sections, leaving a gap in the middle to form the recess.

This allowed me to cater for space constraints in the workshop, tool limitations (maximum width of the thicknesser), and to make use of the shorter lengths of pallet wood.

I also opted to offset the recess to move the machine towards the right of the tabletop, to increase space on the left hand side, which is where the sewing would be done.

The four main segments - the blue area is where the sewing machine will be recessed



Once that was done, the edges were straightened up and some strips of mahogany were attached to the end to cover the end grain, and tidy-up the design.

3 coach bolts were added and recessed on each side to provide some mechanical retention and also to add to the rustic-industrial aesthetic.

The gap in the middle was by design slightly smaller than the footprint of the sewing machine - this allowed me to cut a rebate to size and provide a platform for the machine to sit on.

Additionally the machine has 2 hinges, which although I needn't use them (as I have access to the underside of the machine from under the table top), they are cast into the frame of the machine, so had to drill recesses for them also.

I also cut recesses for the latches from the original case, and mounted those into the surface, so that I could use the lid from the case.


By this time I'd managed to find a set of the cast iron treadle legs, but unfortunately without the treadle. Nonetheless, they still made a good stand.


Tuesday 9 August 2022

Multi-tiered triangular planter

I'm pretty sure at some point I said I was done with making planters, but, here we are, here's another.

It's a multi-tiered, 4-segment planter made from pallet wood and arris rails from a dismantled fence.

I've always liked the idea of mixing differing heights in gardens, like with the firepit project, and as we're aiming for a zero(ish) waste approach to the garden, planters are a great means of re-homing soil that is displaced from other projects.

The triangular arris rail is an example of letting the available materials influence the design of the project. In my original sketches I'd planned for a square design, but finding the arris rail led me to using triangles, which actually fits better as the planter is intended to go in a corner.

Likewise, the pallet wood influenced the sizing, as the sizes of the triangle are 120cm, which is a standard footprint for a pallet.

Saturday 18 June 2022

Fallout New Vegas inspired "Sunset Sarsaparilla" lamp

In Fallout New Vegas there is a fictional drink - Sunset Sarsaparilla - and in various locations throughout the game there are these bottle lamps, which served as the inspiration for this project.



I'm not trying to make a perfect replica, but instead just follow the general format of the design.


The base lamp I am re-purposing is a basic  bedside lamp. It has a simple stem that lends itself well to this kind of project


I found a beer bottle which had no embossing or branding on it other than an easily removed label.

To drill the hole in the bottom of the bottle I created a single-use jig to hold the bottle upside down. I filled the curved base of the bottle with water to act as coolant and lubricant, as excess heat can be a big problem when drilling glass. An abrasive drill bit, normally meant for drilling tile, was used, which worked very well.

In it's simplest guise, the project would just be "Drill hole in bottom of bottle, thread lamp through bottle, done."



Although I didn't want to make this project an on-the-nose gaming build, I do have some Sunset Sarsaparilla branded bottle caps, which I wanted to use as the switch. However I don't want the sharp-ish edges of the cap exposed, so I encased it in two-part epoxy resin.

This sat atop a simple toggle push-switch poking through from the bottom of the base.


Starting with the stem of the lamp, I drilled a small hole in its side, to thread the fairy lights through.

Then the connector end of the fairy lights are threaded through that hole, and the lights themselves wound fairly tightly around the stem

A second, plain brass, bottle cap was drilled to fit the stem of the lamp, and threaded onto the lead for the main bulb.

This was then attached to the top of the stem, and the lead threaded through.

This assembly was then put into the bottle. Before pushing the bottle cap down entirely, by pinching the end of the fairy lights and then rotating the stem, the lights could be unwound, so that they expanded into the bottle.

At this point the fairy lights were tested (with just battery power) to ensure no wires were broken or damaged during assembly.




The original lamp runs on regular mains voltage.

However I'd like to reduce it so that I can add some fairy lights in the bottle for some additional lighting.

There exist 12v DC bulbs for the type of fitting this lamp has (E14 SES), which would typically be used in caravans etc. Obviously it's not just a case of switching the bulb over, else the 12v DC bulb will just get destroyed.

So firstly, I'm removing the plug from the lamp, so it's not connected back to direct mains by accident.

I intend to simply use a 12V wall-wart, which the new bulb can be powered directly from.

The fairy lights that I'm using are powered by 2 CR2032 coin cell batteries (6v), so I'll still need to reduce the voltage to power them.

To do this I'm using a LM317 regulator, with 4.7k and 1.5k ohm resistors to create a 5.4v output voltage

I'm also including a small current-limiting diode on the output to the fairy lights for added protection.


The base of the original lamp, aside from a weight, was hollow. I took the base and flattened it into a simple metal disc.  

My router was broken, so had to be
creative with a forstner drill
I took a piece of chestnut wood, and cut a new base from that, hollowing out the enough to recess the original base disc, and house the additional electronics.

 In the top another hole was drilled from the button

The button that the bottle cap will sit on


End Result

Friday 20 May 2022

Laser-line Oche for Dartboard

When I built the dartboard cabinet last year, I put a piece of tape on the floor to act as an oche (throw line).

As they say, there's nothing more permanent than a temporary solution, and a year later, the tape was still there, so now it's time to do something about it.

Years ago, back when I first started posting my projects on social media, one of my first Instagram posts was about a (now long abandoned) project to create a 3D scanner:


In this process, a regular laser diode - like one from a laser pointer - is aimed through a transparent cylindrical object. This acts like a prism, refracting the light, creating a line.

The same principle I used back then, is what I'm using this time around. Although this time I'm using a piece of acrylic rod rather than being cheap and trying to use a stem from a broken wine glass...

The Diode

The laser diode that I'm using comes from an old Nintendo Wii lightgun accessory, and was the one I started using in the laser scanner project.

With all the plastic shroud removed, this is what is we're left with


 The Casing

I initially went down the rabbit hole of making a 3D printed case, but in a moment of inspiration, realised that a short section of copper pipe would be perfect.

The pipe is about 1.5 inches long, and we're using two end caps.

One simply has a small hole drilled for the wires to come out of the back

A plastic washer was used to create a mount for the laser diode in the pipe.

The second pipe end cap is used to create the lens assembly.







The lens assembly

A hole was drilled into the end cap, bevelled at the outside for a nicer finish. The hole should be no wider than the diameter of the acrylic rod.

A small piece of transparent acrylic rod was cut, and sanded to make a friction fit in the end cap perpendicular to the hole that was drilled.

You can see how the rod bends the light, making the drilled hole look square.

This lens assembly can be push fit over the end of the rod.


The wiring

The diode was powered by 2 AAA batteries, so I found a 3.7V phone charger as the closest contender for a power source. However, it's not just a case of connecting the diode to the charger.

It's important that laser diodes are driven correctly as current fluctuations can easily damage them. In some cheap laser pointers, control of the current is sometimes limited by the specification of the batteries that are used.

I was expecting this to be the case with this one, but after some probing, I determined that I was lucky, this laser contained some control circuitry (behind the yellow shrink-wrap in the diode picture).

So the only extra circuitry I had to add was a resistor to drop the voltage closer to the 3v that a battery would provide, and adjusted the resistance of the battery so that the current was also similar.

For safety I did this by starting with a high value, which provided virtually no light output on the diode, then reduced it until the brightness was suitable.


The mount

The mount is 3D printed (Source), and attaches to the top of the bottom compartment of the Dartboard Cabinet. The body of the laser is attached with a copper pipe clip, and is simply a case of holding the laser so the line is drawn the required distance away, and then the bolt tightened.

This can take a bit of trial and error, as the tightening of the bolt can unintentionally move the line.




The finished oche


Wednesday 20 April 2022

Motion activated and timed staircase lights

Years ago, when I first started with electronics one of the first projects I did was to create some motion-activated lighting on the staircase.

It was a basic setup with stick-on LED lights, activated by a pressure pad under the carpet on the top and bottom step. This is a re-make and update of that project in my new home.


The lights

I recovered 6 under-counter lights from a kitchen renovation.

The fittings are for G4 bulbs, run off 12V AC, and have a nice chromed finish.

The bulbs were originally halogen, but I swapped them out for LEDs to reduce the power requirements.

As the lights are designed for AC voltage, they can also be driven by a DC supply to simplify the circuitry and make it easier for them to be micro-controlled, so in effect they will be little different to regular LEDs.

The staircase doubles back on itself, so the idea is to mount the lights in the middle partition, and then run the wiring to the control in the under-stairs cupboard. 

Because of the number of steps on the staircase, there will be one light every two steps starting at the second step.

This will put two lights on the bottom half of the stairs, one light on the middle landing, and then 3 on the larger upper half of the stands (as there are more steps on that half).

Routing the cabling

The main difficulty will be in routing the cable for the lights on the upper part of the staircase as it will be difficult to recess the lights without the cable needing to be threaded all the way through. Rather than run the cable all the way through, then have to recess it I opted for a method using the drill as illustrated in the graphic below - this minimizes the amount of material that was removed from the sides and reduces the amount of patching and filler that is required. 

The sensors 

To modernize the switching system, I am implementing a sensor system at the top and bottom of the staircase. I originally intended to use passive infra-red (PIR) sensors, however I don’t want the lights to be triggered just walking past the staircase, and these can be tricky to focus on a precise area.

Instead I’ve opted for ultrasonic distance sensors - not just like the ones used as car parking sensors, but literally those.

These systems typically contain four sensors, a control box, and a small LED display module.

There are several others who've made efforts to interpret the pulsed signal from the control box. I initially tried to follow a similar approach with mine, however was unable to get the example code working - it seems perhaps the sensors I have were either using a different PWM speed or encoding system.

As I do not care too much about measuring the exact difference, and am treating them more like a 'beam-break' sensor, I can take a rougher approach to detecting motion.

After some prodding with an oscilloscope I found a couple of pins that showed a square waveform that appeared to react suitably to me waving my hand in front of the sensors.

I put together a simple arduino sketch to read the rising and falling edge of those waveforms, and simply counted the transitions.

This is a rather effective, but admittedly hacky, solution - basically just observe the range that the transitions are when there's no obstruction in front of the sensor, what the value is when the sensor detects something, and then simply if/else on the value to detect if the sensor has been triggered.

Lighting Pattern and Timing

The lights will be patterned to switch one at a time, starting at either the bottom or top of the stairs (depending on which sensor is triggered), remain on for approximately 10 seconds, and then switch off in the same order. 

The Circuit

The Code

As usual, the code is available on GitHub.