In this post, we’ll have a go at assembling our very own hardware controller for Switch access on Android. Let’s start by going over what Switch access is, and why it’s useful.
What is Switch access?
Switch access lets you interact with your Android device using one or more switches instead of the touch screen. Switch access can be helpful for people with dexterity impairments that prevent them from interacting directly with the Android device.About Switch Access for Android – support.google.com
Switch Access works by assigning actions to buttons. Commonly, switches are sold in two-button configurations, with one button assigned to “scan” (for navigating through the screen) and the other button assigned to “select”.
On Android, we can enable the Switch Access service from system settings, and with the “Assign switches for scanning” menu, we can associate a button with an action.
To get started, we don’t need an external device: you can assign your phone’s volume buttons e.g. “volume down” for “Next” and “volume up” for “Select”.
Here’s a demo of this in action:
For more information about making your app accessible with the Switch access service, check out this article by Rebecca Franks.
Since we can assign any key event to these actions, it means that it’ll work with any external USB keyboard too. We just need to make a device that sends key events!
What we’ll need
The knob (an incremental encoder with a built-in pushbutton). The picture here doesn’t have the knob itself (it just slots on top):
For our custom input device, we want send the “DPAD_RIGHT” key event when we rotate the knob clockwise, and the “DPAD_LEFT” key event when we rotate counter-clockwise.
If we push the knob in, we want to send the “ENTER” key event.
A TeensyLC (this is the bit that we’ll upload our program to):
It’s really small (teensy).
Female-to-male jumper strips (5 wires is enough). Since the knob has 5 pins, we need 5 jumper cables. Using the female-to-male variants, we can use the female side on the pins directly, and then solder the male side into the TeensyLC.
(I already had female-to-female and male-to-male cables, so I used these):
Rather than solder the wire directly to the board (and risk goofing it up), we can just bend them around the contact points for now.
It would be a good idea to grab a micro-USB to USB Type-C cable too – the TeensyLC has a built-in micro-USB port, and the USB Type-C end will make it useful to plug into a new-ish Android phone without using an adapter.
Getting started with the TeensyLC
I started by installing the Arduino IDE and Teensyduino. I had to use Arduino 1.8.2 and Teensyduino 1.36 to get everything working correctly.
I didn’t start with the knob initially—I had some arcade-style push buttons lying around that I could use to get my bearings before I spent more money.
Connecting the knob to the TeensyLC
There’s 5 pins from the knob. I searched for KY-040 and found this tutorial on hooking it up to an Arduino. The only difference is that I also wired the middle pin for the push-button switch.
The tutorial also included some code that formed the basis of what I ended up with here:
The last part will be soldering the wires to the board and housing it nicely. It’s almost certainly never going to happen.