Wednesday, 15 February 2012

Arduino based ZX81 USB Keyboard

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.

Update:
Post with source and description
Post with schematics

Further update:
Arduino Leonardo based ZX81 USB keyboard

Creative Commons Licence
ZX81 USB Keyboard by Dave Curran is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License