Step 0 – Learning Arduino

As stated in the last post, the goal is to use a microcontroller to light up a Munny doll with the same color that appears in the Office Communicator status.  Ultimately, I would like to have all of the logic housed within the Munny and just have a USB cable coming out of the Munny into the computer.  This would mean that I would have to build a pretty damn small circuit with a pretty damn small microcontroller.  The alternative would be to house the electronics in an Altoids box, plug that into the USB, and then have a long wire to just light an LED within the Munny.  Either way, the device will need to read the info from the USB and light accordingly.  This means that I would have to write some sort of daemon to respond to OCS status events and then bitbang an RGB color code to the Munny.
My initial thought is to use an HTML-like RGB color code, but also tack on an extra couple bytes for some additional info.  This is the same sort of thing that I saw on the todbot blog for his Ambient Orb, but I want to add some extra info.  So my payload would look something like this:
Each event from the USB should start with ‘#’ to notify the microcontroller, "Yo, I’m going to send you some color info."  The first two bytes will be the red hex value, followed by green, followed by blue.  The last two bytes should be some sort of bit flag to do some extra crud.  Right now I’m thinking of the following:
#define OPTION_SOLID  0x00
#define OPTION_THROB  0x01
#define OPTION_BLINK  0x02
Yes, that says throb.  My intention is that for some status (either Do Not Disturb or maybe even Away), the Munny should have a nice organic fade in/out.  Not sure if I will use BLINK (maybe to just be annoying?).  If anyone has other ideas for these options, let me know.
This payload will be a pretty generic way for anything to make the Munny light up.  So I can use it for OCS today, and maybe for build status tomorrow, or even something to show how test pass rates are going.  Possibilities are endless.
First though, I want to just prototype this with the Arduino and a protoshield and then go from there. 
Step 0 was to learn how the Arduino works, or rather how to work the Arduino.  I picked up a copy of Making Things Talk, and also Getting Started with Arduino.  Making Things Talk is a good detailed book, but I feel that they are trying to build something a wee bit ambitous as the first project.  On the other hand, Getting Started with Arduino was way too basic, but had excellent noobie examples to just get things up and running slowly (note: if you have any experience with coding, just skip the first half of the book and jump right into blink tutorial).
Getting "blink" to work was trivial.  I simply loaded the example code that came with the Arduino IDE and got the onboard LED to blink appropriately.  I then loaded a throb example onto the board from  I didn’t like this at all.  Since it’s using software PWM, the LED clearly blinks.  It’s ugly.  I want something nice.  The answer was actually in the Getting Started with Arduino book.  Utilizing the PWM pins on the Arduino itself, I was able to just loop through sending 0-255 straight to the LED, which caused a very nice gradual fade in and fade out.  I did adjust the delay a little bit so that the fade out "animation" was a hair quicker than fading in.
   1: #define LED_RED    9
   3: int i = 0;
   5: void setup()
   6: {
   7:   pinMode(LED_RED, OUTPUT);
   8: }
  10: void loop()
  11: {
  12:  for(i=0; i<255; i++)
  13:  {
  14:    analogWrite(LED_RED, i);
  15:    delay(10);
  16:  }
  18:  delay(10); 
  20:  for(i=255; i>0; i--)
  21:  {
  22:    analogWrite(LED_RED, 255);
  23:    delay(5);
  24:  }  
  25: }

In the next post I’ll talk about working with the Protoshield, an RGB LED, and why getting the Arduino to read serial data without corruption.

This entry was posted in Arduino. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s