---
deprecated: true
excerpt_separator: <br />
category: technology
layout: post
title: 'The Orange Box: A custom USB Flight Control Panel'
date: '2015-11-06T11:05:00.000-05:00'
author: Anna Wiggins
tags:
- Programming
- electronics
- 'Elite: Dangerous'
- maker
- diy
- Technology
modified_time: '2015-11-06T11:05:16.611-05:00'
thumbnail: http://4.bp.blogspot.com/-DAZG1CkJy9s/VjphmdMmBZI/AAAAAAAAG_s/8R2F-hNYIEw/s72-c/single_switch.jpg
blogger_id: tag:blogger.com,1999:blog-4209116010564764361.post-9195320296970552731
blogger_orig_url: http://www.stringofbits.net/2015/11/the-orange-box-custom-usb-flight.html
---

I play a lot of <a href="https://www.elitedangerous.com/" target="_blank">Elite: Dangerous</a>. And while I use a reasonably nice <a href="http://www.amazon.com/Saitek-X52-Flight-System-Controller/dp/B000LQ4HTS" target="_blank">HOTAS</a>, I've long wanted a flight panel: a bank of toggle switches with LED indicators that would act as a USB joystick. I can only find one company <a href="http://www.desktopaviator.com/Products/Switch_Array/index.htm" target="_blank">selling such a thing</a>, and their solution leaves exposed wiring. (a no-no when you live with cats) Also, their website looks like it is from the 90s and just feels kind of sketchy. (Seriously, guys, if you happen to read this, your website does not inspire confidence)<br /><br />And, anyway, I've been looking for an excuse to learn some basic electronics for a long time. So, I built my own! Several other people have built similar things, but I decided to jump in head-first and not follow any guides, in hopes of learning about electronics and wiring along the way.<br /><br /><h2>Acquiring Gear</h2>First up, a parts list:<br /><br /><ul><li><a href="http://www.amazon.com/gp/product/B00B4ZQ3L0?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s01" target="_blank">Wire</a>! Stranded, 22 AWG wire is perfect for general hobbyist electronics work.</li><li>An <a href="http://www.amazon.com/gp/product/B00E5WJSHK?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s01" target="_blank">Arduino board</a>, and an accompanying <a href="http://www.amazon.com/gp/product/B0076FWAAK?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s04" target="_blank">sensor shield</a>. (But see my lessons learned section)</li><li><a href="http://www.amazon.com/gp/product/B00CO87DD8?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s01" target="_blank">3-pin dupont connector housings</a>&nbsp;combined with the sensor shield make it possible to wire each switch in a modular way.</li><li><a href="http://www.amazon.com/gp/product/B00X9W87XS?psc=1&amp;redirect=true&amp;ref_=od_aui_detailpages01" target="_blank">Female dupont connector pins</a> or else the housings are useless.</li><li>Some <a href="http://www.amazon.com/gp/product/B010UIW82E?psc=1&amp;redirect=true&amp;ref_=od_aui_detailpages01" target="_blank">LEDs</a>, and accompanying <a href="http://www.amazon.com/gp/product/B00P3FMGP4?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s00" target="_blank">LED holders</a>.</li><li><a href="http://www.amazon.com/gp/product/B00P3FMGP4?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s00" target="_blank">Toggle switches</a>, the satisfying clicky heart of the project.</li><li><a href="http://www.amazon.com/gp/product/B003E48ERU?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o04_s00" target="_blank">Resistors</a>.</li></ul><div><br /></div><div>And a partial list of tools I needed:</div><div><ul><li>A <a href="http://www.amazon.com/gp/product/B00DHCRVSC?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o06_s01" target="_blank">crimping tool</a>.</li><li>A <a href="http://www.amazon.com/gp/product/B000NPT5TO?keywords=needle-nosed%20pliers&amp;qid=1446664371&amp;ref_=sr_1_1&amp;sr=8-1" target="_blank">wire stripper</a>.</li><li>A <a href="http://www.amazon.com/J-L-SI60-Watt-Soldering/dp/B0006NGZK0" target="_blank">soldering iron</a>, and <a href="http://www.amazon.com/Kester-Pocket-Pack-Solder-0-031/dp/B00068IJNQ/ref=pd_sim_469_1?ie=UTF8&amp;dpID=31-IEj9o8CL&amp;dpSrc=sims&amp;preST=_AC_UL160_SR160%2C160_&amp;refRID=1ACK2379SKPG2V3BA0E0" target="_blank">several</a> <a href="http://www.amazon.com/gp/product/B00FZPGDLA?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o04_s00" target="_blank">accompanying</a> <a href="http://www.amazon.com/gp/product/B003E48ERU?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o04_s00" target="_blank">accessories</a>.</li><li>Smallish <a href="http://www.amazon.com/gp/product/B000NPT5TO?keywords=needle-nosed%20pliers&amp;qid=1446664371&amp;ref_=sr_1_1&amp;sr=8-1" target="_blank">needle-nosed pliers</a>.</li><li>A drill. (a Unibit came in particularly handy)</li><li>A router. (In future iterations, I'll try to get away without one of these)</li><li>A screwdriver.</li><li>A 3D Printer (but see lessons learned!)</li><li>Some nuts and bolts for binding everything together.</li><li>A <a href="https://www.sparkfun.com/products/112" target="_blank">breadboard</a>, with <a href="https://www.sparkfun.com/products/11026" target="_blank">jumper wires</a>&nbsp;and these really useful <a href="https://www.sparkfun.com/products/13191" target="_blank">jumper/alligator clip wires</a>.</li></ul></div><h2>Getting Started</h2><div>Ok, now that you have this big pile of stuff, what do we do? I started by emulating everything; I was a bit worried about frying my new Arduino board! So I designed a circuit using <a href="http://123d.circuits.io/">123d.circuits.io</a>. You can see it <a href="https://123d.circuits.io/circuits/1160849-led-switch-input" target="_blank">here</a>. Connecting the switch turns on the LED and changes I/O pin 2 from high to low. (the pin is configured as INPUT_PULLUP, see the programming section later)</div><div><br /></div><div>Next I replicated this with my physical tools. I started by wiring everything up, (you'll want those hybrid jumper/alligator wires to hook up the toggle switch!) then plugged my Arduino into the PC to give it power. Before throwing the switch, I uploaded this very simple sketch to it:</div><div><br /></div><blockquote class="tr_bq"><span style="font-family: &quot;courier new&quot; , &quot;courier&quot; , monospace;">void setup() {<br />&nbsp;&nbsp;pinMode(2, INPUT_PULLUP);<br />&nbsp;&nbsp;pinMode(13, OUTPUT); // this is the Arduino's on-board LED.<br />}<br /><br />void loop() {<br />&nbsp;&nbsp;int state = digitalRead(2);<br />&nbsp;&nbsp;if (state == HIGH) digitalWrite(13, LOW);<br />&nbsp;&nbsp;else digitalWrite(13, HIGH);<br />}</span></blockquote>If this works as expected, then flipping the toggle switch should light up both the breadboard LED <i>and</i>&nbsp;the on-board LED (marked 'L' on the Arduino board). The logic is inverted (we write HIGH when we read LOW) because I'm using INPUT_PULLUP, which reverses the usual logic of the input pin. (This lets me wire the LED without worrying about how much current the input pin can sink. I'm probably being overly cautious here, actually.)<br /><br /><h2>Building the thing</h2>Now that I had a proof of concept, I moved on to building things in earnest. First, I needed a box to store it all in. I had trouble finding an appropriately-sized box (again, see "lessons learned"), so I decided to 3D Print one! I have access to a shared Ultimaker2 3D printer. So I <a href="https://tinkercad.com/things/eVYt2DODJ2c" target="_blank">designed and printed</a> a box. <b>I really don't recommend using this design</b>. This was my first attempt ever at 3D printing. The print took about 13 hours, and the resulting box had a bunch of problems, despite my attempt to make careful measurements. I had to drill out the holes for the switches more, and had to hack up the back pretty badly to get the USB port out. I also neglected to put mounting posts in for the lid, (I <a href="https://tinkercad.com/things/cZhLgvGRaKO" target="_blank">printed some</a> later, but it was a huge pain) or holes to mount the arduino board on. (The odd bumps on the inside and the plastic bar were meant to be a little physical barrier to hold the board in place, but they printed out way too low to actually do anything.)<br /><br />So anyway, now I have a box. (the project quickly got nicknamed <a href="https://en.wikipedia.org/wiki/The_Orange_Box" target="_blank">The Orange Box</a>, naturally) Next, I created five of these, with varying LED colors:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-DAZG1CkJy9s/VjphmdMmBZI/AAAAAAAAG_s/8R2F-hNYIEw/s1600/single_switch.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="http://4.bp.blogspot.com/-DAZG1CkJy9s/VjphmdMmBZI/AAAAAAAAG_s/8R2F-hNYIEw/s320/single_switch.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">This is just the design from the breadboard realized in a way that lets it interface with the Arduino sensor shield. The red wire is connected from 5V through the LED setup and onto one of the switch posts. The LED has a resistor in series with it; I used 1kΩ resistors for my red and yellow LEDs, and 10kΩ for blue and white.&nbsp;</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">The other switch post has lines going to both Ground (black) and the input pin. (white) The wire splices and connections are all soldered, *except* for the 3-pin dupont casing. To make those connections, I had to learn to work with dupont pins, which is a little complicated. You have to:</div><div class="separator" style="clear: both; text-align: left;"></div><ol><li>Strip the end of your wire.</li><li>Twist the exposed wire strands together. (this is often a good idea when working with stranded wire)</li><li>Lay the wire onto the 'open' part of the dupont pin, and push it in a bit. Ideally you want the bottom of the pin to be flush against your wire casing.</li><li>Fold the metal flanges on the pin around the wire with needle-nosed pliers, so that it's semi-closed.</li><li>Crimp those flanges down with a crimp tool. Be careful not to crimp the 'top' half of the pin, where you don't have wire. You'll need that to mate the pin with the headers on the board.</li><li>Using the pliers again, squeeze the metal that was flattened by the crimp tool into a rounder shape.</li><li>Insert the pin into the casing. (For this project, I hade to make sure the voltage line was in the middle, to match the pinout on the shield) There is a correct orientation but it's a bit hard to describe. The pin should click into place and not come back out easily.</li></ol><br />It takes a little practice to get the hang of it, but not having any connections soldered directly onto the Arduino makes it a lot more reusable!<br /><br />Once I had all 5 of these, I mounted them in the box and wired them onto the sensor shield (which was connected to the arduino board. It just plugs right in on top!) With the 3-pin dupont widgets, this was super easy:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-VcAUUzzJjvo/Vjpk5Cj_2RI/AAAAAAAAG_4/B7UvHThl-DM/s1600/wiring.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="http://1.bp.blogspot.com/-VcAUUzzJjvo/Vjpk5Cj_2RI/AAAAAAAAG_4/B7UvHThl-DM/s320/wiring.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><br /></div>Those 3 rows of pins are just a row of Ground, a row of 5V, and then a row for all the I/O pins. So the white wires are all on the bottom row (the input signals), and the black wires are on the top. Each row is labelled on the board: G, V, and S.<br /><br /><h2>Programming the Thing</h2><div>For me, this was the easy part. Familiar territory. Arduino's "IDE" is really just a slightly specialized C++ framework. I wanted the OS to treat my device as a joystick with as little hassle as possible, so I used this <a href="https://github.com/harlequin-tech/arduino-usb" target="_blank">custom firmware</a> for the Arduino's USB communication chip. (Note: you want to install that *last*, because while it's installed you can't upload new sketches to the Arduino. It's easily reversible, though, so you won't ruin anything.)</div><br />I wrote a simple&nbsp;<a href="https://github.com/annabunches/arduino-joystick" target="_blank">library</a> to interface with the Joystick firmware, and a <a href="https://github.com/annabunches/arduino-joystick/blob/master/examples/switch_panel.ino" target="_blank">sketch</a> tailored to how I have my inputs setup and what I want them to do. The sketch interprets the toggle switches as momentary inputs; that is, it sends a short button-press event every time you toggle the switch, as opposed to "holding down" the button the entire time the switch is on. This design makes it work well with most of Elite: Dangerous' controls.<br /><br />In a future iteration I hope to make this all a bit more generalized and include a lot more functionality in the Joystick library. But for now, this works really well!<br /><br /><br /><h2>The Finishing Touches</h2><div>I printed some support structures to make it possible to screw the box (mostly) shut:</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-SWaOGh4It64/VjppoceaS-I/AAAAAAAAHAQ/-_XXnrRcTRo/s1600/support_posts.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="http://3.bp.blogspot.com/-SWaOGh4It64/VjppoceaS-I/AAAAAAAAHAQ/-_XXnrRcTRo/s320/support_posts.jpg" width="320" /></a></div><div><br /></div><br />After putting these in place, I briefly lamented not printing counter-sunk screw holes into the box, but then I realized ABS plastic was soft enough that I didn't need them. All I had to do was tighten the screws a bit more, and:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-SndCSTVEy2s/VjppzQ_hKnI/AAAAAAAAHAY/Og0Ggm-AIFc/s1600/countersink.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="http://3.bp.blogspot.com/-SndCSTVEy2s/VjppzQ_hKnI/AAAAAAAAHAY/Og0Ggm-AIFc/s320/countersink.jpg" width="320" /></a></div><br /><br />And finally, with everything screwed in place, the finished product:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-68j8fKHkocI/Vjpp-6QjcrI/AAAAAAAAHAg/q_Yhtu6PBT0/s1600/final_product.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="http://4.bp.blogspot.com/-68j8fKHkocI/Vjpp-6QjcrI/AAAAAAAAHAg/q_Yhtu6PBT0/s320/final_product.jpg" width="320" /></a></div><br /><br /><h2>Lessons Learned</h2><ul><li>3D printing the project box sounded super cool, but I wouldn't do it again. It took too long, the resulting plastic is a bit weak for the job, and getting the hole placement just right was a pain. (and 3D printed parts don't take especially well to drilling) For my next iteration of this box I've purchased a pre-made <a href="http://www.amazon.com/gp/product/B0002BSRIO?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o01_s03" target="_blank">project box</a>.</li><li>If I <i>were</i> to 3D print again: remember to put screw-holes and posts in!<br />Mounting the LEDs was a bit of a problem, since the LED holders assume you're wiring them in place. I couldn't use their intended mounting setup, and had to just hot-glue them into place instead. This happened because the LED holders were back-ordered, and didn't arrive until late in the project.</li><li>Soldering is fun, but moderately permanent. For future projects I'd rather invest in connectors that are slightly easier to disconnect. I bought a bunch of <a href="http://www.amazon.com/gp/product/B00HUOZEVY?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o01_s03" target="_blank">these</a> in the hopes that the female connectors can mount to switch/button terminal posts. (early tests suggest they will work well)</li><li>The Arduino Uno R3&nbsp;+ sensor shield is nice, but the total package is a bit big. I later discovered the <a href="http://yourduino.com/sunshop2/index.php?l=product_detail&amp;p=429" target="_blank">Yourduino Robored</a>, which has the same 3-row pinout as the sensor shield, but in a much smaller (and cheaper) package. I ordered a couple of these and intend to use them in future projects. One downside: they ship from Hong Kong and take a while to arrive.</li><li>In the quiet of night (when I often play Elite) these toggle switches are loud enough to wake up and scare my housemate! I bought a bunch of rocker switches with <a href="http://www.amazon.com/gp/product/B012IE1EKA?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o01_s00" target="_blank">LEDs already integrated</a>&nbsp;for future use.</li></ul>
