Dear Lazyweb, can an Adafruit Metro Mini (ATmega328P) be made to impersonate a USB keyboard? If so, how? If not, what board should I buy instead? Smallest possible, with 7 digital inputs.

Keyboard.h: warning: Using legacy HID core (non pluggable)
error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

Some breadcrumbs seemed to be suggesting "HID-Project" and "HoodLoader2" but neither seemed to help.


Tags: , ,

19 Responses:

  1. T Hudson says:

    Not directly - the ATmega328P does not have any USB hardware built in and typically use a FTDI (or knockoff) USB serial converter that doesn't have any flexibility. There is the bit-banging V-usb stack that fakes it on GPIO pins, and can emulate USB HID keyboards, although you might be better off with a slightly fancier Arduino if you want stability.

    Most of the Arduino USB HID keyboards use ATmega32U4 variants like the Leonardo, which do have a USB peripheral. I've been very happy with the smaller form-factor Teensy 2 for 5v peripherals or the Teensy 3.2 for 3.3v with a much faster CPU.

  2. Ryan Finnie says:

    ATmega32U4 can do simulated keyboard / mouse. I have the Arduino Micro which has 20 digital inputs and is about the size of Adafruit Metro Mini. Looks like the SparkFun Pro Micro is smaller but still has 12 inputs.

  3. dean says:

    Teensy LC has very solid and easy to use USB keyboard support and is under $12.

  4. Gordo says:

    I don't know if this is the smallest, but I am using a Arduino Leonardo as a HID device to provide key presses to linux.

    Code is here:

    (The project turns a Raspberry Pi screen on / off and refreshes the browser. Also has a light sensor that toggles the screen when the lights go on / off.)

    If you really want to go down a rabbit hole, there is qmk, which apparently many custom mechanical keyboards use.

    • dcapacitor says:

      As someone who's diving into QMK right now, I can share a few things I learned already.

      Most custom keyboards that people build are based on specific projects. The QMK repo hosts the config files and keymaps for those projects, so all that's required in that case is to compile the right version of the firmware and write it to the board. Not that big of a rabbit hole in that scenario.

      QMK supports a ton of different features though, so getting started with from scratch is daunting. The good part is that there is a lot of documentation out there, and an active community.

      Jamie, I'd check if there's a QMK-based project that works for your purposes, or could be used as a starting point. At the very least, you could check their docs to see which boards they use. Sparkfun's Pro Micro and Elite-C seem to be the most popular choices, at least for keyboards I was looking at.

      Beetle USB ATMEGA32U4 could be the smallest.

      • jwz says:

        I'm just working on a redesign of the payphone keypad, not a full keyboard, so QMK is probably overkill.

  5. codepilot says:

    Teensy works. Our (I work at SparkFun) pro-micro will work too.

    If you want - ping me at the email I reg’d with, give me a shipping address and an idea of what you’re doing, and I’ll send you a redbox of boards – least I can do for the decades of stories and Lucid->XEmacs…

  6. Dan Steingart says:

    I think the QT py ( gets it done, $6.00.

  7. larb says:

    Doable with RPi Nano for about 9 bucks, and it has the usual GPIOs, serial, wifi, etc. There's some code at for example.

    • jwz says:

      Using a Pi for embedded projects like this sounds to me like "your keyboard will take 2 minutes to boot, and will eventually corrupt it's file system because you didn't run shutdown."

      • Derpatron9000 says:

        Sadly, this is a thing. It's 2020 and people are building mechanical keyboards that require a raspberry pi to run, and are somehow happy with themselves for having achieved this overkill, grinning from ear to ear while they wait for their keyboards to boot up, prior to logging in and telling anyone who will listen about this fantastic waste of time and technology.

        • jwz says:

          It's kind of shocking to me that Rasbian doesn't have a default setting of "boot off of a 100% read-only file system". Configuring Linux to work that way was hellaciously difficult when I did it back in Y2K, but at least back then there was the excuse that almost nobody needed that. Today, it's likely that the majority of Rasbian installations would benefit from it.

          Also why isn't this shit instant-on by now? They should restore a RAM snapshot from the flash card like a laptop un-hibernating. The kernel has supported this for decades.

          • Derpatron9000 says:

            Sorry it took so long to reply, my desk had to reboot due to OS patching. Trying to talk to anyone in the raspberry pi 'community' about anything technical is a waste of effort. Even the 'harsware hackers' there are scared of basic soldering.

          • Line Noise says:

            The Pi4 only just got firmware support for booting off an external USB drive! I have a box full of SD cards that have been trashed by various Pis over the years.

          • margaret says:

            i had a pi that would corrupt filesystems left and right. asked the pi community what was up and the answers ranged from "that doesn't happen" to "that has never happened." figured out how to put a read-only filesystem in with in-memory tmp space and the problem went away. long boot times are still long boot times.

  • Previously