blink(16) prototype is woody and awesome

[originally posted on ThingM blog]

A few days ago ThingM friend Rusty, operator of the wonderful SomaFM, wondered if there would ever be a “blink(16)”: a blink(1) with a 4×4 grid of LEDs. Well it turns out that due to a secret feature of all blink(1) mk2s, it’s actually pretty easy to make, if you have some WS2812-style LED strip laying around.

 

blink16-somafm-500px

Making a blink(1) mk2 use 16 extra LEDs is pretty easy because it has a hidden 3-pin port for wiring up WS2812/NeoPixel-type LED strips.  In this photo, you can see the three holes: one each for Gnd, +5V, and data.

Below is a video showing it in action.  The two ‘blink1-tool’ commands used in the video are:

blink1-tool --random=1000  -l 18 -m 50 -t 50
blink1-tool --running  -l 18 -m 200 -t 200

Notice the “-l” option. Using this option, you can control a single LED in a blink(1) mk2. For instance, on a regular blink(1) mk2, you can do:

blink1-tool -l 1 --red
blink1-tool -l 2 --blue

to make the top LED red and the bottom one blue. For the “random” and “running” commands, the “-l” option means how many LEDs to use.

Some build photos from Flickr:
blink(16) blink(1) prototype
blink(16) prototype
blink(16) prototype
blink(16) prototype

I’m a video star on Slate, sort of

SlateV had a feature on 3D printing and Makerbots entitled “How to Print a Bicycle”. Bre of course was the spokesman. About halfway through it though, my friend Jon saw my face. Whoop, I’m famous! Okay, so maybe not famous exactly. But they did feature one of my creations (at the 3:15 mark).

While I think it’s cool they used my laser-cut iPhone stand as the representative of what Thingiverse is about, they probably should have used something 3d printed instead of laser cut. :)

BristleBots and LED throwie art at Crash Space!

This upcoming Tuesday, 9 March 2010, 8pm at Crash Space in Culver City, we’ll be having some fun quick DIY projects for you to build. Come on over and have fun with us. The project kits are $5 for CrashSpace members or $10 for non-members and you can take them home after you build them.

In the kit you get the parts to build your own Bristlebot, a tiny robot made from a toothbrush:
Crash Space bristlebots
(consists of toothbrush, pager motor, battery, and foam tape)

and LED throwie art:
Crash Space LED art throwies
Crash Space LED art
(consists of two color-changing RGB LEDs, battery, and a magnet)

We’ll have a Bristlebot race track you can do time trials on:
Creativity Lab  at TEDActive2010

And we’ll be showing you how to build all of this, no previous experience required. Come build bots and lights!

Not a sunrise, but a galaxy rise

This is one of the greatest bits of youtubery I’ve ever seen, and I generally dislike auto-tuned stuff. Carl Sagan’s Cosmos was one of the most important things to happen to me as a child. This video & song gives me the shivvers. And makes me miss Sagan all the more.

I love the song’s chorus created from cut up Sagan quotes:

A still more glorious dawn awaits
Not a sunrise, but a galaxy rise
A morning filled with 400 billion suns
The rising of the milky way

(via jwz)

Arduino Serial protocol design patterns

[I posted this to the Arduino developer’s mailing list, but figured others might find it useful too]

When I first started with Arduino, I thought Serial.available() was a very loose wrapping of the RXC bit in the USCRA register, i.e. if I didn’t get data out of there fast, it’d be gone. That led to convoluted code like:

 if( Serial.available() ) {
   val1 = Serial.read();
   while( !Serial.available() );
   val2 = Serial.read();
   // and so on
 }

Yuck. So you end up designing protocols that are too terse. Or maybe you think you need to buffer so you don’t lose it:

 while( Serial.available() ) {
   commandbuffer[i++] = Serial.read();
 }

Then parsing becomes a two step process: read serial, parse buffer. Confusing to newbies perhaps, but at least it allows for a better protocol down the line. (And descend into madness as you gaze into the maw of strtok())

Because Serial contains these big comfy buffers, we often don’t need a second buffer to let us easily implement good protocols. My current favorite is to do something like this:

 // protocol is "CCaaaa", two bytes of command, four bytes of args
 if( Serial.available() >= 6 ) {  // command length is 6 bytes
   cmd0 = Serial.read();
   cmd1 = Serial.read();
   arg0 = Serial.read();
   arg1 = Serial.read();
  // ...etc...
 }

I don’t think I’ve seen any Serial examples that check for a specific number of bytes available. It’s really handy.

Implementing a human-friendly protocol like “command arg0 arg1 arg2”, where command and args are space-separated strings like “servo 12 0xff”, is currently hard with Serial. I do this right now with a 2nd buffer and lots of C hackery:

 char* cmdbuf; char c; int i;
 while( Serial.available() && c!= '\n' ) {  // buffer up a line
   c = Serial.read();
   cmdbuf[i++] = c;
 }

 int i = 0;
 while( cmdbuf[++i] != ' ' ) ; // find first space
 cmdbuf[i] = 0;          // null terminate command
 char* cmd = cmdbuf;     //
 int cmdlen = i;         // length of cmd

 int args[5], a;         // five args max, 'a' is arg counter
 char* s; char* argbuf = cmdbuf+cmdlen+1;
 while( (s = strtok(argbuf, " ")) != NULL && a < 5 ) {
   argbuf = NULL;
   args[a++] = (byte)strtol(s,NULL,0); // parse hex or decimal arg
 }
 int argcnt = a;         // number of args read

This sort of functionality would be great in a library I think. Maybe not in Serial, but a core class.

Any other protocols people like to use and the Arduino code they use to do it?

New RoombaComm 0.96

Paul Bouchier has kindly spent time and updated the Java RoombaComm library. Not only did he add support for the newer 5xx series Roombas, but he fixed a lot of bugs, added new features, made things work easier under Windows, and generally cleaned up the mess of code I had created.

Check out the Changelog for a list of the changes. And try out the new version of RoombaComm!