Hardware is hard, let’s go shopping…

After a brief diversion into soldering I was back to playing with the Arduino last night, working through samples in the Arduino Experimentation Kit I bought a while back from Adafruit.  I’m only up to experiment 4 because I’ve spent a lot of time trying to understand the underlying electronics theory (why can’t you drive a motor directly from an arduino pin?  I mean, mathematically?  What the heck does a transistor actually do?).  The experimentation kit seems geared more towards getting people comfortable with the programming than the electronics, so wikipedia and I have been spending a lot of time together.

Last night’s experiment was working with a shift register to drive 8 LEDs.  There was a previous 8 LED project, but those were driven directly from Arduino pins, this project was designed to drive the same 8 LEDs, but only using 3 pins.  Wiring it was a snap (more or less, still trying to get a grip on the best order in which to place components) and the software was easy to load.  Just needed to give it a cursory run to prove it works so I could move on to what I really wanted to do, which was to see if I could figure out how to load a potentiometer into the circuit and use the LEDs as an indicator of the pot’s position.

Compile, load, and… Well, ok, the light’s were blinking, but not in the order I expected.  Changed the code to increase the delay between cycles, and the blinks were definitely not what I expected.  Rereading the project details, I notice it never actually says what the lights will do, but it seems really clear from the code that it will be a 0-255 binary counter.  But that’s not what it’s doing.  I spent an hour reviewing my code (which means I would have found a bug in the kit’s sample code, which seemed unlikely), removing the loop, trying to drive just one led for the whole app…  Nothing.  The pattern of the lights would change everytime I made a change, but not in any manner I could predict.

It was late so I decided to hang it up for the night and try again later.  I put everything away, and was standing up when I happened to glance at the wiring diagram.  I instantly noticed I had reversed the CLOCK and LATCH pins on the shift register.  The Arduino still had the last sketch I loaded on it (which simply sent “8” to the shift register), so I plugged in the 9v battery and voila – LED #3 lit up.  Arggg!

It seems likely that it will take me a while to get used to the rhythms of electronics/microcontroller debugging.  95% of the time I know where to look for a bug in a piece of software I’m writing instantly, but because the lights did something, I assumed the circuit was right and the code was wrong.  Bzzt.  That would be like a junior developer telling me his code wasn’t working, and he was pretty sure it was a bug in the library.  Nope.

On the plus side, now I’m ready to play with the pot tonight!  Whee!

1 thought on “Hardware is hard, let’s go shopping…

  1. Pingback: » Why Hardware Gotta Make Me Love It So Hard? Great Hat…

Leave a Reply

Your email address will not be published. Required fields are marked *