Introduction: Gongbutton: Big Button to Control Your Gongs
At the Stripe office, there's a tradition of ringing a gong at meal times. As we grew, I built a cluster of networked robotic gongs to keep the tradition alive throughout the office (see instructable for Gongbot). The Gongbutton sits in the kitchen to trigger all of the Gongbots.
Gongbutton shares much of the design of Gongbot but is built into a fun big button case and plays a gong sound when the button is pressed. It's based on the Spark Core, connects over WiFi and communicates via an MQTT message broker.
Note that the Gongbutton isn't much fun without a Gongbot to go with it!
Step 1: Parts, Tools and Software
- Button: Learning Resources Answer Buzzers
- Spark Core: Spark has since released a cheaper/better version called the Photon but the code won't be immediately compatible.
- 2N2222A NPN transistor
- 2.2k resistor
- USB power adapter / wall charger
- Drill and 1/8" bit
- Dremel and various attachments
- Soldering iron and solder
- Various basic hand tools
- Spark command line client
dfu-util: I installed it via Homebrew on OS X
Gongbot firmware: See the attached bin file or look on github.
Serial terminal: minicom, screen or Putty should all work though I found minicom easiest to work with.
Note that you may choose to build the firmware from source to get the latest version. You should be able to find instructions for setting up a build environment in the Spark documentation. You can find the source and its dependencies at these links: spark-gongbot, spark-core-communication-lib, core-common-lib.
Step 2: Modify the Button
The button needs space for the Spark Core with a hole for the USB port. I chose to use the space usually reserved for batteries to fit the Core. Use a Dremel to cut out a slot for the board as shown in the picture. Try to leave the fit somewhat snug to avoid the Core wiggling around too much after assembly. You may also want to drill small access holes for the two buttons on top of the Core to allow for reprogramming.
Carve out space for the USB port in the black rim of the button taking care to align the small plastic notch in the rim. I used a small drill bit to start the hole and a Dremel to carve it out to size. Note that you'll have to take some plastic off the inside of the black ring with your Dremel to get the Core to fit properly.
When done, you should be able to fully reassemble the button with the Core inside and power it up via USB.
Step 3: Electronics
The Gongbutton uses a 1-bit DAC and a simple single transistor amplifier to power the speaker. You can learn a bit more about the design principles at Makezine. I found through trial and error that a 2.2k resistor worked well with the 2N2222A transistor I used. You can do much better than this design as far as amplifiers go though I'm not sure how much it would help given the quality of the speaker. The low pass filtering didn't seem to help the sound quality so I excluded the capacitor from the final design.
The audio itself is a PCM-encoded wave file built into the firmware binary.
Prepare the Spark Core
Out of the box, the Spark Core comes with header pins that are great for prototyping but won't fit in the enclosure. Remove the black plastic spacer at the base of each set of pins then carefully desolder and remove each of the 24 pins from the Core. I found this to be a slow process with a soldering iron and needle nose pliers.
Connect the electronics
Remove the jumpers (little black components with "0"s on them) from the original button board. Connect up the components as follows. Make sure everything fits when the button is assembled!
- Button pin 1 (VDD) - Spark GND
- Button pin 2 (near the jumpers) - Spark D4
- Resistor - Spark A7
- Transistor Base - Resistor
- Transistor Emitter - Spark GND
- Transistor Collector - Speaker Pin 1
- Speaker Pin 2 - Spark Vin
Note that I ended up debugging for awhile after taking the picture above. The pinouts/parts in the description are correct even if they don't quite match the picture.
Step 4: Flash, Configure and Gong!
Flash the firmware
Follow Spark's directions for setting up the command line client. Connect the Spark Core to your computer via USB. The LED should come on and then nothing should happen. Hold down both buttons on the Core. Release the RST button. When the LED starts flashing yellow, release the MODE button. Run "spark flash --usb core-firmware.bin" from the command line. You should see a series of text and then progress dots while the flashing is in progress. You may get a poll timeout error message at the end of the process -- that's a known Spark bug but not a problem.
Configure the core
Run "spark serial list" to find the serial port or device file associated with your core. On OS X, mine was "/dev/cu.usbmodem1411". Connect to your core using your serial terminal. With minicom I use the command "minicom -D /dev/cu.usbmodem1411".
Press RST. A 2-3 seconds after resetting, press Enter in your serial terminal to start device configuration. You'll be asked for the following:
- App type: Enter "1" for button.
- MQTT Host: The hostname of an MQTT broker (e.g. m2m.eclipse.org)
- MQTT Port: The port of the MQTT broker (e.g. 1883)
- Root topic: An MQTT topic that your Gongbutton will publish on and subscribe to (e.g. /instructables/gongbot). Gongbots that share the same root topic will ring. It must start with a trailing slash and cannot end with one.
- Name: A unique name for your Gongbutton. This name can be used by other software you have listening such as an IRC bot.
At this point, the serial port will reset and the button will enter WiFi config mode. Press "w" to write a new WiFi configuration and follow the prompts. If you've already configured the WiFi, you can press RST to skip this step.
- SSID: Name of your WiFi network
- Security: Note that Spark indicates they've had problems with WEP networks.
- Password: Password used to connect to your network.
The LED on the Core should eventually start pulsing cyan indicating that it is online. Aside from the use of cyan to indicate a connection with the MQTT broker, the other colors should match the Spark documentation. Each time the Core boots up, the LED will transition through the following colors:
- White: Starting up
- Blue: Searching for WiFi
- Green: Connected to WiFi
- Cyan: Connected to the MQTT broker.
With the LED pulsing cyan, press the button. Your gongs should ring!