Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/42/d191189227/htdocs/snakeye2/wp-includes/post-template.php on line 284

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/42/d191189227/htdocs/snakeye2/wp-includes/post-template.php on line 284

Building (and flying) my quadcopter has been taking up the past few weekends… until I accidentally American-Gladiatored the thing through a gauntlet of tree branches.  Oops.  They say that there are those that will crash one, and those that have crashed one; I now stand firmly in the latter group.  So, as I await the spare parts to arrive in the mail for repairs, my attention has been diverted onto the next project that’s captivated me for about six months now: a kid’s play spaceship.

I forgot what originally directed me to this back then, but I was mesmerized after stumbling across this video:

After watching this, I knew I had to build this for my own kids at some point!  This type of creativity is right up my alley, and my thorough knowledge of military fast jets can potentially make this thing better than the video above.  I credit this video (and the guy, Jeff, who made the project and video) as my single launching point into the world of micro-computing: doing cool, what you would think are beyond you, projects with the credit-card-sized Raspberry Pi and Arduino computers.

With this inspiration in the back of my mind, I’ve been slowly stockpiling the switches, LEDs, and learning books (on the coding) to eke out forward movement towards this project.  Over the months, I’ve experimented with a few blinking LEDs controlled by a few buttons (or other input sensors, like a motion detector) using either the Arduino or the Raspberry Pi to start understanding the basics of the programming code that go along with them.  Then a few times a month I get curious and pour over Jeff’s code, finding out I understand just a little more of what’s going on within it each time.

Like Jeff, I’m going to use a Raspberry Pi to deal with logics and sequences of events and switches (like a start-up sequence, a launch sequence, etc), and an Arduino to read the status of all the switches and turn on/off all the LEDs.  Essentially, the Raspberry Pi is the brain and the Arduino is the brawn.  With a yellow-belt understanding of the code (meaning: I know enough to look good but would really get my ass kicked in a street fight), I’ve broken it down into a few milestones:

  1. Coding the Master Caution system (light and button) to work exactly as I want it.  This ‘system’ is ultimately the overseer of every other system throughout the entire cockpit.  If pervades every light and switch, so it’s bound to be the most complicated to program.  This step will also tackle getting the Arduino and Raspberry Pi to speak to each other which, up until now, I know very little of how to do.  Once I get this up and running, the rest of the switches will be gravy and I can consider the first of three milestones complete.
  2. Figuring out how to I2C together all the switches.  You see, the Arduino (which is the keeper of the switches and lights) only has enough ports to handle any combination of 19 individual switches and lights.  To get this thing to work, I need to be able to control in excess of 200 switches and individual lights.  I2C using a few MCP23017 chips is apparently how to connect all this stuff in serial so only one Arduino (and its 19 ports) can handle this.  So figuring this out, and the address system that goes along with to listen to individual switches, will be the next 1/3 step forward.
  3. Figuring out how to I2C together all the LEDs/lights.  This is the same know-how from milestone 2, but whereas the switches were just figuring out the wiring and addressing issues, the additional displays coordination moves into the territory of more intense programming code.  For example, one LED number (say like the number 8) consists of something like seven different LEDs that you have to coordinate through code so your 8 doesn’t look like an upside-down U.  Like the MCP23017 chip used above, the HT16K33 LED driver chip is supposed to make all this more manageable… but you just have to figure out how it’s wired and the coding needed to make it work.  Do this, and the cockpit will be completed.

For me, figuring out the electronics that go into the cockpit is about 99% of the challenge for this entire project.  Given my woodworking experience, building and designing the wooden spaceship frame is the easiest part of the whole thing.

So this weekend was spent doing hours of Google research into Python (the language of Raspberry Pi) and Arduino coding.

I found a buzzer sound online and, using a sound editor, molded it into what I think is the perfect annoying Master Caution alarm sound.  I know the (not-so) modern day Spaceshuttle uses an almost calming airline-style ring as in Jeff’s design (the first video of the post), but I wanted a 1970’s Apollo-13-style gritty, archaic buzz for my Master Caution.  The end sound was only a ½ second long and is looped endlessly by the python code until the button is pressed.  Unfortunately, the sound lags the button by almost a second (out of sync), so I had to further modify my Arduino code by delaying the lightshow (both its start and finish) by that same amount of time… that took a few hours of trial and error to finally arrive at a solution.  Lastly, rather than a solid-lit Master Caution button, I wanted emergencies to be highlighted by something that gets your attention through both annoying light flashes and obnoxious noises (á la Eurofighter-style).  Like the sound-lag code, this flashing added hours of trial-and-error frustration as well (hint: never use ‘delay()’ in the Arduino code).  In the end, I think it turned out exactly as I wanted:

In my video, I used a little button with a 5-second delay to trigger the “emergency.”  However, once I transplant this code into the entire cockpit code, it will be switches and/or sequences of switches that will trigger the emergency and, ultimately, this annoying button.

With one of the three hurdles behind me, this is indeed one giant leap to understanding the programming and making this come together for Snakeye-kind.  To save any other beginners hours of their time, I’ve posted the Master Caution code that drives this thing on Github.

Up next: frustrating hours of trial and error to demystify the MCP23017 and reading the positions of multiple buttons and switches.

Tagged with →