Wednesday, January 25, 2012

Adventures With Arduino

Me: Guess what I did in Digital History today? 

Doug: What? 

M: I played with an Arduino board! 

D:  You played with a what?  Arduino board?  Like that waffle-board looking thing? 

M:  Yeah, an Arduino board !  You know...a little computer-like thing that...um, it has all these inputs and outputs.  We plugged it into a computer, copied some code, and made a light bulb turn on!  And then we turned it on and off with a button, then we made it blink and fade.  We tried to get two different lights to fade in and out at the same time, but we couldn't quite get the code right.  Okay, it was a lot cooler than it sounds now.... 

D:  And this was in your history class.....?


--------------------------------------------------------------------------------------------------------


Admittedly I am not a techie.  My foray into HTML last semester was a leap for me, so actually programming?  That would be crazy!  What an interesting challenge!  Prof. Turkel opened the class by telling us that we would be making two things this semester:
  1. stuff
  2. mistakes
As he pointed out, it's not often professors encourage you to make mistakes.  He said he'd rather have us dream big, fail spectacularly, and learn something along the way than to play it safe.  I figured even if it's scary, what's the worst that could happen, I make a mistake?  Cool!


For those of you, like I, unfamiliar with Arduino it's "a popular open-source electronic board that is capable of controlling just about any DIY hardware project."  I figured if this girl could handle it, so could I:


So armed with our box-o-Arduino supplies, and big dreams (or at least big dreams in the making) my partner Adriana and I dove in!  Our kit came with an instruction manual, but we find illustrations much easier to follow so with the help of this comic we got to work.  Adriana had downloaded the software onto her computer, so we sped through the instructions, hooked up all the wires, copied the code into the computer, and voila - our light blinked! 

Now, if that description of how things happened leaves you a little lost and confused, you are exactly where I was in class.  I was so excited to see something happen (i.e. make a light blink) that I wasn't really paying attention to what we were doing.  In fact, everything was pretty much happening all at once.  Adriana was entering the code into the Arduino program, I was following the illustration and hooking up all the wires in the Arduino board and breadboard, but I can't say as though I understood exactly what we were doing.  I was just excited to see this happen:



However, at this point I realized that I had done little more than show I was capable of cutting and pasting code text, and following an illustration to put wires in the right place.  And while the end result was cool - I didn't really understand what I was actually doing.  So we slowed down and Adriana and I went through the code step-by-step.  When you put a sketch (or code) into the Arduino software, it looks a little something like this:

Sketch for fading LED

The light-grey text (following the //) is not actually part of the code, but it's included in the Getting Started with Arduino book to help you understand what each line does.  So we went line by line to figure out what the sketch was telling the Arduino board.  Once we had a basic understanding, we wanted to try something new (dream big right?) and have two different lights hooked up and have them fade in and out at the same time.  So we copied and pasted the sketch over again and made a few changes (there is a "verify" button on the software that double checks your sketch to make sure it's correct), added a second light and BAM - nothing happened.  Well, not quite nothing, but just the first light worked, not the second.


We were really bummed at first, we thought we were wizards and had everything figured out.  But then we realized what we had done...made our first mistake!  So rather than fail, this was just an opportunity to learn what we had done wrong.  Unfortunately, at that very moment, class was over and we had to pack up and call it a day.


But the thing about Arduino is once you start thinking about it, it's hard to stop.  There were numerous Tweets flying around that evening among classmates, with suggestions, solutions, and cool websites to check out.  Adriana eventually figured out our mistake in the sketch.  (If I understand it correctly, we had created a second "loop" or entirely separate part of the code, or the Arduino was only reading the first part - hence only one light coming on.)  


The nice thing about Arduino being open-source is that you can find a lot of people on the web sharing what they are doing and the codes that go along with their projects.  So if you're really bored creative, you can do something like this:



2 comments:

  1. So cool. I wish I had classes like that in school.

    ReplyDelete
  2. I picked up an arduino board simply so I could make my garden gnome creepy and satanic looking. Good for you for venturing into my world!

    ReplyDelete