Wednesday 15 February 2012

Arduino based ZX81 USB Keyboard

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

Here's the first Arduino based project, or at least developed on an Arduino.
Yes, it looks like a ZX81, and it is a ZX81, or at least it was many years ago. This is in fact the remains of my very first computer, a Sinclair ZX81, which I got around 1982. It served me well, and I learned to program on it, first in BASIC and then in Z80 assembler. At one point it stopped working, and with the help of a family friend we traced the problem to a failed 7805 voltage regulator. That was replaced, and that was my first computer repair, probably around 1983. It lasted another couple of years but was replaced by my second ZX81, which is still complete and in working order.  I expect I was keep to learn how things work, and one of the best ways is to take them to bits and find out, and many experiments were carried out in my youth and the sadly this ZX81 didn't come out of it well. I think the plans to put it into a new case with a proper keyboard were probably its final downfall.
Roll forward 25 years, and I still have the bits. I did look at getting it up and running again. The keyboard was a write off, but I managed to find new replacement keyboard membranes from RWAP and bought one. They are very good replicas, the only noticeable difference I could see is the © date at the top, 1980 vs 2008.
The main board was pretty much a write off as well. I tried to revive it, but youthful enthusiasm and the passage of time we working against me. The case was OK though, and I did have the membrane, so I thought why not make it into a USB keyboard (as you do). This was one of the things I tried to do a couple of years ago with the PIC, and that wasn't having any of it.
The Arduino USB Library seems to be in good order, a port of V-USB, and little is required to get a USB keyboard up an running. I built the circuit on a propto shields and added some keys on breadboard. The major stumbling block for me was most of the sample circuits on the net used pins D2 and D3, where as the config file supplied used D2 and D4. Once I'd changed that, my little 6 key keyboard was up and running. I also tested it with the new membrane and that was working as well.
I ended up writing my own keyboard scanning and debouncing code as I wanted multiple button presses and rollover repeat. A bit of tweaking of the timings was required but I soon got it down a comfortably usable level.
One of the neat things about the Arduino is that once it's working on the Arduino board, you can transfer the ATMega328P onto another board and use it there. If you leave the bootloader in place and add the appropriate headers, you can use a FTDI or one of the new Arduino USB Serial boards to program it in place. I've put together the circuit on a piece of padboard and to all intents and purposes, with the USB-Serial board plugged it, you can treat it like the Ardunio Uno and continue development, upload new software and use the serial monitor.
I was able to continue this once installed in the final unit and sort the final key mappings. Once complete, I unplugged the USB to Serial board and screwed the lid on and there you have it, a USB keyboard from a ZX81.
It was never going to be fantastic to use, due to the fact it is a membrane, although the new one seems to be better to use the the one on my other ZX81. The application I have for the ZX81 USB keybaord is on my HTPC, which is mainly controlled from the remote. I occasionally will pause or change programs in Myth TV using the keyboard if it is nearer that the remote, and for that it works fine and looks better than the standard keyboard it replaced.

I was probably watching the same thing the last time I used the original ZX81, just on a slightly smaller TV.

2022 Note: this was a very primitive version of the USB keyboards I produced later on, with custom PCBs and custom firemware. I have left this post here for historic reasons, but I have got rid of all of the other USB keyboard posts as I think there time is over, and I don't want to get any more requests for them.

2023 Note: Still getting requests, so I have listed some of the newer custom ZX81 USB keyboard controllers on my SellMyRetro store.

Two versions, one for use within a ZX81 case, and one to use a ZX81 membrane standalone for your own project not in a ZX81 case.