April 16, 2013

Getting started with Arduino

I got started on the hardware portion of my Hackbright final project (3-D gesture authentication using a Wii nunchuck and an Arduino board, aka motion-based passwords) today and want to log the tutorials that I found particularly helpful as a total electronics newbie.

One of the reasons I never really considered a career in software engineering was that I thought to be good at it, you had to be one of those people who had been building computers from spare parts in the garage since age 10. With the rise of web apps, this doesn't seem to be the case anymore, but I figured that while I was at Hackbright and had access to the excellent instructors here, I should push myself out of my comfort zone and learn something totally new. So, I come to this with some vague memories of circuits and electricity from physics classes in high school and college (I never took AP Physics and then I was a Biology major, so it was just the calculus-based Intro to Physic co-requisite course).

For the Arduino part, I decided on the $49.50 Budget Pack for Arduino (Arduino Uno R3) - Uno w/328 sold by Adafruit Industries so that I'd have a decent variety of extra parts (wires/LEDs etc.) to play around with a bit, particularly if I ended up wanting to try other projects down the line.


I have a Mac laptop that also has a VirtualBox to run Ubuntu (a particular "flavor" of the Linux operating system) using the Unity user interface, so I set both of them up to be able work on the Arduino following the steps in Lesson 0 on Learn Arduino.

The VirtualBox was a bit finicky about recognizing the plugged Arduino from the USB port, so I followed these steps to get that working (with a quick detour to this post in order to get the user group permissions bit working). And even then, I would sometimes get this "programmer is not responding" error. Following these recommendations to hit the reset button would sometimes work, but not always, so I mostly gave up on working on the Arduino from within the VirtualBox.

I then followed it through to Lesson 2 and got the LED working (if you want to modify the code in the blink tutorial, the reference for syntax you should use to program the Arduino sketches is here), but realized that I didn't actually understand how the breadboard worked.


For that, I found Adafruit's founder's site of Arduino tutorials and started over from there. The software setup was pretty much the same, but I did get an explanation for what the four black bumpy things that came in the same box as the board were: rubber bumper feet.

From this:

To this (back view):

Anyway, there was then a good explanation of the breadboard in Lesson 3 but I wanted to add a bit more explanation.


Basically, half-size breadboard that you get with the budget kit is composed of two sets of two different pieces: a "power rail" (the skinnier ones on the left and right sides that have the + and - signs and red/blue lines running vertically down) and a block of 30 sets of 5 row holes (not sure what the technical term for that is). The way these work is that the power rail, once connected, will provide power up and down all the rows, while the rows only have connectivity within their own numerical row. In the above photo, I outlined each different section in a bright blue box.

By convention, you connect the power (3.3V or 5V) in from the Arduino to the positive (red, +) side and then back out from a negative (blue, -) to the ground (GND) on the Arduino board. So, you could bring power in at the top left and out from the top right, or in from the bottom left and out from the top right, or from only in the middle, and you would still have access to that power all the way up and down the power rails.

The rows, on the other hand, are only connected to each horizontally. So 1A-1E are all connected, and if you connected 1A to power, something connected to 1C would be able to access that power as well. 2A-2E would be totally independent, as would all the rest of the rows, unless you deliberately connected something in row 1 to another row. These rows also don't go across the dip in the middle, so 1A-1E are separate from 1F-1J unless you connect them somewhere along the way.

Another thing to note while you're working your way through the LED tutorials is that when you have a directional element like the LED that has a positive end and a negative end (unlike resistors which don't have a particular direction), you connect it on the board positive-positive and negative-negative. So one configuration could be:
  1. A wire from the 3.3V on the Arduino to a hole in the + column.
  2. The positive end of the LED in another hole in that same + column.
  3. The negative end of the LED in a hole in a - negative column (doesn't really matter which, but the LED probably can't stretch across the whole width of this particular board...if you had additional wires or a resistor in here though, there's nothing stopping you from using the whole width if you wanted to).
  4. A wire from another hole in the - column to a GND on the Arduino.
One cool thing to do is supply the power pin 13 to hook it up to an LED on the breadboard while running the blink "sketch" (Arduino programs are called sketches, I guess), because then you'll get the LED on the breadboard to blink on and off as well and not just the tiny one on the Arduino board itself.

Ta da! I'll write a post as well about the exact steps to hook up the Arduino up to a Wii nunchuck because that caused quite a bit of brow furrowing for me today as well. It turned out to be not that complicated but I didn't find any super detailed descriptions or photos of what to do exactly, so I will put that up.

[edited 5/5/13] This post from the Make magazine blog is a new overview of the differences between the different microprocessors you can use for hardware projects: Arduino vs. Raspberry Pi vs. BeagleBone.