Saturday, December 22, 2018

More 3D Printed Christmas Tree Decorations

Made a few more Nintendo-themed 3D printed Christmas decorations, to add to my existing ones. These are a bunch of power-ups form Super Mario Bros. 3 on the NES. Using a python script to read in an image file and convert into ASCII code for OpenSCAD, then importing this into an OpenSCAD file to generate the stl files for each of the five colour layers, each printed separately and then "clicked-in" by hand to finish.

You can download the stl files to print here: Mario Power-up Christmas Tree Decorations (thingiverse)

Merry Christmas!

Sunday, November 18, 2018

PyWeek 26: Storm Drain Odyssey

"Storm Drain Odyssey" was a team entry by Team Universe Factory (for which I was part of) for PyWeek 26 (October 2018), a twice yearly video game development competition that gets competitors to build a complete game from scratch in seven days using the python programming language. This year's theme was "Flow" and we created a 3D dungeon exploration/puzzle game where you control a pet goldfish navigating your way out of a sewer labyrinth.

I'd been itching to be part of a team entry (I've done the last three comps solo), so I was stoked when I was able to join Universe Factory (definitely one of the most competitive teams in PyWeek, with several existing titles :) ) ... the team was very welcoming to new-comers. I focussed on graphics, 3D modelling and graphical programming (with a bit of sound-design) and it was a good experience working in a team but not leading or being responsible for major game mechanics: Cosmologicon, our team lead, ran a very tight ship and was very organised, so everyone seemed to be on the same page. I learnt a ton of practical experience in version control and managing working on software in a team (which I don't do much), so that was cool too. I also learnt how to use scripting with OpenSCAD to quickly turn around 3D environment models (which I documented in a game page blog here), a technique that I think I would definitely try to use again.

The game ended up coming second in the team division, which we were fairly happy with. There's a source and Windows standalone version that can be downloaded from the game page here:

"Storm Drain Odyssey" on

Saturday, November 3, 2018

Record Clock

It was my wife's birthday coming up soon, and I knew she wanted to get a new clock for our living room, so in the do-it-yourself spirit, I decided to make her one. I'd seen a couple of previous projects where clocks had been build around an old LP vinyl record, and wanted to try the same idea myself, and see if I could do it on Carvey (3D carving machine).

I picked up a $7 clock from Kmart and pulled off the case to retrieve the clock mechanism inside. I bought a second hand 7'' single vinyl record ("Total Eclipse of the Heart" by Bonnie Tyler, quite randomly :) ) which I would use to carve on my clock face using Carvey. I ended up going with a 7'' as I couldn't fit a 12'' inside Carvey. I knocked up a quick design in Easel by just using a standard font and a few icons for fun arranged around a 7'' circle. To do the setup in Carvey, I used a bit of MDF waste board and an additional 1-by-1'' piece of 2mm scrap wood to raise the height of Carvey's smart sensor to a little bit above the 1mm thickness of the record: because the record is a circle, you can't get it under the clamp while also being able to carve on all sides. I carved with a 1/16'' up-cut bit (the only 1/16'' bit available), and set the material type to "acrylic" (seemed the closest match). This worked pretty well, however the vinyl is pretty soft and so there was a pretty sizeable bur of vinyl that was stuck around the bit for most of the process: this ended up "buffing" around the edge of each number cutout, but didn't really have too much of a negative impact on the final result.

Once the clock face was carved, I glued on the clock mechanism to the back, placed the clock hands back on and pasted on a family pic to the record label area: if I'd found a second hand single of a song my wife really liked, I might have just kept the label as-is.

Final result looks pretty cool, and not bad for a $9 present :) (I might be a bit of a cheap skate sometimes, but in this case I did get her a few other things too!)

Friday, August 31, 2018

"Ret-Row": a 5th Kajam entry

"Ret-row" is my entry for the 5th Kajam, a month-long event in which people make a video game from scratch, focusing each time on a specific aspect of game making, as chosen by its host. This Kajam's theme was "Retro", so a made a little retro style shoot-em-up where you control a row-boat. I started off pottering with some pixel art and music, not thinking I would actually submit anything, but found that the game started to take shape after a week or two, so decided to see it through to completion.


I did all of the game's pixel art on my phone in spare pockets of time using the app "8bit Painter". The music was done in Musescore using a set of NES instruments, to give a bit of an old-school flavour. The game is programmed in Python and uses Pygame.




Mac OSX 10.7+:


Source code distribution (compatible with Windows/Mac OSX/Linux, requires python and pygame):

Tuesday, July 10, 2018

Pentasynth: A homebuilt pentatonic keyboard and synth (part 2)

This is part two (see part one) of a post on a custom-built Arduino-based synthesizer and keyboard called “Pentasynth”. Pentasynth uses a keyboard based on a five note pentatonic scale, so it’s easy to play for people with limited background in music (such as young kids) and encourages experimentation and improvisation. Pentasynth creates a user-selectable accompaniment including different drum patterns, bass lines and chord progressions and allows the user to play a pentatonic melody line over the top. Under the hood, Pentasynth runs on an Adafruit Metro Mini (using the same ATmega328 microcontroller as the Arduino Uno) and generates three channel audio (two square-wave tones and one pseudo-random noise drum beat), which is passed through and onboard amplifier and speaker, while simultaneously passing all outputs as MIDI messages via the USB for either a lo-fi or hi-fi audio experience. Pentasynth has controls for volume, tempo and selection of different accompaniment patterns. The keys and case components are 3D printed, with the main case panelling carved from clear acrylic using Carvey. Custom PCBs containing switches for detection of key presses were also carved on Carvey.

In the previous post, I discussed the hardware development of the keyboard including 3D printed keys and CNCed case and key switch PCBs, and the use of a wavetable synth for audio. I wasn't that happy with the audio quality from the wavetable synth, so I re-wrote my own system using hardware PWM square-waves for audio, with a bit of re-jigging to add MIDI output. I'll also discuss the electronics in a bit more details and the code running on the Arduino.

The ATmega328 has three hardware timers that can each be used to drive interrupt routines or run a hardware Pulse Width Modulation (PWM) signal. Since I wanted to keep the main program on the microcontroller free to managing key and control inputs and running an accompaniment system, the hardware timers were the only way to generate audio signals. By default, two of these timers (Timer 1 and 2) are unused, and the other (Timer 0) is set to run at 1kHz and controls functions such as millis() and delay(): any change in this frequency would mess with these. I've setup Timer 2 to run a square-wave output based on the note pressed on the keyboard and Timer 1 to run a square-wave from an accompaniment baseline. In order to get a pseudo random noise signal for a drum beat, I've piggy-backed an interrupt routine on the existing 1kHz to generate a pseudo random square-wave (i.e. randomly ordered series of LOW/HIGH) using a Galois linear feedback shift register (see this nifty little post). The random signal switched at 1kHz sounds a bit like a snare or open high-hat, so makes for a decent (lo-fi) beat.

I ended up re-jigging the electronics to account for the changes in signal generation (I'm glad now I had left everything breadboarded on the final keyboard :) ). The three audio channels are generated as separate square-waves on three digital output lines (pins 9 and 11 on the metro mini, corresponding to the hardware PWM outputs) and pin 13 for the drum beat. The separate signals are then all connected together via 220 Ohm resistors to a potentiometer pin used for volume control. This output is then fed through a single NPN transistor, which is also connected the the 5V output, acting as an amplifier which is then connected to a 3W, 4 Ohm speaker. The ten keys and four control buttons are connected to the remaining digital input pins, and a second potentiometer connected to an analog input pin which is used as tempo control for the accompaniment.

In terms of code, the microcontroller polls the switches corresponding to each key and send the appropriate tone via both the audio output (hardware PWM) and a MIDI message. The code also implements an accompaniment system. This consists of a drum beat, base line pattern and four-step chord progression that runs along at the user selected tempo. The control button for each of the drums/bass/chord is used to cycle through the available patterns: the player can therefore experiment and choose a combination of drums, bass pattern and chord progression that they like and then improvise a melody over the top of this using the keys. A fourth control panel button is used to switch between different pentatonic modes (at this stage either a major or minor pentatonic scale).

The video shows the keyboard in action. My five year old son has been having fun playing around on it: I think he mostly likes that he can ramp the tempo up to crazy speed and mash the chord progression button to create havoc :).

Arduino code for Pentasynth can be found at:

The 3D models of printed parts and carvey SVG design files can be found here:

Edit (October 2018): Pentasynth also made it to the semi-finals of the 2018 Hackaday Prize, for which I won $1000! Pretty chuffed :) see:

Sunday, June 24, 2018

Pentasynth: A homebuilt pentatonic keyboard and synth (part 1)

I’ve been working on another music project: it’s a custom-built Arduino-based synthesizer and keyboard called “Pentasynth”. Pentasynth uses a keyboard based on a five note pentatonic scale, so it’s easy to play for people with limited background in music (such as young kids) and encourages experimentation and improvisation. Pentasynth creates a user-selectable accompaniment including different drum patterns, bass lines and chord progressions and allows the user to play a pentatonic melody line over the top. Under the hood, the audio generation is performed using a four channel, 10kHz playback of wavetables (sine, pulse, sawtooth, triangle and random noise) using a micro-controller generated PWM that is then passed through a low-pass filter and into a small amplifier and speaker. The microcontroller is programmed in Arduino, with code based on “The Synth”, a wavetable synth library by DZL/Illustron. Pentasynth has controls for volume, tempo and selection of different accompaniment patterns. The keys and case components are 3D printed, with the main case panelling carved from clear acrylic using Carvey. Custom PCBs containing switches for detection of key presses were also carved on Carvey.

My local makerspace (Thinkspace) got in some carvable PCB blanks for Carvey last year, and I had been thinking about trying them out. A while ago, I had picked up a broken kids toy electric guitar from the side of the road (I like picking up random electronics junk I find :) ). I ripped it apart just out of curiosity to see how it worked. The guitar was controlled by little buttons: the buttons were basically bits of plastic that held a little piece of clear rubber with a little bit of conductive material in it. When the button is pressed, it would push the conductive material across a PCB with a criss-cross of conductive tracks that close a switch, that is then detected by a little microcontroller to produce a sound:

I salvaged out the little clear rubber bits and decided to try and carve my own PCB “criss-crosses” for the keys on my own keyboard. The advantage of designing it this way, instead of using some off-the-shelf buttons (the usual “clicky” kind) is that the keys then have a nice, soft tactile feel to them and don’t make a horrible “clicky” sound, that interferes with the music (I had regretted using clicky switches in a previous handheld video game project I made).

For carving the PCBs, I used these 2-by-3 inch PCB blanks and designed the circuit as an SVG with paths to cut out the ground and positive voltage paths for each of the ten switches (ten keyboard keys). I had to split the pads across three separate PCBs. I used a V-shaped milling bit (20 degrees) to mill the cuts into the PCB at a cutting depth of approximately 0.2mm. I found that in practice the height wasn't super accurate on Carvey, so had to experiment with different height each and every time I setup a new board to mill. Once the tracks were milled, I used a 1/16in to drill holes for screws and through holes for soldering connections to the PCB pads, and a 1/8in flat milling bit to cut out the final board.

I 3D printed banks of keys in different colours: I designed the “neck” of each key to be a 1mm height layer which produced the flex that allowed the key to swivel when pressed (printed in PLA). The keys were coloured in lots of three and two per octave, to give the feeling of the black keys on a normal piano (which also follow a major pentatonic scale). Originally I intended to design the entire case as a single 3D print, but found it was going to be fairly big (and hence take forever to print), so I ended up changing the design. I created one big baseplate out of clear acrylic (which I carved on carvey, with drill holes) and connected everything to this with screws and a screwdriver. I 3D printed an array of standoffs and other knick knacks to hold the assembly together. I also carved from clear acrylic a top panel which held two dials (one for volume, one for accompaniment tempo) and four control buttons for the accompaniment. This panel also had the small speaker mounted to it.

For the electronics, I used a Adafruit Metro Mini 328 (running at 5V/16MHz), an Arduino compatible board that uses the same ATmega328 chip as the Ardunio Uno. Each of the ten keys is connected to separate digital-in pins, and the remaining GPIO pins are connected to buttons and pots for the controls. The digital PWM output from the micro is then connected to an RC/low-pass filter (to create the waveforms from the PWM pulses) and the output sent to a 4-ohm, 3W speaker after amplification. Originally I had a small D-class audio amplifier I had left over from another project, but I accidentally broke it while desoldering an existing header off it, and so had to put together a simple, single stage transistor amp (which is very soft, and a temporary fix until I get another amp).

Instead of hard-soldering everything into the arduino, I got a bit lazy and decided to glue a small breadboard in and connect everything up via the breadboard. The advantage with this is that I can plug and swap-in a different microcontroller/synths/amplifiers in the future (which I am intending to do).

I'm pretty happy with the look and feel of the keyboard (it's a bit raw looking, but kind of cool), but not super happy with the sound at the moment: I need to get a proper amp for a bit of amplification, and I've found that the audio from the arduino synth library I'm using is not super nice sounding (it sounds a bit like a bad/cheap kids toy piano at the moment). I'm going to do some brainstorming for updating the audio, hence a probable part two post on the project: stay tuned!

The 3D models of printed parts and carvey SVG design files can be found here:

Wednesday, May 23, 2018

Ships and Dynamites: A father and son made video game

My son is five years old now, and as he has got older I have begun to share my love of video games with him. He has taken a keen interest in my last two or three PyWeek entries, as so after the last comp he asked if he could help me make a video game. I told him "sure! why don't you design the game and make the graphics and sound, and I can do the programming". I asked him what the game should be about, what does the player do? He told me "You jump out of a big spaceship and jump over lots of dynamite and then get in another spaceship and shoot all the dynamite with your lasers". Sounded good so far. I asked him to draw me a picture of what the game looked like. He drew this:

I then got him to draw a few additional assets on paper: a dynamite box exploding, the word "level", the numbers 0-9 and a titlescreen for the game. I asked him "what about the player's character before they get into the ship? what do they look like?" He drew me this:

I took all of the pictures he drew, scanned them and then chopped them all up in Gimp. I wrote a quick bit of prototype code in python and pygame with the player running around in the game world, with the big ship in the background, little ships that you can jump in and shoot with, and dynamite blocks. My son gave some feedback on how the levels should be structured and gave the nod of approval.

Next I told him "we are going to need some sound effects ... what sort of sounds do you want in the game?". He made the sounds for the lasers, dynamite explosions and a little jingle for when the player dies. We recorded him making the sounds on my laptop's built-in microphone, and I used Audacity to crop the sounds and perform a bit of basic normalisation and noise filtering, before loading them into the game. "What about music?" I asked. He told me "the music has to go like this: da da da daaa da, da da da daaaa da! ...", so I recorded a snippet and set about making a quick orchestral arrangement around the tune he had hummed in Musescore.

Finally I asked him "So, what are you going to call our game?". He told me "It's called 'Ships and Dynamites' ...". "Shouldn't that be 'Ships and Dynamite'?" I asked. "No, dad ... it's Dynamites" he insisted. "OK fair enough ... Dynamites it is".

This is a brief playthrough of our final game:

It was really fun to do this together, we both had a great time. He has had fun showing his game to friends and cousins, and everyone we have shown so far seems to like the game, and I think he's learnt a bit about logically what has to go into a game, how to get something like this to work etc. If interested, you can download the game here: (1.2Mb)
Source distribution: requires python and pygame