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.
Ok, so some assembly required. A few re-reads of the Instructable article later and I had my head around what was going to happen. At the heart of this little enterprise is the iddy-biddy Pro Micro, which is a clone of the Arduino Leonardo, a popular micro-controller. The Leonardo has a major trick up its sleeve compared to the more commonly-encountered Uno: Its USB port can be addressed, allowing you to easily create a new USB device. In fact, when you first hook it up to a Mac, the Mac thinks a keyboard has been attached (which is handy). So, a load of inputs to one USB output.
The Speccy’s keyboard uses a thin plastic membrane sandwich with two layers of electrical tracks which form a matrix grid of 5 by 8 tracks. When a key is pressed it creates a circuit between two of these tracks that are connected to the motherboard. Each key ‘lights up’ a unique pair of tracks. The tracks lead into two ribbon cables that go from the keyboard assembly to the motherboard. These are known as the ‘data’ and ‘address’ cables and only one wire on each will light up per keypress. The ribbon itself is very, very delicate and normally the first thing to fail on a Speccy, causing any keys on the broken line to fail. Newly manufactured replacements are available that are a lot more sturdy should they be needed.
The deal is this: Hook up the Speccy’s keyboard matrix to the Pro Micro’s input lines (of which it has many) and write a bit of software that monitors these inputs and converts them into USB keyboard controller information, which is then passed back to the computer connected to it. So, step one is to create the USB interface then I’ll hook it up to a Raspberry Pi that will also live inside the Speccy.
It’s time to make a wish-list. I might not get all of this done but, hey, it’s nice to have a plan:
- Stand-alone ZX Spectrum emulator powered by a Raspberry Pi (of course)
- Wi-Fi access to the Pi (as the network port is likely to be covered)
- Switchable to USB keyboard for any other device
- Nuclear Power-Station Controller (Hey, Clive said the ZX81 could do it)
- Bluetooth keyboard
The last one came about as a bluetooth dongle was included with the things I bought. Seems a shame to waste it.
Let’s get started.
First off, what’s in box? Well, not much. The Speccy’s motherboard has presumably wandered off in search of new capacitors and 4116 ram. There is, however, a keyboard membrane that needs testing. Of course, we know that the Speccy’s membrane is a resilient beast, easily capable of holding out against the hardest that a dedicated Daley Thompson’s Decathlon player can throw at it. Made you look. Sadly this wasn’t even the later, better Samsung version of the membrane so I made myself a £10 bet it was broken and set about testing it on a Speccy motherboard.
The good news is, it wasn’t all bad. Only track 3 of KB1 (the smaller ribbon) appeared damaged. The ribbon looked like it had been previously trimmed and was pretty ragged. Time for scissors and some supportive insulation tape. There, that’s better:
Originally I’d thought the Pi (a model B+) wasn’t going to fit with its tall USB ports. Thankfully it does so in the upper raised area of the case, albeit placing some annoying restrictions on where it can be placed.
An alternative is the funky new Pi Zero which would fit just about anywhere:
Having given this serious consideration, I decided against it as there’s no network connectivity and only one USB port. Still, what a thing!
Next is a test of the Pro Micro. I’ve made some notes below on the fun of getting this working but I did establish I had a 5v Pro Micro that was working fine and I was able to upload code to it. You could also use an ‘official’ Leonardo for this controller, but it’s a lot larger and would compromise what else you could get in the case.
Before breaking the soldering iron out, I had a few run-throughs laying out the boards and making sure everything will fit. The two pieces of stripboard you can see will hold the connectors for the keyboard membrane.
Now, where’s that soldering iron?
Experiences with the Pro Micro
I had some fun with the Leonardo-compatible Pro Micro. If you’ve got one of these and, like me, have little idea what you’re doing, then do go ahead and do what I did and brick it almost immediately. Thankfully, they’re hard to upset and can be un-bricked easily.
These funky little micro-controllers are programmed from a free app from Arduino, the Arduino IDE. You can write code (called a ‘sketch’) and transfer it to the Pro Micro using its USB connection. However, as I learned, it’s vital to have everything set up correctly. The IDE needs an ‘board profile’ file to know how to talk to the Pro Micro. Also, it’s available in two different voltages: 3.3v and 5v. This is normally marked on the back of the board (but not in my case).
PJ’s top tips for getting started with the Pro Micro
- Don’t use version 1.6.6 (current at time of writing) of the Arduino IDE, use version 1.6.5 instead. A bug prevents successful upload of the sketch.
- Get the correct board profile from Sparkfun before doing anything and follow the installation instructions.
- Pro Micros are available in 3.3v and 5v versions. If you upload a test and have the wrong voltage type selected, things so South, but not too South.
If you find you can no longer talk to the Pro Micro:
- Set the board type correctly in the IDE (i.e. the other one)
- Get a small piece of stiff wire
- With the Pro Micro on, carefully short the pins marked GND and RST twice in short succession
- The Pro Micro will now activate its bootloader and create a new COM port on your machine
- You now have eight seconds to go back to the Arduino IDE, select the newly recreated COM port and upload a simple sketch to replace what was there before
This process takes a few times to get right but once done, the Pro Micro comes back to life.
When programming (uploading sketches) to the Pro Micro, it will restart, then its USB COM port will disappear only to be replaced by another with a number at the end incremented by 2. This is normal. You’ll need to reselect the port in use each time you upload a sketch. I really wish I’d figured that out sooner.