It would be neat to have a dedicated key to mute myself in these ever-present video meetings. I don’t have a lot of clues when it comes to electronics, but this was an interesting first project with a PCB of my own.
What I was looking to make was:
- a simple USB keyboard with 1 key
- mechanical keyboard key
- cheap enough to give away
The last item was probably just a self-justification - if I make a board, I might as well make a bunch of them. If I make a bunch of them, I can’t possibly use them all myself. Selling electronics sounds like a hassle, therefore I’ll just give them away. Yay, nice-guy-me (but actually just justifying things for fun).
I succeeded with most of these, but realized along the way that I also want things like “debuggable” and “works on most computers.” Details.
Taking the cheapest of my Arduino-boards that supports USB keyboards (it was something like the Digispark), looking at the schematic, I came up with a version of my own. It works, which surprised me, but programming with Arduino on an ATTINY85 is such a hassle.
The design is here on EasyEDA. They’re 26mm in diameter, nice & small.
I had these made by JLCPCB - who also runs EasyEDA. I have no idea what I’m doing, and I managed to get them made. One difficulty I ran into was that JLCPCB doesn’t have USB ports that they add, so I had to find a USB port that I felt comfortable with soldering myself.
There are so many connectors:
I picked the ones with the weird ox-horn in front. While not great to use as-is, you can easily remove the bar and still solder it fairly rigidly to a board.
It turns out, you have to practice soldering these a bit, especially if this is your first tiny thing to solder, and having something to zoom in (like a microscope) helps a lot :-).
I splurged. $2 for 5 PCBs. $21 for the parts & assembly of 5 boards (+ the USB connector separately). It took me a long time to feel comfortable with the layout enough to order the parts. When I saw the final prices I realized I could have just tried it out earlier.
JLCPCB is easy to use & super-cheap. The site isn’t perfect and flakes in weird ways sometimes, but it’s basically upload file, adjust settings, get printed circuit boards. Who knew making electronic designs was this easy? I thought I’d have to order tons of equipment, chemicals, etc – it’s all so trivial nowadays.
Like I mentioned, USB ports are hard when you first get started. I ended up messing 2 boards up, but fixed one with an extra wire to the back. Oy. Messy.
The code & details are on Github. I tried to use the Digispark-like setup as much as possible. I used the Micronucleus bootloader. The firmware uses V-USB, which I thought would be suitable, but it turns out it’s a bit hit & miss.
What threw me off the most - apart from that it just doesn’t always work - was that the ATTINY85 is so, well, tiny, and limited.
In particular, I can’t use the serial USB output while using the USB keyboard functionality, which means debugging essentially happens in the blind. The only debugging output I had was the LED on the board.
Blink twice if you’re ok.
At this point, I saw two routes:
- Figure out low-level ATTINY programming with C, learn how to write USB keyboard code manually
- Move to a hardware platform that supports USB natively
Writing all of these things manually is probably possible, but the uncertainty + the unknown amount of hassle pushed me towards something that supports USB natively. Checking the other Arduino’y boards (something I was familiar with), the ones using ATMEGA 32u4 chips seemed to be the smallest & cheapest. There are also STM chips (and probably others) which support USB natively, but that would have meant moving away from Arduino environment.
Designing ATMEGA 32u4 boards is a bit more complex though.
Looking back, I think the MCU choice (ATTINY85) was bad.
There are various forum posts that point at the ATTINY85 being not that great for USB keyboards, and none of the USB keyboards (that I found) use them.
I could probably make the hardware a tiny bit more stable by adding capacitors here & there (considering how they’re often used on all power pins of a MCU).
I don’t think I’d be able to make these work well as USB keyboards even with a lot of low-level coding though.
(And honestly, lots of low-level coding with minimal ways to debug sounds terrible.)
Weirdly enough, there are a bunch of ATTINY85-based USB keyboards on blogs, just none (at least that I noticed) used for higher quality keyboards.
The other thing is that with an 8-pin MCU, you’re extremely limited in the number of inputs and outputs. Two go for the USB port, 1 for the button, 1 for the LED, that leaves 1 for something else. Not really a lot of room for expansion (two buttons! colored LEDs!).
The other hardware components (resistors, LED) worried me a bit too, but they seemed to work, and the size 0603 is not as tiny as I thought. (Various sized components, if you’re curious. 0603 components are approximately 1.6mm x 0.8mm. People can still hand-solder them, which is what I was looking for. Some people even hand-solder 0402 components, but look at what I did with the USB connectors, haha.)
Next up in this adventure is the Atmega 32u4 version.
Comments / questions
There's currently no commenting functionality here. If you'd like to comment, please use Twitter and @me there. Thanks!