Monday, September 30, 2013

Adding some color with NeoPixels

For the traffic light project, I will require different colored LEDs. Rather than going with single color LEDs, I decided to use RGB LEDs. There are a wide variety of RGB LEDs available, but I wanted to try my hand with the popular SMD 5050 RGB LEDs using an integrated WS2812 driver. The marketing term coined by Adafruit for these is NeoPixels, and I learned a great deal about how to work with these from Adafruit's NeoPixel Überguide.
Close up of SMD 5050 showing the integrated WS2812 IC and separate RGB LEDs

The NeoPixels themselves come in a wide variety of form factors, from individual LEDs to being pre-mounted on a board, to long ribbons or chains. I found what I wanted at a significant discount from various eBay sellers and ended up purchasing two kinds: a handful of individually mounted LEDs and a chain of 50 that were covered with a diffuser to soften and disperse the light.


What makes NeoPixels Über-Awesome is that each pixel within a chain of them can be individually addressed by your code. That is, if you have a serial chain of 10 NeoPixels, your code sketch can have the first Pixel light up one color, the second light up another color, and the third... etc. all the way down the chain, all controlled from a single pin from your microcontroller. "Ordinary" RGB LEDs connected to a single pin would all show the same color because the pin would only be able to control the entire chain as a whole. This can lead to some amazing effects even though the wiring is relatively simple. An entire string of NeoPixels requires only three connections: power, ground, and a single wire data/clock channel. (Note that there is a different kind of RGB pixels distinguished by the fact that they require separate pins for the clock and data, in addition to the power and ground lines. You may see reference to the WS2801 driver for these kinds of pixels)

The details of how this is accomplished by the microcontroller are far beyond the scope of this blog post (but explained nicely in this Sparkfun WS2812 Tutorial), but one of the great things about the Arduino community is the existence of publicly available code libraries that do all the hard work of making neat stuff happen. You just have to include the library in your sketch and learn some syntax for how to call the various functions. For these NeoPixels, the go-to library is of course the Adafruit NeoPixel library. This library also includes a good sample sketch called "strandtest" that demonstrates the library functions and this page in the überguide breaks down the strandtest sketch and explains how these functions work.

Over the weekend, I started trying to put together a basic circuit using the long 50 NeoPixel strand. I wired everything up in accordance with the tutorials I found, using a separate power source for the LED strand because the current draw for all 50 LEDs would be significantly more than the Arduino Uno I was using could muster. One tricky part was figuring out how to load the Adafruit NeoPixel library into Codebender. I followed the instructions to do this from a Codebender support page and uploaded the example strandtest sketch to the Arduino and... nothing!

The troublesome part was that there were multiple possibilities for why it wasn't working: perhaps there was a loose connection somewhere, or the power supply wasn't providing enough current or voltage, or I had a wire in the wrong pin, or there was an error in the sketch (though not one that was caught by the compiler). And so I spent a long, frustrating night trying to debug everything to find what was wrong, switching components, testing with the other kind of LED, and finally calling it quits at midnight with nothing to show for the time than a few brief flickers from one LED.

The next day I brought out the big (debugging) guns: a multimeter that a former student had given to me. It's an electronic tinkerer's best friend.
I should have thought of using this the previous night. With the multimeter, I was able to determine that the circuit was fine, all voltages were as they should be, with the exception of the data pin from the Arduino, which wasn't outputting anything. This led me to conclude that there was something wrong with the code, and I began to suspect that it had something to do with the workaround way of including custom external libraries in Codebender. On a hunch, I installed the original Arduino IDE, loaded up the Adafruit NeoPixel library for it, uploaded the strandtest sketch to the Arduino again, and then sat back to enjoy the light show.



Acronym Glossary:
LED - Light Emitting Diode
RGB - Red Green Blue, for the three individual color LEDs that actually make up the RGB LED
SMD - Surface Mounted Device


Friday, September 13, 2013

Learning with the Lilypad Protosnap Development Board

I started playing around with the Lilypad Protosnap Development board. I found this awesome Sketch (what Arduino calls a program) that utilizes all the sensors, switches, and LEDs on the development board and provides a great test bed to learn the basics of the board. This sketch has proven invaluable in understanding how the pins on the Arduino output to various components, as well as basic Arduino code syntax. By having all the components already connected on one board minimizes the frustration of wiring things together yourself, so that you can focus on understanding what is happening in the code rather than trying to troubleshoot whether you have a loose wire or connection somewhere in your circuit.

Here is the codebender embed of the Protosnap Development Platform Test Code.

I also put together a very rough and rambling video demonstrating the board running this sketch. One of the really neat things is the serial monitor that allows the Arduino to communicate things back to the computer. In this sketch, the serial monitor is programmed to display the real-time status of various switches and sensors. I show this in the video below. There is certainly a sense of satisfaction in getting lines of code to do some visible and interactive functions.


Thursday, September 12, 2013

The Lilypad Arduino

Some initial parts arrived!
 The first Arduino board that I'm learning on is the Lilypad Protosnap Development Board. It conveniently comes with a variety of components and sensors all pre-connected on a single board to aid in development and learning. Later on, each component can be cut out of the circuit board and used separately in projects. Components on the Protosnap include temperature and light sensors, a buzzer, a small vibrating motor (think old school pager), a RGB and 5 white LEDs, and both a push-button (or momentary) and slider switches.
The Lilypad series is intended more for textile projects, using conductive thread instead of normal wiring to connect components. Each component has large holes to make it easier to sew into a project. These make for excellent wearable electronic projects.
The Interactive Town Play Mat project I have in mind does not require wearable electronics, plus I just don't have the patience for sewing, so I'm planning on getting some other Arduino boards to play with, such as the widely used Arduino Uno. The great thing is that the Lilypad Arduino uses the same microcontroller (the ATmega328V as the most popular Arduino board (the Uno) so much of the things that I learn on the Lilypad will directly translate to the Uno.

Codebender - Like Google Docs for Arduino Sketches

I came across an interesting website called Codebender.cc. Think of it as Google Docs for Arduino sketches (Arduino programs are called "sketches"). It can serve as cloud storage for your Arduino projects, so that you have access to all your project code sketches  from any web browser. The website has its own online compiler that will check your code for errors, and it displays rather less cryptic error messages than the normal Arduino IDE if it encounters any problems (YMMV). This can be very convenient if you want to work on your sketch while you are on a computer that does not have the Arduino IDE software installed. And if the computer that you are using has the FTDI drivers installed, you can even upload the sketch directly from the browser to your Arduino board without having to open the Arduino IDE software at all.

I’ve been using it regularly this past week to store examples of code that I’d like to modify from whatever computer I happen to be on at the moment, whether at work or home. I’m no longer using the Arduino IDE program at all any more because I find the code editor on codebender.cc is easier to use and looks better too. This plus the convenience of easy access to my project from any computer.

If anyone would like to give it a try, it would be great if you signed up via the referral link below. I'm trying to earn enough points for a free T-shirt. :) Also feel free to grab any of the sketches that I've uploaded in my account!

Wednesday, September 11, 2013

Interactive Town Play Mat Project

We have this IKEA town play mat that my kids like to drive toy vehicles and other things on. My son also has a Thomas the Train track set and sometimes he incorporates a track layout around the town. Like a true bricoleur, he uses whatever he can find to create crossing guards and such to mark the railroad crossings.


My idea is to use Arduinos and other components to add some interactivity and lights to this play mat. I have three primary features that I would like to accomplish:
  1. Set up one or two working intersection signal lights that will alternately cycle through green, yellow, and red lights in a timed sequence.
  2. Build a working railroad crossing signal that will detect when a toy train is approaching and flash red warning lights and maybe sound a warning bell.
  3. Add a series of "street lights" that will automatically turn on when the ambient light level gets low
Subsequent posts will detail the process of building this project, from finding the components to programming the Arduino Sketch to the final layout of the play mat.

Monday, September 9, 2013

Arduinos and the next microprocessor revolution

One of the exciting new "bricks" that I've been playing with recently is the Arduino microcontroller board. The Arduino is described as "an open source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments."
Arduino boards come in a variety of shapes and sizes, but what they all hold in common is a relatively low cost of entry and accessibility to a wide range of users, including those who may not have previously considered programming and microprocessors a particular area of interest. A friend of mine called Arduino "the hardware version of MySpace," a very apt description. MySpace dramatically lowered the barrier to creating your own web page and gave everyone the opportunity to be a webmaster. In similar fashion, Arduino has significantly lowered the barrier to electronics and basic computing, giving everyone the chance to be a programmer and electrical engineer.

While researching about Arduino and the culture that has formed around these devices I see many parallels to the microprocessor revolution of the '70s and '80s. The early history of microprocessors was marked by scores of hobbyists simply tinkering with early microprocessors like the Intel 4004 and 8080 and making them do new and wonderful things. The accessibility of Arduino has similarly led to an extensive array of students, educators, and tinkerers in general playing around with the devices and documenting the neat projects that they have created. The open source nature of Arduino supports a culture of sharing among the participants, with Arduino code "sketches" being passed around and modified and incorporated into any number of projects. We may very well be participating in the next great microprocessor revolution.

Saturday, September 7, 2013

"Brickolage" - or what we make of things

The title of this blog is a play on the word 'bricoleur', which refers to someone who engages in bricolage, or the creation of things using whatever is at hand. The humble "brick" is often the most basic component of any construction, and as a fundamental building block it can be made from any variety of materials. It seems fitting then for "Brickoleur" to be the title of a blog about building, creating, tinkering, and assembling, using a wide assortment of materials.

This plus the fact that "bricolage," "bricoleur," and "brickolage" were all already taken as Blogger domain names....