#+TITLE: Keyboard Project
#+OPTIONS: toc:nil num:3 H:4 ^:nil pri:t
#+HTML_HEAD:
Building my own keyboard.
The idea is to construct a frame based on the STL files of the Dactyl keyboard.
As the micro-controller I'm aiming to use an Arduino Uno board I have.
I'll call it: The Dactylino
* The plan
** The frame can be 3D-printed, it
* Components
** Keycaps
** 3D-printed frame
** Arduino
* Cost overview
Keeping track of expenses
| Item | Shop | Price | Price (DKK) |
|--------------------+---------------------------------------------------------------------------------------+-------+-------------|
| Keycaps | https://pimpmykeyboard.com/dsa-pbt-blank-keysets/ | $62 | 400 |
| Wires | | | |
| Diodes | https://elextra.dk/p/1n4148-sm%C3%A5signal-ensretterdiode-75v-50ma-do35/H13963 | | 45 |
| PLA Filament | https://3deksperten.dk/2kg-pirate-black-3de-premium-pla-2-85mm.html | | 300 |
| Cherry MX switches | https://mechboards.co.uk/shop/switches/cherry-switches/ | £50 | 410 |
| Soldering station | https://elextra.dk/p/loddestationss%C3%A6t-m-justerbar-temperatur-48w-150-480c/H48978 | | 345 |
| | | | |
| | | | 1500 |
#+TBLFM: $4='(apply '+ '(@2$4..@-1$4));N
* Programming the Arduino as a keyboard
** DONE Get the compilation and upload to work
There's multiple ways of doing this: Either use the Arduino IDE, use the
arduino-builder (which is deprecated in favor of arduino-cli) or just learn how
to use the avr-gcc toolchain. I'm going with the latter approach.
The arduino-builder is basically a make replacement for Arduino.
** DONE Build basic blink program
Initially, I built and transferred the simple Blink.ino sketch using the Arduino
IDE, then I tried using the [[https://github.com/arduino/arduino-builder][arduino-builder]].
Next, I figured I could setup a Makefile and found [[https://github.com/sudar/Arduino-Makefile][A Makefile for Arduino
Sketches]] which looks really cool, but I couldn't quite get it working. Besides I
don't need the ability to retarget the project to a different board, and if so,
I'd rather learn how to do it from scratch.
Then I found [[https://thinkingonthinking.com/an-arduino-sketch-from-scratch/][Building an Arduino sketch from scratch]] that (despite many errors
and omissions), actually explains how to build and transfer a sketch from
scratch, using avr-{g++,ld,ar,objcopy} and avrdude, which are the suite of
programs being used under the hood by both Arduino IDE and arduino-builder.
Lesson learned: The *.ino files are basically *.cpp files that are intended to
go in a special context. For example, if we have =main.ino= then converting it
to =main.cpp= is more or less doing this:
#+BEGIN_SRC
echo '#include ' > main.cpp
cat main.ino >> main.cpp
cat /usr/share/arduino/hardware/arduino/avr/cores/arduino/main.cpp >> main.cpp
#+END_SRC
Instead of doing that, I'll just build the =main.cpp= by hand.
** DONE Setup "ninja" as the builder
Now I've decided to setup the [[https://ninja-build.org/manual.html][Ninja build system]] for this project. Ninja is
nice, small and fast and it'll give me full control of the build process. Make
is good, but comes with many built-in variables and rules and I'd prefer not to
have to spend any time working around any issues with it.
See [[https://ninja-build.org/manual.html#ref_rule][the reference]].
** DONE Figure out how to read from the serial port
Running =screen /dev/ttyACM0 9600= allows receiving whatever is
=Serial.print()='ed. The biggest problem is exiting =screen=.
This should make for a good test-bed though, to ensure that all the keys are
working as intended prior to reflashing the board as a HID keyboard.
** TODO Program a small four-button keyboard
I found this small video explaining how to turn the Arduino UNO into a
four-button keyboard (using push buttons). I have all the components, so I just
want to try it out.
- https://www.instructables.com/id/How-to-Make-a-Arduino-HID-Keyboard/
- https://www.arduino.cc/en/tutorial/pushbutton
- https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/all
* Log
** <2021-01-31 Sun>
We have a working four-button keyboard! Thanks to Diego, we managed to get a 2×2
matrix keyboard working on the breadboard, exactly as I had wanted (minus the
diodes).
Couple of lessons:
- Pins 0 and 1 cannot be used for IO in conjunction with =Serial=, neither
=digitalRead()=, nor =digitalWrite()=. Bit of a bummer, it might mean I have
two fewer pins than I expected.
- The breadboard might have some loose connections, everything started working
as intended once two keys were shifted one row up each.
** <2021-01-16 Sat>
Last log entry was a bust in the end - one key worked, but four I couldn't get
working. I think concept is clear enough though, so I'm a little mystified by my
lack of success.
Also see: https://github.com/Chris--A/Keypad/blob/master/src/Keypad.cpp
** <2021-01-10 Sun>
The first small step towards programming the keyboard has been made!
Following http://gammon.com.au/forum/?id=14175 I have a one-key keyboard working
on the breadboard including the diode
1N4148 diode:
Anode ╭─────╮ Cathode
*─────│ ⇒ █│─────*
╰─────╯
One thing I think I've misunderstood about the diodes is that they are employed
to help prevent the backflow of current, so their "arrow" is mounted the
opposite direction of what I had visualized.
The gist is this:
- Input pins should be programmed as INPUT_PULLUP to utilize their internal
pull-up resistor
- Output pins (the pins that we scan) are programmed initially as INPUT
- When it comes time to scan a given row/column, set the corresponding output
pin to OUTPUT and =digitalWrite(.., LOW)= to it. Scanning the input pins to
see if any of them become low. The corresponding key is then pressed.
** <2020-11-21 Sat>
The 3D-printed parts are finally done! I have cleaned the supports of all the
parts and couldn't wait to assemble the parts, so I've inserted key switches in
all
** <2020-10-03 Sat>
I'm starting to realize that maybe the Arduino doesn't have enough digital pins
to support the full keyset of the Dactyl keyboard, and I may have to go for a
Teensy 2.0.
It'll still be useful to learn the grid programming.
** <2020-10-09 Fri>
The Arduino has 20 pins in total which /should/ be enough pins. Basically, the
matrix layout requires M columns and N rows to support M×N keys.
The basic idea is to loop through the columns, write a =HIGH= to it, do a
=digitalRead()= on each row to see if any of those keys were pressed.
** <2020-10-11 Sun>
See https://deskthority.net/wiki/Keyboard_profile for a description of the
different keycap profiles
Could consider getting a set of keycaps from https://mechanicalkeyboards.com/shop/index.php?l=product_detail&p=6874
https://pimpmykeyboard.com/dcs-pbt-blank-keysets/
** <2020-10-25 Sun>
I ordered keycaps from [[mechboards.co.uk][mechboards.co.uk]], 80 pcs of Cherry MX blues. I should
need 76 in total, so there's a couple to spare.
The first of four parts has been 3D-printed! It's the left-hand side, upper part
that holds the keys. I have a couple of Cherry MX browns lying around and they
fit snugly in the frame.
* References/resources
- [[https://www.pjrc.com/teensy/][Teensy USB Development Board]]
- [[https://www.elextra.dk/komponenter/spray-printfremstilling/hulprint][Elextra Hulprint]]
- Matt3o [[https://deskthority.net/viewtopic.php?f=7&t=5761&start=][Building a custom keyboard from the ground up]]
- Matt3o [[https://matt3o.com/hand-wiring-a-custom-keyboard/][Handwiring a custom keyboard]]
- [[https://hackaday.com/2019/09/27/the-zen-of-mechanical-keyboard-wiring/][The Zen of Mechanical Keyboard Wiring]]
- https://github.com/adereth/dactyl-keyboard Dactyl keyboard]
- https://www.thingiverse.com/thing:3815317 [Ex-Dactyl keyboard]
- https://www.thingiverse.com/thing:2523675 [Dactyl keyboard]
- https://www.thingiverse.com/thing:1702966 [Dactyl keyboard]
- [[https://wiki.gentoo.org/wiki/Arduino][Gentoo Wiki: Arduino]]
- [[http://hackqiang.org/2017/07/24/e6-9b-b2-e9-9d-a2ergodox-dactyl/][Qiang's Life]] [ergodox--dactyl]
- https://deskthority.net/viewtopic.php?f=7&t=6050&start= [brown fix step by step]
- https://medium.com/swlh/complete-idiot-guide-for-building-a-dactyl-manuform-keyboard-53454845b065
- https://docs.qmk.fm/#/
- https://docs.qmk.fm/#/hand_wire?id=wiring-the-matrix
- https://www.dribin.org/dave/keyboard/one_html/
- http://gammon.com.au/forum/?id=14175
* Other interesting references
- https://www.eurocircuits.com/