My Raspberry Pi Powered Sinclair ZX Spectrum
I've previously posted about my Raspberry Pi Powered Commodore Plus 4 build, now it's time to revisit another one of my cherished childhood machines, the Sinclair ZX Spectrum. I had the Toastrack model back in the day, Although I now have a Spectrum +2 in my collection.I have seen this build done several times before, so it's nothing new, and after stumbling across a reasonably cheap empty Spectrum 48K case on eBay, I'd thought I'd give it a go myself. Obviously I would have to improve on the build when I do it... So let's get down to business, there's not much going on inside this machine, just a Raspberry Pi Zero, two home made connectors for the keyboard membrane, some extensions for the Zero's ports, and a couple of buttons mounted on piece of strip board.The Spectrum keyboard membrane connects directly to the Zero's GPIO pins, and is read by a Python script and the uinput module The parts required for this build are...One (preferably dead) ZX Spectrum 48K (or 48K+) with working keyboard membraneOne Raspberry Pi Zero (Original/W/WH)Power supply for the PiHeatsink for the PiMicro SD card (16GB at least)Eight 1N4048 diodesMini HDMI plug to HDMI socketMicro USB Plug to USB socket (mine wasn't long enough, so I needed a short extension as wellMicro USB socket to micro USB plugSome small pieces of strip boardBoth of the connectors for the keyboard membrane (you can take these from a dead board, or you can buy them new)A load of GPIO jumper wiresHeader pins for the Zero and strip boardTwo small normally open momentary buttonsThe Software of your choice (Retropie / ZXBaremulator / Sinclairian etc) Tools requiredScrewdriverSoldering ironSolderDouble sided tape or glueComputer Build detailsFirst thing to do is remove the five screws on the bottom of the case then remove the main board, be careful with the keyboard membrane, they are fragile. Keyboard connectors There are two membrane connectors, a five way and an eight way, the five way just needs the connector soldering to the strip board along with a pin header, the eight way is the same, but needs a diode in between each connector and pin header, the negative end of the diode (marked by a black band) needs to be away from the membrane connector, ie, towards the Pi. In the second image above you can see the cut I made in the board to electrically separate the two sides of the diode Switch board The next step is to make the board with the buttons fitted, I found these buttons in an old Freeview box, and with a bit of persuasion they fitted nicely on the strip board, the two sides of each switch just go to a pin header, you don't need a resistor, and you can use a common ground if you preferPositioning it all inside the case Now it's time to fit the extension leads in place, the first picture was an early mock up, the second and third pictures show the final position of the ports, the power and USB sockets are mounted on small scraps of strip board stuck together, the HDMI socket has been filed down to the plastic inside because it was too big to fit in the expansion port, then it was stuck down with double sided tape, the two buttons fit nicely in the EAR and MIC port holes, although I'm sure you could do a better job of lining them up in the centre of the holes than I didConnecting the GPIO leads to the PiThis is tricky as there's a lot of wires to connect, so here's a crudely made image showing which wire goes to which GPIO pin. This is viewed from above looking into the bottom half of the Spectrum, the left track on each keyboard membrane is pin 1. SoftwareThe original ZXScanner scripts and installation instructions can be found here. You may notice things have changed a bit and the instructions aren't quite right with the installation of the dependencies, but it's not too hard to figure out.You will need to modify the zxscanner.py script slightlyOpen the file in Notepad++ and look for the code under the line # MagPi Article MappingsdataLines = [26,19,13,6,5] and addressLines = [25,24,23,22,27,18,17,4]Put a # in front of both of these to comment them outScroll down to the next section where it 's headed # Original Mappings and remove the # from the lines starting dataLines and addressLinesYou have just swapped the GPIO pin numbers over, the script was featured in the same MagPi as my Plus4 was, but with different GPIO pins used, so the script now contains bothYou will also need to install mpg123 to hear the sound when the buttons are pressedapt-get install mpg123It was at this point during testing I discovered the keys 6, 7, 8, 9, and 0 weren't working. So the whole build was stripped down, the membrane tested, the code analysed, and continuity tests performed, it was eventually discovered to be a broken track on the eight way connector board.The script as it is only allows one button, which swaps over the key mapping and exits FUSE, I added the code for the second button myself, also I swapped the key mapping around to include a backspace key, so you can delete text easier You can download my version of the script and the updated sound files here, just replace the original files with this theseThe differences are, Two buttons are supported, connect the 2nd button to GPIO3 and ground, this gives start, restart, and shut down functionsSo on my build a short press on the left button swaps between the different key maps for the Speccy keyboard, and a long press exits FUSE. While a short press on the second button when the Pi is halted will start it up, when it's running pressing the button for a second will restart the Pi, and a long press will shut it down FinallyThat's it really, not much hardware to assemble, it's mainly about the softwareEnjoy!