# Commodore Keyboard to USB HID with CircuitPython

## Overview

https://youtu.be/8-WUAa3axDc

In this guide, you'll see how to adapt a Commodore 16 keyboard for use on modern computers using CircuitPython and an Adafruit KB2040 microcontroller board.

The techniques in this guide may also be helpful in converting other classic keyboards that use a key matrix. The `keypad.KeyMatrix` class in CircuitPython makes this task actually quite simple.

The code in this guide is made for the KB2040, which was designed for exactly this kind of project! With adaptation it would work on many other CircuitPython boards, provided they support the KeyMatrix class, USB HID, and (for the advanced version) asyncio.

## Homework

I received this bare keyboard with no documentation. Some internet image searches confirmed it was a Commodore 16 keyboard (the 4 arrow keys on the top row are a dead giveaway). This keyboard is much rarer than the more common Commodore 64 keyboard, which is similar but not 100% compatible.

The keyboard has 60-odd keys (including a physically locking shift key) and a 20-pin connector. Without more documentation or a plan, there are a lot of possible combinations to try.

Luckily, classic computers of this age tended to have good documentation, including schematics. A search for a Commodore 16 schematic [finds the following](https://archive.org/details/SAMS_Computerfacts_Commodore_C16_1984-12_Howard_W_Sams_Co_CC8/page/n9/mode/2up) (screenshot from archive.org):

![](https://cdn-learn.adafruit.com/assets/assets/000/114/877/medium800/circuitpython_Screenshot_2022-09-08_13-37-08.png?1662662733)

From this, you can intuit the following pin numbers on the keyboard connector

- Rows: 6, 16, 1, 13, 11, 12, 8, 19
- Columns: 5, 3, 10, 9, 7, 17, 14, 15, 18
- Unused: 5, 20
- Optional GND: 4
- Orientation key: 2

From the [source code of the Commodore 16's kernal](https://github.com/mist64/cbmsrc/blob/master/KERNAL_TED_04/ed7.src) (sic), I found the following table giving the key that corresponds to each row and column--noting that both "shift" keys as well as "shift lock" activate the same row & column:

```terminal
del   return  £       help    f1      f2      f3      @
3     w       a       4       z       s       e       shift
5     r       d       6       c       f       t       x
7     y       g       8       b       h       u       v
9     i       j       0       m       k       o       n
down  p       l       up      .       :       -       ,
left  *       ;       right   escape  =       +       /
1     home    control 2       space   c=key   q       stop
```

Armed with this information, you can connect your keyboard to a microcontroller. You can use individual jumper wire connections, or build an adapter cable as detailed on the next page of the guide.

## Parts
Featured
### Adafruit KB2040 - RP2040 Kee Boar Driver

[Adafruit KB2040 - RP2040 Kee Boar Driver](https://www.adafruit.com/product/5302)
A wild Kee Boar appears! It’s a shiny **KB2040**! An Arduino Pro Micro-shaped board for Keebs with RP2040. (#keeblife 4 evah) A lot of folks like using Adafruit parts for their Keeb builds – but with the ItsyBitsy not being pin-compatible with the Pro Micro pinout, it...

In Stock
[Buy Now](https://www.adafruit.com/product/5302)
[Related Guides to the Product](https://learn.adafruit.com/products/5302/guides)
![Angled shot of short black microcontroller.](https://cdn-shop.adafruit.com/640x480/5302-07.jpg)

Featured
### Large Single Row Housing Pack for DIY Jumper Cables

[Large Single Row Housing Pack for DIY Jumper Cables](https://www.adafruit.com/product/3146)
Are you frustrated by the lack of customization options for your jumper wires? Look no further!

Compatible with both male and female wires, these fully customizable wire housings bring DIY to a new level, giving you near limitless options when using jumper wires in your...

In Stock
[Buy Now](https://www.adafruit.com/product/3146)
[Related Guides to the Product](https://learn.adafruit.com/products/3146/guides)
![Collection of many Large Single Row Wire Housing Packs](https://cdn-shop.adafruit.com/640x480/3146-00.jpg)

Featured
### Premium Male/Female Raw Jumper Wires - 40 x 6"

[Premium Male/Female Raw Jumper Wires - 40 x 6"](https://www.adafruit.com/product/3633)
Our **Raw Male/Female Jumper Wires** are perfect for making a custom jumper wire sets for wire harnesses or jumpering between headers on PCBs. These premium jumpers are a little over 6", almost 8" (about 200mm) long and come in a 'strip' of 40 (5 pieces of the ten rainbow...

In Stock
[Buy Now](https://www.adafruit.com/product/3633)
[Related Guides to the Product](https://learn.adafruit.com/products/3633/guides)
![Angled shot of Premium Male/Female Raw Jumper Wires - 40 x 6](https://cdn-shop.adafruit.com/640x480/3633-02.jpg)

Featured
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

Featured
### USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long

[USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long](https://www.adafruit.com/product/4199)
As technology changes and adapts, so does Adafruit! Rather than the regular USB A, this cable has&nbsp; **USB C to USB C** &nbsp;plugs!

USB C is the latest industry-standard connector for transmitting data&nbsp;_and_&nbsp;power. Like Lightning and MagSafe cables, USB C...

In Stock
[Buy Now](https://www.adafruit.com/product/4199)
[Related Guides to the Product](https://learn.adafruit.com/products/4199/guides)
![USB C to USB C cable. USB 3.1 gen 4 with E-Mark. 1 meter long](https://cdn-shop.adafruit.com/640x480/4199-01.jpg)

- [Next Page](https://learn.adafruit.com/commodore-keyboard-to-usb-hid-with-circuitpython/wiring-the-commodore-16-keyboard.md)

## Guide Products

### Adafruit KB2040 - RP2040 Kee Boar Driver

[Adafruit KB2040 - RP2040 Kee Boar Driver](https://www.adafruit.com/product/5302)
A wild Kee Boar appears! It’s a shiny **KB2040**! An Arduino Pro Micro-shaped board for Keebs with RP2040. (#keeblife 4 evah) A lot of folks like using Adafruit parts for their Keeb builds – but with the ItsyBitsy not being pin-compatible with the Pro Micro pinout, it...

In Stock
[Buy Now](https://www.adafruit.com/product/5302)
[Related Guides to the Product](https://learn.adafruit.com/products/5302/guides)
### Large Single Row Housing Pack for DIY Jumper Cables

[Large Single Row Housing Pack for DIY Jumper Cables](https://www.adafruit.com/product/3146)
Are you frustrated by the lack of customization options for your jumper wires? Look no further!

Compatible with both male and female wires, these fully customizable wire housings bring DIY to a new level, giving you near limitless options when using jumper wires in your...

In Stock
[Buy Now](https://www.adafruit.com/product/3146)
[Related Guides to the Product](https://learn.adafruit.com/products/3146/guides)
### Premium Male/Female Raw Jumper Wires - 40 x 6"

[Premium Male/Female Raw Jumper Wires - 40 x 6"](https://www.adafruit.com/product/3633)
Our **Raw Male/Female Jumper Wires** are perfect for making a custom jumper wire sets for wire harnesses or jumpering between headers on PCBs. These premium jumpers are a little over 6", almost 8" (about 200mm) long and come in a 'strip' of 40 (5 pieces of the ten rainbow...

In Stock
[Buy Now](https://www.adafruit.com/product/3633)
[Related Guides to the Product](https://learn.adafruit.com/products/3633/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
### USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long

[USB C to USB C Cable - USB 3.1 Gen 4 with E-Mark - 1 meter long](https://www.adafruit.com/product/4199)
As technology changes and adapts, so does Adafruit! Rather than the regular USB A, this cable has&nbsp; **USB C to USB C** &nbsp;plugs!

USB C is the latest industry-standard connector for transmitting data&nbsp;_and_&nbsp;power. Like Lightning and MagSafe cables, USB C...

In Stock
[Buy Now](https://www.adafruit.com/product/4199)
[Related Guides to the Product](https://learn.adafruit.com/products/4199/guides)

## Related Guides

- [Adafruit KB2040](https://learn.adafruit.com/adafruit-kb2040.md)
- [Fruit Jam IRC Client in CircuitPython](https://learn.adafruit.com/fruit-jam-irc-client-in-circuitpython.md)
- [USB Host SDR for AM/FM & Weather Radio on Fruit Jam](https://learn.adafruit.com/usb-host-sdr-for-am-fm-weather-radio-on-fruit-jam.md)
- [No-Code Snowfall Tracker with WipperSnapper and Adafruit IO](https://learn.adafruit.com/no-code-snow-tracker-with-wippersnapper-and-adafruit-io.md)
- [Laser-Cut Layered LED Art Panel (Wood + Acrylic) with WLED](https://learn.adafruit.com/laser-cut-layered-led-art-panel-wood-acrylic-with-wled.md)
- [NextBus Transit Predictions for Adafruit MagTag](https://learn.adafruit.com/nextbus-transit-predictions-for-adafruit-magtag.md)
- [Close Encounters of the MIDI NeoPixel Visualizer Kind](https://learn.adafruit.com/midi-neopixel-visualizer.md)
- [Google Graveyard with Adafruit MagTag](https://learn.adafruit.com/google-graveyard-with-adafruit-magtag.md)
- [LOVE Light](https://learn.adafruit.com/love-light.md)
- [Rotary Phone Dial Keypad](https://learn.adafruit.com/rotary-phone-dial-keypad.md)
- [Star Trek Data Dispenser](https://learn.adafruit.com/star-trek-data-dispenser.md)
- [Create a Memory Game on Fruit Jam Metro RP2350](https://learn.adafruit.com/create-a-memory-game-on-metro-rp2350.md)
- [Light Up your Costume with Noods](https://learn.adafruit.com/light-up-your-costume-with-noods.md)
- [No-Code DS18B20 Temperature Sensor with WipperSnapper](https://learn.adafruit.com/using-ds18b20-temperature-sensor-with-wippersnapper.md)
- [Mushroom Lights with NeoPixels and WLED](https://learn.adafruit.com/mushroom-lights-with-neopixels-and-wled.md)
- [Color Mixing QT Py Cuff Bracelet](https://learn.adafruit.com/color-mixing-qt-py-cuff.md)
