Commodore 64 Keyboard Gets The USB Treatment Thanks to Arduino

Recently I’ve been repairing a batch of broken Commodore 64’s that I scored on eBay for cheap. Out of the repairs, two boards were beyond hope but still had some usable parts on them so motherboards became donor boards. That left me with a couple empty cases and keyboards so I decided to make a Commodore 64 USB keyboard.

There’s already a nice product called Keyrah that does just this (plus a lot more) and I recommend you checking it out as it adds Amiga keyboard and joystick support.

But if you’re like me and want the challenge, I decided to go the maker route.

First, I searched for any such projects– no sense in re-inventing the wheel. I found a project by Mikkel Holm Olsen called C64 USB Keyboard. It used an Atmel ATMega-8 chip which I’ve learned is very similar to Arduino’s 168/328P chip. It might work but with some modifications– beyond my skill set today. I shelved this project and continued.

The keyboard is basically an 8×8 matrix keypad. There’s already a keypad library for Arduino. A couple of things that I discovered while using this library. One, don’t use pin 13 with the C64 keyboard. It’s probably because of the built in resister and LED that causes the pull ups to not work. An outside pull up might fix this. Two, the library only supports single keypresses. This is a bummer since you often will press two keys (i.e. the shift key, control, etc). But I worked around it. I put together a quick harness that will connect the Commodore 64 keyboard to the Arduino, aligning the rows and columns to the right pins. I like to make my projects the least destructive way so I use a lot of tape, jumpers and breadboards.

Getting the Arduino to talk USB makes use of the V-USB library which has been ported to Arduino. I really like this implementation because it’s all handled by the Arduino and needs very little passive glue on the outside to make it work. Below is a diagram of how to hook up USB to the Arduino. The values on the diodes are pretty strict and must be 3.6V 500mW zener diodes (although I hear 250mW is better). More information can be found in the V-USB documentation.

I made a small change to the V-USB code and moved the USB data (-) from Arduino pin 4 to pin 3– just edit usbconfig.h inside the UsbKeyboard library. I also commented out the optional connect/disconnect on pin 5 because I simply don’t have the pins to spare! Connected, the inside looks like this.

I power the Arduino via the incoming USB. To get it to be recognized properly by your computer, unplug the USB programming cable from the Arduino and then plug in the USB cable to the V-USB side. Otherwise it will not be recognized. It makes for a lot of cable swapping unfortunately while coding. I also powered the C64 power LED for nostalgia (this may be a good use for pin 13).

Speaking of code, I needed to define some key codes that were missing from the UsbKeyboard library. This was fairly straight-forward by looking them up on the USB HID guide (chapter 10). I also defined “bogus” key codes that I could intercept and do something else with. Most keys on the keyboard can be passed straight through. Others, like the arrow keys, F-keys, quote, asterisk, etc need a little more help since their locations are different than a standard keyboard. I also hacked together to ability to detect a modifier key (shift, control, etc) along with another key (from the keypad library). The resulting code isn’t pretty but I think it’s easy enough to follow. It’s included below for your amusement.

admin

Reg

January 18, 2012 at 7:41pm

Two Questions: 1 – is there a way to make the C64 keyboard bluetooth compatible (slap a bluetooth dongle in it)?
and 2 – even with the USB mod, are you selling it? I would love to buy it – it’s the perfect tactile keyboard to use with my desktop or iPad

admin

January 29, 2012 at 11:08pm

This mod works with the C64 keyboard. I think the C64C (light beige model) uses the same keyboard connector so it would probably also work. You don’t need the insides of the C64 at all for this mod– just the keyboard.

In theory this can be changed to work with any keyboard that uses a matrix– you just need to change the code appropriately.

Micky

Atfer

November 8, 2012 at 12:21am

Really nice project! I am trying to reproduce what you did there, but I am getting an error! I know that it’s not from my setup, because with the VirtualKeyboard project example it is recognized as an USB HID device, but when I am trying with your code, it gives me an error : Unknown device or three fast beep. Some help would be appreciated ;).

antoniotrkdz

April 13, 2013 at 6:59pm

Hi!
This work is superb !
I made one myself using arduino nano v 3.0. I redesigned the pin outline to suit a small I/O board I built. Everything gone pretty much straight but I am having problems with the SHIFT & co. Keys…would you like to help?
What resistor are you using for the led?
Thank you for all your work.

admin

April 13, 2013 at 8:49pm

That’s great to hear that you built one. What sort of problem are you having with the keys? I honestly don’t remember the value for the resistor on the LED– a160 Ohm might work well. Share pictures of your final project, I’d love to see.

Carl

April 26, 2013 at 2:57am

Hi Great Project, I want to make a start on this, however when I look in the readme of the USBkeyboard library it says that the sketch will ot work with the stripboard circuit ( like yours ) only with the PCB one that is on the wiki.

Carl

April 28, 2013 at 3:33am

Thanks for your reply, I have built mine, the USB works with a circuit, I used the same Zdiodes as you too.
However my problem is that none of the keys map correctly, if at all. I checked and double checked the connections, I have even traced each wire back to the Matrix to verify my pinouts. When I single test each combination ‘Q’ is always ‘3’ no matter what wire is inserted into the arduino!

The only clear difference to your method was that I can’t uncomment out the optional connect/disconnect on pin 5 in config without breaking the code, it wont compile. is this where the fault lies?

antoniotrkdz

April 30, 2013 at 4:02pm

@Carl,

your issues look hardware to me, I had the z,x and most notably return not working. I unscrewed all the twentysomething little screws on the back of the keyboard and cleaned with alcohol all the contact surfaces, screwed back in all the twentysomething little screws and…TA DAA everything is working again!

I used the CBM keyboard connector layout provided by Mikkel Holm Olsen.
All the keys work except for modifier keys and some keys like star, at, etc. that need shift to work.
Please let me know if you find some error in my pin layout.
Thanks!

Cristian

May 4, 2014 at 8:38pm

Hi, I’ve been trying to map the C64 keyboard using Arduino UNO and always have a set of keys that don’t work. I have tried all possible ways without success. I always see a missed column…sometimes is Column H…sometimes is C. I have checked all connections. It seems as if the matrix had a column less. Please if someone can help me.

TechC64C

October 27, 2014 at 2:36am

Please help me, i did a shield for my C64C Keyboard, it works with the USBKeyboard Example 1, but it doesn’t work with your code..
I tried also old IDE builds like 1.0.0 (2012), but it doesn’t work.. please help me! 🙁

amidar

November 16, 2014 at 1:31am

@TechC64C
Did You read this part :

I made a small change to the V-USB code and moved the USB data (-) from Arduino pin 4 to pin 3– just edit usbconfig.h inside the UsbKeyboard library. I also commented out the optional connect/disconnect on pin 5 because I simply don’t have the pins to spare! Connected, the inside looks like this.

Leandro

October 4, 2017 at 3:19am

Hey, Nice project! I moved out to a old house that happens to have a sort of attic full of junk stuff left from the old family that lived here. Trying to clean out things i found 2 commodores 64 and other similar computer that appears to be a commodore 128 (not sure, covered with ages of dust..).
The question is, if the keyboards on the commodores arent stuck, this project would be suitable on the pinout of an arduino uno, since my brother has one and not really using it, or is more convenient to buy a arduino nano clone?
Thanks in advance, And keep this kind of projects up, im new to all the arduino stuff and trying to learn more about this platform!

nicola

reliable225

December 31, 2017 at 2:32am

ok will someone mind explaining to me how the Commodore 64 keyboard works? All I want to know is about the cursor keys, like there’s two of them (one is up and and down, second is left and right) so how do I move around with them, do I put pressure on the specific spot of the key? Do I combine it with another key? What do I do, or are they not used for movements at all? Please explain

reliable225

December 31, 2017 at 3:09am

nvm peeps I just realized the whole cursor key thing it turns out you have to combine the cursor key with shift if you want to go in a different direction (cursor up-down+shift=up,cursor up-down=down,cursor left-right+shift=left, cursor left-right=right) so yeah the shift is close to the two cursor keys so I can put three fingers there, I didn’t notice that sorry guys