chester's blog

technology, travel, comics, books, math, web, software and random thoughts

Connecting a classic (ADB) Apple keyboard to a modern (USB) PC using a regular Arduino

27 Dec 2016

When I saw this person building a Raspberry Pi inside a vintage Apple Keyboard, I thought it could be a comfortable way to play Apple II games on a TV. More important, I happen to have an Apple Extended Keyboard II just waiting for such an experiment…

Keyboard + Arduino

My winter holiday plans did not include going outside, so I wanted to build it with parts I already had. But the hack uses an Arduino Pro Micro (with a little help of the TMK Keyboard Firmware Collection) as a converter between ADB (the interface used by the Apple IIGS and older Macs) and the familiar USB, and I only had a regular Arduino (actually, a Leonardo-compatible clone).

I wasn’t sure that would do the job, so before tearing the keyboard apart, I decided that my first experiment would be an attempt to connect it to my computer.

To connect the Arduino to the keyboard, I could have cannibalized an S-Video MiniDIN-4 cable, since ADB uses the same connector. But I ended up using breadboard jumper wires, because they can be easily plugged on the Arduino and inserted straight into the ADB jack holes.

The TMK ADB-USB wiring instructions suggest a pull-up resistor. I used a 6K8Ω (the first one I found within the recommended range) and a mini-breadboard to organize the connections. Here is how I wired it:

Arduino-ADB connection with pull-up resistor

I wasn’t sure which (if any) of the .hex files on the binary/ folder would work, so I built my own. You can download it here, or build (on a Mac with Homebrew) with:

brew tap osx-cross/avr
brew install avr-libc avrdude
git clone https://github.com/tmk/tmk_keyboard
cd tmk_keyboard/converter/adb_usb

At this point, edit the Makefile, changing MCU to atmega32u4 and TARGET to adb_usb_leonardo (or any name you want), then:

make -f Makefile clean
make -f Makefile

Keyboard + Arduino from behind

Now you should have a binary (adb_usb_leonardo.hex). To install it on the Arduino, use this command (pushing the RESET button on the board right before you hit ENTER):

sudo avrdude -patmega32u4 -cavr109 -P/dev/cu.usbmodemFD121 -b57600 \
  -D -Uflash:w:adb_usb_leonardo.hex:i

The device (cu.usbmodemFD121) may be a bit different for you (you can check the right name with the Arduino IDE). You will know it worked when you get a few progress bars, then something like avrdude: 20528 bytes of flash verified. At that point, the computer should “see” your Arduino as a USB keyboard.

It took me some time to figure out the build and install, but the hardware part worked without a hitch. With due apologies for the narration (I was pretty tired), you can see it in action here:

Comments




Korean goat

i did it with your Hex file and aek2 keyboard and pro micro days ago, thank you for your file. but i found a interesting one. after restaring my mac-mini, i pressed Option key for selecting startup disk but it didnt work. it keeps booting to macOS installed already. i want to know your keyboard also is doing like mine.

chesterbr

That is curious! I don't have that keyboard/setup anymore, but I did try rebooting while holding Option on my current external keyboard (an Ergodox EZ), and it does _not_ prompt me for the startup disk.

Since it's a MacBook, I repeated the experiment using the built-in keyboard, and for that one it asks me to select the startup disk.

My guess is that Apple only allows that shortcut with official/blessed keyboards? Not unlike they only allow mapping the fn key to system shortcuts on those (as througoutly debugged by the QMK peeps in https://github.com/qmk/qmk_..., I mean.

I guess we must test that with a more "vanilla" keyboard, will try to find one around here, now I got curious! :)

[EDIT fixed the link to the qmk_firmware issue]

Korean goat

"Shutdown first and then start Mac and then press Option key"
i started my mac this morning first time of day and pressed Option key, IT WORKS HAHAHA. so i restarted Mac and pressed Option key like yesterday. yea it didnt work again. i think we have to do shutdown-starting routine instead of restarting.

chesterbr

That is interesting. I tried that here, but still got no result by shutting down and restarting.

But then I tried another thing: instead of just holding option and turning on the computer, I hit it repeatedly while I turned on, and _that_ activated the selector.

So maybe external keyboards require you to press Option _after_ the boot starts (which is much easier to do if you shutdown then start, as opposed to just starting), but before the check is done?

Anyway, happy that you sorted it out, and that we learned the startup disk selector is a bit more finicky than expected! :-)


Learn how to write in Markdown with this Quick Reference.