An Atari 2600 in a Cartridge

You know when you’re having that long-overdue clean-out and you find a few things stashed away you’d forgotten about? From when you said “that’ll make a great project one day” then tossed it in your equivalent of the bargain bin? Just happened to me.

A few years ago, I got a great Atari 2600 VCS job lot. Two consoles (a light-sixer and a Vader – now both composite modded) and a stack of games. Out of all the games only one appeared to be beyond repair. That cartridge, Activision’s F-14 Tomcat, was duly placed in the bits and bobs box until a project came to light for it.

Almost simultaneously, I came across the cart and a couple of 9-pin sub-D joystick ports. The brain, it ticked. And tocked. And finally came up with a Raspberry Pi Zero. Of course, an Atari 2600 in a cartridge! Why not? Why? Who cares.

Before I did anything else, I prototyped the build on a Raspberry Pi 2 and a breadboard. My requirements were:

  • Inputs for two joysticks
  • A power button
  • A method for shutting the Pi down cleanly
  • The TV colour switch
  • The difficulty switches for both players
  • Select and reset
  • Some method of access to the console

Thankfully, the newer Pis have enough GPIO inputs to handle all this.

The Atari emulation itself is very straightforward. I decided to use the excellent RetroPie operating system as it handles all the game selection menus for you. I would then use Stella for the actual emulation of the Atari 2600.

The trick now was how to couple-up the joysticks and buttons to the emulator. The easiest approach is to trigger keypresses and map the emulator to them. After some research and a few false-starts, I settled on Adafruit’s Retrogame package, which did exactly what I needed. With a simple config file, I could map changes on the GPIO pins to keypresses. It worked perfectly. Soon I had a breadboard mockup where I was controlling the games by shorting the pins to ground.


Another problem with keys was to be able to shutdown the Pi cleanly. I ended up writing a short Python script using the python-uinput package. This does a similar job to Retrogame but I was able to configure things so if the power button was pressed once it would quit the current game (and return to the selection menu) but if held for three seconds, it would trigger a system shutdown. Implementing this script also gave me the chance to add an LED to the front so I could see when the system had finished shutting down (I also really like LEDs).

The last part was adding a barrel connector hooked up to the UART pins so should I ever need to, I can get console access without having to take everything apart. I tend to do this just out of habit with build like this and have a ready-made USB-to-UART lead with a 3.5” stereo jack on the end.

To work!

First off, lets get that cartridge cleanup, open and remove all that complex circuitry. Oh.

Next, get rid of all the interior posts and bits with a pair of pilers and some deft craft-knife work to get it as smooth as possible. Didn’t need to be perfect.
I wanted to not only have the joystick ports (which, let’s be honest, are kinda important) but also all the switches that the original Atari VCS has. So, I measured up the front area and made up a template to make sure everything would fit.
With the template in place and looking good, next up was to cut the holes. I only had one shot at this, so time was taken. The holes for the switches were done with a low-speed drill and the larger joystick holes with a rotary tool.
A little scraping later, and the ports fit nicely.
Now to get a bit more artistic. The Atari cart font was easy enough to track down (it’s called MumboSSK) and I made a little mock-up of a cart with labels for all the controls. The graphics were, ahem, borrowed from the cover of ‘Art of Atari’. I suggest you buy it as it’ll make me feel better.

Apologies for the wobble-vision

Time to get the soldering iron out. Thankfully the Pi Zero (I’m using the original, not the W) has enough GPIO pins to cover all my requirements. I needed five controls per player (up, down, left, right, fire) and a further six for my control buttons. Luckily the Zero could accommodate this without needing to resort to any kind of space-destroying input extender.
With everything tested, time to fix things in place. Superglue did the trick nicely for the ports, but the Pi is mounted with (non-conductive!) sticky foam pads.
Time to very carefully fold things up.
I’m not quite prepared to get the glue out yet, so an elastic band is helping hold the cart together in the meantime.
I mapped the Emulationstation (RetroPie’s UI) controls to the same as the left joystick so you can select your game. Once in a game, a tap on the power button will drop you back to the main menu.

So there you go. Hours of fun on Combat ahead. Think I’ll skip E.T. though. The Pi Zero has enough grunt to run Stella very well indeed, although it finds Emulationstation a bit of a struggle (but not bad enough to be unusable).

I’ll be bringing this little gizmo to the Milton Keynes Raspberry Jam on the 15th July 2017. Hopefully I’ll see you there!


Building The ZX Raspberry – Part Four

In which our hero is unable to leave well alone

A little epilogue to the ZX Raspberry project. I came into possession of a very dead ZX Spectrum+ and, following my own personal rule of ‘it gets fixed or it gets modded’, I decided that it was time for a ZX Raspberry+. This project did away with the USB keyboard option, so just a standalone Raspberry Pi-driven unit.

ZX Raspberry+ Innards

ZX Raspberry+ Innards

I made a few improvements and discoveries along the way.

  1. It’s a lot easier to put all this gubbins in a Plus case rather than an original.
  2. The Raspberry PI + variant (+ or 2) is conveniently sized to place the HDMI and power alongside the expansion port (less cables!).
  3. The +’s reset switch makes a handy keyboard mode switch.
  4. A conclusion I reached during the first project was right, I didn’t need the resistors on KB1. Leave them and the power line out, wire the connector directly to the Pro Micro and just set the inputs to INPUT_PULLUP in the Arduino sketch. It does everything for you.

Finally, I was able to really speed up boot time by using PipaOS instead of the standard Rasbian distribution. It’s still Raspbian, but optimised for fast bootup and without a lot of the stuff you don’t need anyway. The results on a Raspberry PI 2 with a Class 10 SD card are quite something. Here’s a boot video:

Just a shade over 10 seconds. Not bad eh?


Building The ZX Raspberry – Part One

In which our hero plans and schemes

Despite wanting to convert a ZX Spectrum into a USB keyboard for some time, I held off to wait for the unlikely duo of the ZX Spectrum Vega and the Recreated ZX Spectrum. Sadly, neither buttered my parsnips, and the reasons why have been discussed at length around this Internet of ours, so I shall say no more here. What I really wanted a combination of the two: The stand-alone operation of the Vega and the keyboard of the ‘Recreated’.

Not being one to re-invent the wheel, I’d been reading over this Instructable wot I found and occasionally drooling over the excellent kits offered by Tynemouth Software. Then, a battered old Speccy case and the parts needed for a USB interface found their way onto a Facebook group for just £20, their current owner being caught between retro-project-awesomeness and ‘having a life’ and ‘friends’. Clearly making the wrong choice, he put them up for sale. … 


Enigma-E + Raspberry Pi = Enigma Pi

This is a follow-on from my previous post on building the Enigma-E (an electronic version of the Naval Enigma)

Huh. Turns out the Enigma-E can send its stream of cyphertext via a very simple RS232 port on the PCB. Now, what small little device could have fun with that I wonder?

Here’s the idea: Add a Raspberry Pi inside the case of the Enigma-E and create the world’s first Internet-enabled Enigma machine.

So, here’s what we’re starting with; an Enigma-E fully constructed and tested. The cable connected at the front is the current RS232 link.

I needed to get the Raspberry Pi talking to the Enigma-E over RS232. I decided to use an off-the-shelf USB-to-serial adaptor to do this for reasons that will become apparent. Thankfully, Maplin’s stock-item uses a well-supported chipset (PL2303) which the Pi is more than happy with. Plugged it in and there was the new device in /dev. A quick test in the command-line proved the Pi could happily talk to the Enigma-E.

Next, how to get the Raspberry Pi talking to the outside world? I wanted it to be as wireless as possible. Fortunately, Maplin saved the day again with the Edimax N150 Nano USB Wi-Fi adaptor. It’s tiny and supported by the Pi after a firmware update. Instructions on getting all this going are easily found on that Internet thing. A bit of fiddling around and I had a good reliable wifi connection running.

If the Raspberry Pi is going to be inside the Enigma-E’s box, how am I  going to talk to it if can’t get a wifi connection? There’s not a lot of space inside the box and on the front board, so I was reluctant to start making holes for HDMI and USB. Using a little circuit I had previously built, I had a solution. On the first build I had wired up the E’s RS232 terminals to a 3.5″ socket in the front plugboard. This was removed and in place went a hook-up to a logic-level conversion circuit that allows an additional RS232 connection to the low-voltage UART connection on the Raspberry Pi’s GPIO. I’ve covered how to build this circuit in a previous post. RS232 on a Raspberry Pi

Final challenge: Power. The Raspberry Pi needs a nice stable 5V but the Enigma-E needs a minimum 6V. Luckily, it’s also happy with 12V. So, get a cheap (but reputable) car USB power adaptor and gut it. Some drastic shortening of the cables later and we have a tiny 12V-5V convertor on board. I wired this up to the external power input for the Enigma, added a 12V supply and bingo, both devices happily powered up.

A final bit of securing of all the bits into the box, some very careful assembly (and an improved lampboard cover) and I’m done.

Oh, one more thing, we need some logos in a cheap-printed-WWII-style.

Now onto software. A simple PHP script monitors the Pi -> Enigma serial port. Anything coming in is then broadcast as a HTTP request to my server, which receives the request and stores it. When demonstrating the Enigma Pi, a page on the main web site retrieves the store and displays the cyphertext coming in live with some morse audio for good measure.

Thing is, in true software developer yak-shaving fashion, I wanted the person seeing the signal coming in to be able to decrypt it on the web site. I found a couple of Enigma M4 simulators but none were quite up to the mark. So, obviously, I had to build my own. 🙂

It’s taken a few weeks, but it’s done. A fully-functional Enigma M4 written entirely in JavaScript that can be used to send and receive encrypted messages to the Enigma-E.

Well, I’ve come this far, may as well go the whole hog. See, there’s only one Enigma-E, and that’s no fun if you don’t have it with you to play with. As I had developed the site this far, I decided to add the ability to send and receive messages using only the virtual Enigmas and email. I figured this may be useful is demonstrating how Enigma works, especially to younger visitors to Bletchley Park. The result is – The Virtual Enigma.

The site requires a modern browser (support for HTML5) so IE9 or above as well as recent builds of Firefox, Safari and Chrome all work nicely. Do try it out and let me know what you think.

The worst bit? This project has given me another idea. Maybe next year. :S

Send and receive Enigma messages at



RS232 on the Raspberry Pi (to a Psion 5)

The Raspberry Pi’s General-Purpose Input/Output (GPIO) connector consists of 26 pins that are a hacker’s delight, allowing for some serious analogue and digital tomfoolery. When drooling over the specs, one thing that surprised me was the inclusion of a basic serial port. This was a lower-powered version of our old 20th century friend, RS232. For those of you who have no idea what I’m talking about, don’t panic, although this post may not be for you. RS232 would seem to many to be redundant old-school tech but in reality it’s still all around you as it is still probably the simplest way you can get two computers chatting digitally.

As a bonus, the bright folks of Pi have configured their stock Raspbian OS to use the serial port as a console. That is, you can use it to log in and get a command line prompt. My day job involves a number of servers at a data centre. Despite being the latest and greatest kit, each one has an RS232 port configured like this. In the event of serious problem where not even the graphics card is working correctly, you may still be able to get into the system using this interface.

The serial interface provided on the Pi is about as simple as you can make it. Only four lines are used; power, transmit, receive and ground. Couldn’t be easier, just wire this to to a COM port on a PC and get talking. Right?

Err, no. There’s a problem: The Pi runs at a meagre 3.3V. RS232 requires +12V for the high (or ‘1’) signal and -12V for low (or ‘0’). My friend the Pi can’t do that out of the box, but a bit of Googling revealed some enterprising types who had constructed a solution. Luckily, there’s a readily-available chip that can convert the signals in both directions, allowing us to create a ‘real’ RS232 interface from the Pi’s low-voltage version. This gizmo costs about £5, is readily available and has the catchy title of the MAX3232CPE. All it needs is a few capacitors to help it along at you’re good to go.

Time to get to work. I got everything from my local Maplin (links and order codes provided).

Also handy:

  • Some soldering experience (unless breadboarding)
  • A COM/Serial Port

I had a problem with the last item there. As a Mac user, I knew that Steve Jobs had banished the RS232 port to the parts bin many years ago in favour of the over-complicated-but-a-bit-more-useful USB interface. Fortunately, Maplin sell a USB to serial adaptor based on the PL2303 chipset that works great on recent OS X flavours, including Mountain Lion – although I had to dig around for some drivers and instructions. (PL2303 drivers for Mac)

To Work. Here’s what we’re going to create: (a more technical version from speakjava)


Click to embiggen. The red dots represent a cut through the tracks.

First of all I built this up on a breadboard, following Joonas Pihlajamaa’s instructions (link at foot of page). If you’re new to mounting ICs on a breadboard, note that you’ll need to carefully bend the slightly splayed pins in to fit. Don’t use the socket at this point. Next up, I soldered up the 9-pin connector. From the reverse/solder-side I connected RXD to Pin 2, TXD to Pin 3 and Ground to Pin 5 (top-right).

Breadboard Version

Now with your Pi switched OFF, connect the four lines for the Pi from the circuit to pins 1, 6, 8 and 10. Pin 1 is the top-left pin marked ‘P1’ on the board. The pin on it’s right is Pin 2, then the pin below P1 is Pin 3, on it’s right Pin 4 and so on.

The four lines you are connecting are:

  • Pin 1 – +3.3V
  • Pin 6 – Ground
  • Pin 8 – TXD (Transmit data)
  • Pin 10 – RXD (Receive data)

With the 9-pin RS232 connector hooked up to your COM port, switch your Pi on.

Your Pi should start up normally and seem blissfully unaware of it’s new connection. Now turn your attention to your computer.

You need some software to establish a connection to your Pi. On Windows, hunt down PuTTY, a tool built just for this purpose. On Mac, try out MacWise (£) or, and this applies to Linux as well, go with screen, the command-line utility.

If you’re going with screen, see if it is installed:

$ screen -h

Not found? Then…

$ apt-get install screen
$ screen /dev/ttyUSB0 115200

Or if you’re on a Mac and have MacPorts installed:

$ port install screen
$ screen /dev/tty.usbserial 115200

NB: The /dev/ device many vary depending on OS and drivers etc. Have a look around your /dev/ directory if the above doesn’t work. You’re generally trying to locate something mentioning ‘tty’ and ‘usb’.

The screen should go blank and a tap on the enter key will show a login prompt to the Pi. Congratulations.

If you’re using a more advanced package, note that RS232 requires configuration before it will work. The Pi’s settings are 115,200bps (bits-per-second), 8 data-bits, no parity bit and 1 stop-bit. This is typically written as 115200 8N1 and you should match your settings to this. Once configured, open or connect (depending on how your software terms it) and press the Enter key. All being well, a Raspberry Pi login prompt should greet you.

Not working? Nine out of ten times this is down to the RXD and TXD lines being the wrong way around on the PC side. After disconnecting and switching your Pi off, try swapping the lines around on the breadboard and giving it another go. If that doesn’t do the trick, re-check your settings in your terminal emulator.

I decided to bring this to it’s logical conclusion (in my mind) by hooking up the Pi to a perfect screen and keyboard combination; the Psion 5. However, it didn’t work at first as both the Psion and the Pi expect to be the ‘client’ talking to the computer. I needed to add a crossover cable, which crosses over RXD and TXD, to get it working. But work it did!

Once happy with the breadboard, it was easy enough to transfer the circuit over to veroboard and create something a little more permanent.

You may be wondering what the point of all this is, but the fact is that many, many devices out there still use RS232 for communication. You can find RS232 ports on projectors, set-top boxes, even cars. Heck, my old washing machine had one (a Dyson Contra-rotator). So, having a fully-working RS232 interface on something as versatile as the Pi might be fun. A bit of Googling will also reveal how you can change the operation of the port from a console login to, well, whatever you want. What am I going to use it for? Well, that’s another post.

Sources for this article:
Joonas Pihlajamaa



Colossus on a Raspberry Pi

One of only nine known photographs of Colossus

Like many oldies who ordered a Raspberry Pi, I was more taken that such a thing now existed rather than having any kind of specific plans for it. Never mind, I thought, something will come along. Sure enough it did. A little background first.

In 2007, Tony Sale and the volunteers at The National Museum of Computing at Bletchley Park had completed their magnum opus: The rebuild of Colossus. This saw a major milestone after many years of works by the team as they toiled to recreate the world’s first programmable computer in as authentic a fashion as possible.

Colossus was the ultimate expression of necessity being the mother of invention. In 1941, Bletchley Park was struggling with deciphering the German ‘Fish’ codes. These were high-command transmissions using an unknown enciphering system seemingly much more complex than Enigma. A breakthrough by John Tiltman, helped along unwittingly by some German radio engineers, had given the codebreakers vital clues into how the system worked. After three months obsessive work on the problem, Bill Tutte correctly ascertained how the traffic was being encrypted. They were now able to build an analogue of the deduced twelve-rotor system and had a solid method to crack the messages. The problem was the process took six to eight weeks per message.

The race was on to build machines that could speed up this process. After a few false starts, Tommy Flowers, who was working for the General Post Office’s research department at Dollis Hill, constructed a monster that could cut though the lion’s share of codebreaking work in just a few hours. This machine, Colossus, had such an impact on Bletchley Park’s abilities to read ‘Fish’ traffic that a total of ten were built towards the end of WWII. It wasn’t until after the war that the German secret machine was revealed, the Lorenz SZ40 & SZ42 ‘secret writers’.

So, back to 2007. A rebuilt Colossus partakes in the ‘Great Cypher Challenge’. A Lorenz cypher machine was taken to the Heinz Nixdorf museum in Paderborn, Germany. Over the course of a day, messages were enciphered using the device and transmitted over teleprinter code (‘non-morse’) just as they were in WWII. In Bletchley, modern-day ‘Y’ station operators listened in on old radio sets trying to record the signal. At about 3pm, a clear message was received and Colossus was set to work. A few hours later, and with a little help from it’s modern-day codebreakers, all twelve rotors settings for Lorenz had been found and the message decrypted. Champagne everywhere.


In Bonn, a young cryptology enthusiast by the name of Joachim Schueth was also listening (fair enough, the competition was open to anyone). He had written some software that would not only act as an analogue for Colossus’ work (identifying the first five rotor settings) but would in fact handle the entire process from interception to revealing the plaintext message. He intercepted the message first time and had an answer 46 seconds later.

Jo has been kind enough to allow others to download his code, along with recordings of all three messages he intercepted, along with generous instructions on how to proceed. So, there was my first Raspberry Pi challenge, could it become a modern-day Colossus? It seemed appropriate after all, to see this little wonder of 2012 pit itself against it’s Granddad.

After a few tweaks I was able to get the whole process up and running on Eben and David’s little baby. Yes, the Raspberry Pi, running the standard Debian ‘Squeeze’ image, can not only replicate Colossus’ work but the whole process from interception to plaintext. Let’s call it Pilossus.

I thought others might like to have a go at running this themselves, so I’ve provided a simple tar ball that will get you up and running. Get your Pi booted up and we’ll start from a terminal prompt in your home directory.

Before you go any further, you must run the following command (especially if it’s a clean build of Debian), or the installation will not work).

$ sudo apt-get update

Now you can…

Download Pilossus 0.1 (tgz 12MB)

or, directly from your RasPi, run this:

pi@raspberrypi:~$ wget

Once  you’ve got the package into your ‘pi’ home directory via wget, scp, usb stick, etc we should have this:

pi@raspberrypi:~$ ls

First, uncompress the package in a suitable directory:

$ mkdir pilossus
$ cd pilossus
$ tar xvf ../pilossus-0.1.tar.gz

Now, run the script that will ensure you have all the bits and pieces you need:

$ ./

This will use apt-get to install or update any dependancies. It’ll probably take a few minutes and does require an Internet connection. Once downloaded, the binaries will be compiled from the Ada sources. There will be a couple of warnings, but these are nothing to worry about.

Once you see ‘Pilossus is ready’, the binaries required are now installed in /usr/local/bin and the scripts are ready to run from your current directory.

The cypher challenge comprised three messages. These are known here as 1200, 1600 and 1700 simply based on time of transmission. They had some variations in transmission type and how much information was given away in advance.

You can process and break these three transmissions from their raw audio form by running the script like so:

$ ./ 1200
$ ./ 1600
$ ./ 1700

Each process will take some time but will end with a lot of information including the results of analysis (the analogue for Colossus), the calculated wheel settings for Lorenz and the resulting plaintext. If you scroll up to the start of the plaintext output you will see a time reading. This shows how long it took to run the section that replicates the work of Colossus. I won’t spoil it for you but Colossus itself took around three hours.

If you would like to hear the original recordings, you can cd into the 1200UTC, 1600UTC or 1700UTC directories and enter ‘play A.mp3’.

If you want to run the codebreak again, you can ‘reset’ the system by running the ./ script. This removes all output files from a previous run.

Jo has released the source code and recordings of the original transmissions for anyone to download. However, the comments in the source files attribute copyright to DL2KCD and Joachim Schueth. Unfortunately I have been unable to contact Jo to ask permission. I am assuming that what I am doing here is simply an extension of the public release of his source and I make no assertions over copyright of this code. The scripts I have added ( and may be considered Public Domain.

So, why not download the package and see how your Raspberry Pi compares to the granddaddy of them all, Colossus. The result is quite remarkable considering it’s a £20 computer the size of a credit card. How far we have come. Got a time reading? I would to hear about it in the comments.

 More information on the cypher challenge, and how he did it, can be found on Jo’s website

Clear Printable Raspberry Pi Case

Does your Raspberry Pi need a case? Mine too. I’ve looked at a few options and intend to make a selection. However, my first attempt may well be my favourite. Behold the ‘Raspberry Pi Fold-Up Case’ (name needs work, I think). This is the brainchild of the enigmatically named ‘H2 Database’ and is a printable case. Want one? First download and print out the design onto some normal white paper. Now get a really thick sheet of acetate (OHP paper), the one I used felt about 300-350gsm. Tape the two together the corners so they don’t slip and carefully follow the cut and fold lines with a craft knife. Best of all, there’s no glue required with this case.

Once done, the case folds inwards and the best way to mount the Pi into it is start by folding back the flap that hooks onto the header by the GPIO. This anchors the case into place. It’s a bit fiddly to get it in position but you are rewarded with a solid-feeling and tight-fitting case that protects yet displays your Pi.

My attempt is above, what does yours look like?

Get The Case Template: