Guide: Pill Button
This guide shows how you can build a cool Bluetooth-enabled general-purpose button housed in a pill bottle. The button can easily be programmed to function as a remote button for the Shared Game Timer (or anything else). The button has a programmable RGB LED that can for example show the current player's color.
In this guide, we will make a programmable button housed in a standard pharmacy pill bottle, something probably a lot of people have lying around, at least in the United States.
It will have a single button which we can program to do 'stuff' when pressed, double pressed, long pressed and so on. Of course, the way I intend to use it is as a remote control for the Shared Game Timer, but you can make it do anything you like over Bluetooth.
We will also make the button backlit by a programmable LED light, so the button can change color, perfect to show who the current player is!
The main component is of course the pill bottle itself! I found one lying around at home, and hopefully you do too. Especially if you live in the US, they seem to be in every home. If not, ask around at a pharmacy.
The bottle I used is 73mm tall (not counting the lid) and has an inside diameter of 30mm. Getting the exact measures right is less important if you go with the final 'button in lid' approach. If you want to try the lidless option, then try fitting the arcade button into the bottle before you do all the other assembly.
Below is the shopping list for the electronics. You will also need soldering equipment. Check out the Adafruit Guide to Excellent Soldering for help on that.
Wiring up the circuit board
Check out this excellent guide on how solder wire to the pin holes. You'll be doing it quite a bit in this project.
The Power Switch
Shorten two of the legs on the power switch and solder wires to them, adding heat shrink afterwards. The third leg can be cut off entirely.
Next, cut the trace on the LiPo Backpack and then solder the power switch into the now separated pin holes.
The images show me doing this when I had already soldered the backpack to the ItsyBitsy, which made the soldering much harder! Do it the easy way and do this first before attaching it to the ItsyBitsy!
Connecting the Backpack to the ItsyBitsy
The backpack is made to sit on top of ItsyBitsy boards such that the header pins that come with it connects the two boards' power, ground and battery pins. Only, the Bluetooth ItsyBitsy has a couple of buttons that will get covered. Not a big deal since we only need to press the reset button once in order to load the CircuitPython boot loader. And, there is just enough clearance to still press the buttons if need be.
(in fact, skip ahead and load the CircuitPython bootloader before attaching the backpack.)
After we have soldered the two boards together, we use flush diagonal cutters to trim off the header pins but leave the Ground Pin uncut! This is the only ground we have on the ItsyBitsy, and we will need to run a wire from it to the button. In fact, you might as well solder that wire onto the pin right away, adding a heat shrink to it after you are done for stability.
Assembly without a lid
We have the button and the circuit board, both with loose wires hanging off them. It is now time to wire them together.
How long the wires should be is a matter of taste. Too long, and you start having crammed space inside the bottle. Too short and you might not have enough room to maneuver the board into the right place inside the bottle. I think I went a little short on my wires, but it works.
|ItsyBitsy||Button / NeoPixel|
|G||Button & NeoPixel Ground|
|5!||NeoPixel Signal In|
You must wire the special signal pin 5! to the NeoPixel Signal In because it operates at the same voltage as the Vhi pin.
You can use any GPIO pin for the button switch. I picked A2 because it was in the middle of the ItsyBitsy, so no matter how I insert it into the bottle, the length of the wire will be OK.
Once it is all wired up, simply insert it all into the bottle! It turned out that the size of the bottle I have was exactly right for the arcade button! Simply screw the button in like you would the lid. The plastic 'springs' on the side will hold on the to screw groves of the bottle. To open, simply screw it the other way. Magic!
Well, it was, until the plastic 'springs' one day snapped off. To fix it, or if your bottle doesn't fit as nicely, use the lid option below.
Assembly with a lid
If you have a bigger bottle, or the plastic springs break off, you can easily attach the arcade button to the lid of the pill bottle. You can then open and close the bottle simply by screwing and unscrewing the lid!
Somehow cut a hole in the lid. I used a dremel to first saw off the top part of the lid, then filed down the edges to make the hole just big enough for the button to slide in.
My hole was tight enough that the button stayed in place by friction alone, but a few drops of superglue under the lip of the button would have done the trick otherwise.
Programming the Pill Button
We will be programming the Pill Button using Circuit Python. Please follow
the setup guide
until you are ready to edit the
Download and copy this code.py file to your board. You will also need to install the
libraries imported at the top of the file, as well as edit the fields under
# Constants and Setup
When the code is saved, you should see the pill button blink blue, meaning it is ready to be connected to.
Connecting it to the Shared Game Timer
The Shared Game Timer Bluetooth connectivity is quite open-ended, able to connect to many different devices
This flexibility also means that the process of setting it up can be a bit confusing. Below is both a written guide as well as a video walking through the steps.
Go to any Shared Game Timer game (feel free to create a toy one just to try it out), open the menu, open the Remote Control menu and click into the Bluetooth LE page.
Click the Device Configuration link.
If you have not yet added the Nordic UART service, click the Add New Service button, enter 6e400001-b5a3-f393-e0a9-e50e24dcca9e as the UUID, pick a nickname and then Save.
You should now see the Service in the list of services. Click the button and you should be asked to connect to the Bluetooth device. Assuming the pill button is still blinking blue, you should see it available named something like 'Pill Button' or 'CIRCUITPY'. Click it and then Pair.
You should now see two sections, Write Script and Action Mapping. Let's do them in order.
Where it says 'Write Script', enter this:
What it basically says is, "0 milliseconds after triggering, send the current game state,
color and current turn time, followed by the new line character. For example, it might send
pl;ff0033;15000 . Give it a name (e.g. Adafruit Game Update) and hit Save.
Now look at the Action Mapping section. You should see the word 'Connected', which is the first thing the code we put into the Pill Button will send once it connects. Now, try pressing the button once. You should see 'Short Press 1' appear. Try long-pressing it. You should see 'Long Press 0' appear. How about pressing it twice in quick succession then end it with a long press? You should see 'Long Press 2'.
This section shows all the events sent from the Pill Button to the Shared Game Timer. Now it is up to you to decide which events should correspond to which actions in the Shared Game Timer. Here is my suggestion, but you can enter whatever you want.
|Short Press 1||End Turn|
|Short Press 2||Pass|
|Long Press 0||Toggle Admin|
|Long Press 1||Toggle Pause|
Note that these are evaluated in order, so the final entry, Long Press, will match Long Press 3, Long Press 4 and so on. Basically, hit the button several time and then long press to undo.
We are now all done to use the button! Go back to the Bluetooth Remote page, and you should see the Write Script and Activation Map we just created. Activate both. For the Write Script, click the 'Tick all checkboxes' button, and also tick the 'Whenever target state becomes active' as well as 'When Polled'. Finally, click Connect and you are now DONE! 🥳
To turn the button on or off, or to program it, you must open the lid and pull out the insides. It would be nice to make a small hole in the bottom of the bottle and set the power switch there, or possible a small hole for the USB connection.
Also, I tried to fit a vibrating motor disk or a small speaker into it to provide some feedback other than light, but there wasn't enough space. A larger bottle might accommodate this however.