Program it · KeyChainino 144

How to Program KeyChainino

Your KeyChainino 144 already has 17 games inside. You need this page only if you want to change something: put another sketch on it, try one from GitHub, or write your own game.

The KeyChainino has no USB port. It's programmed through the six pads on the front, with a programmer. You can use two kinds. Pick yours, and the steps below follow.

Choose your programmer
  1. Install the Arduino IDE and MiniCore

    Download the Arduino IDE from arduino.cc. Then add MiniCore, the board package for the ATmega328P that's inside the KeyChainino:

    1. Open File › Preferences.
    2. In Additional boards manager URLs paste:
      https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json
    3. Open Tools › Board › Boards Manager, search for MiniCore and click Install.
  2. Get the USBasp ready

    Take off its power jumper. The KeyChainino keeps its battery in and runs on it, so the USBasp must not power it too.

    On macOS and Linux there's nothing to install: plug it in and that's it. On Windows the USBasp needs a driver the first time: open Zadig, choose the USBasp from the list and install the WinUSB driver.

    Turn your Arduino into a programmer

    1. Connect the Arduino UNO to the computer, alone, with nothing else attached.
    2. Open File › Examples › 11.ArduinoISP › ArduinoISP.
    3. Select Tools › Board › Arduino UNO and its port, then click Upload.

    That's it: now your UNO is a programmer. You need to do this only once, as long as you don't upload anything else to it.

  3. Connect it to the KeyChainino

    Leave the battery in, power jumper off. The KeyChainino runs on its own battery while you upload, so the USBasp must not power it.

    Take the battery out first. The Arduino powers the KeyChainino through its 5V pin, and the coin cell must not be in there too.

    The six pads, seen from the LED side with the hole at the top. Pin 1 is the square pad.

    KeyChainino pad USBasp 10-pin cable
    MISO pin 9
    VCC pin 2 (no power: jumper off)
    SCK pin 7
    MOSI pin 1
    RESET pin 5
    GND pin 10

    With a 10-to-6-pin adapter it's even simpler: the 6-pin plug goes straight on the pads, with pin 1 (the red wire) on the square pad.

    KeyChainino pad Arduino UNO
    MISO D12
    VCC 5V
    SCK D13
    MOSI D11
    RESET D10
    GND GND

    You don't need to solder anything. Put a 6-pin header in the pads and hold it gently in place while it uploads.

    Tip. Some UNO boards reset themselves when the IDE opens the port, and the upload fails. A 10 µF capacitor between RESET and GND on the UNO fixes it.

  4. Get a sketch

    There's no library to install any more. Every sketch folder has everything inside: the game and its own copy of the KeyChainino code that drives the LEDs, the buttons and the sleep.

    1. On GitHub press Code → Download ZIP, and unzip it.
    2. Open Sketch/KeyChainino_v4_144_LEDs, then the folder of the sketch you want.
    3. Open the .ino file inside. The other files open as tabs next to it.

    Keep all the files together in that folder: the IDE builds them with the .ino. If you installed the old KeyChainino library years ago, you can delete it from your libraries folder. The new sketches don't use it.

  5. Set up the board

    In the Tools menu choose these settings. They're always the same, for every sketch.

    Tools menu Choose
    Board MiniCore › ATmega328
    Clock 8 MHz internal
    BOD BOD disabled
    EEPROM EEPROM retained
    Compiler LTO LTO disabled
    Variant 328P / 328PA
    Bootloader No bootloader
    Programmer USBaspArduino as ISP

    "EEPROM retained" keeps your high scores and drawings when you upload a new sketch.

  6. First time only: Burn Bootloader

    Click Tools › Burn Bootloader. Don't worry about the name: with "No bootloader" it doesn't put any bootloader on the chip. It only sets the fuses, so the ATmega runs at 8 MHz on its internal clock.

    Bought your KeyChainino from the shop? It's already done, skip this step.

  7. Upload

    Click Sketch › Upload Using Programmer (Ctrl+Shift+U, or ⌘⇧U on a Mac). After a few seconds you should see Done uploading.

    Lift the header off the pads, press A and B together, and play.

    Put the battery back, press A and B together, and play.

From the terminal

Prefer the command line?

Same thing, with arduino-cli and avrdude. This writes the fuses and the sketch in one go.

# compile
arduino-cli compile --fqbn arduino:avr:pro:cpu=8MHzatmega328 \
  --output-dir build KeyChainino_v144_multigame

# flash: fuses + sketch
avrdude -patmega328p -cusbasp -Pusb \
  -U lfuse:w:0xe2:m -U hfuse:w:0xd7:m -U efuse:w:0xff:m \
  -U flash:w:build/KeyChainino_v144_multigame.ino.hex:i
# compile
arduino-cli compile --fqbn arduino:avr:pro:cpu=8MHzatmega328 \
  --output-dir build KeyChainino_v144_multigame

# flash: fuses + sketch
# -P is your UNO's port (COM3 on Windows)
avrdude -patmega328p -cstk500v1 -P/dev/cu.usbmodem1101 -b19200 \
  -U lfuse:w:0xe2:m -U hfuse:w:0xd7:m -U efuse:w:0xff:m \
  -U flash:w:build/KeyChainino_v144_multigame.ino.hex:i

If something goes wrong

Device signature = 0x000000

The programmer can't hear the chip. Nine times out of ten the header isn't touching all six pads: press it a bit harder, or check the wires. And check the battery: with the jumper off, the KeyChainino runs on it.

could not find USB device with vid=0x16c0 pid=0x5dc

The computer doesn't see the USBasp. Try another USB port or cable. On Windows, check the driver from step 2.

programmer is not responding

The UNO isn't running the ArduinoISP sketch, or the port is wrong. Upload ArduinoISP again (step 2) and check Tools › Port.

warning: cannot set sck period

Old USBasp firmware. You can ignore it: the upload works anyway.

Do you have an older KeyChainino?

Want to write your own game? Start here →

{"cart_token":"","hash":"","cart_data":""}