Random experiments, circuits, code, rapid prototyping examples, sometimes things to buy, and occasionally tunes by Tod E. Kurt.
Yay BlinkMs!
BlinkM is a smart LED. Imagine an LED with a tiny computer inside, one that can be any color and have a life of its own. You can buy them now from one of our global distributors.
SketchUp is pretty great, but I found a problem with it if you’re trying to make accurate to-scale electronic parts: it won’t create surfaces with an area of <1mm. Took me a while to figure that out. The solution is to make a 10x or 100x size version and then do a scale by 0.1 or 0.01 when you’re done.
Arduino makes it pretty easy to store & use character strings, but those strings compete with your variables, so you can’t do as much. Here’s how to put big strings into read-only program memory and use them.
Lots of sketches can have big strings in them. Maybe you’ve built a little command-line interface or you’re storing small web pages (for net-connected Arduinos). Normally you do something like this:
char hellostr[] = “<html><head><title>hello world</title></head>”
“<body><p align=center><h1>hello world</h1></p>
“</body></html>”;
// and then sometime later
Serial.println( hellostr );
The problem with this is that “hellostr” is stored in RAM along with your variables. The ATmega chip in Arduino only has 1kB of RAM. If your code is getting complex, and you’re using big strings, and lots of libraries, you may start having mysterious problems. Arduino can’t warn you if your sketch starts using too much RAM.
Instead, you can use PROGMEM, or PROGram MEMory, to store your strings. That is, the flash ROM memory that your code lives in. Using PROGMEM strings can be tricky, but here’s a little function called “printProgStr()” to make it almost as easy.
const char hellostr[] PROGMEM = “…”; // notice added ‘const’ and ‘PROGMEM’
// given a PROGMEM string, use Serial.print() to send it out
void printProgStr(const prog_char str[])
{
char c;
if(!str) return;
while((c = pgm_read_byte(str++)))
Serial.print(c,BYTE);
}
// and then at some point
printProgStr( hellostr );
If you have another use for the string that isn’t “Serial.print()”, just create your own function and put whatever per-character handling function in there instead.
BlinkMs are a lot of fun by themselves, but they’re also little network devices, each having its own address on an I2C network. Here’s where I think BlinkM can really shine since it makes controlling multiple RGB LEDs pretty easy. For Maker Faire, I wanted to show off this facet by having a single Arduino control a dozen or so BlinkMs on a single I2C bus. The result is shown in the little video below.
I just received some colorful tiny mini-breadboards from FunGizmos.com. They are pretty great. Now quickie ideas prototyped with Arduino can be even smaller than the “1¢ Arduino under-shield”.
They appear to be the same quality as the other breadboards I have, just different color plastic. I can already tell the colors will help me differentiate projects, which all tend to look alike from 10 feet away. Normally when you buy these from Digikey or similar places, these little ones cost $7 a piece. FunGizmos has them for $5.40. And that’s cheap enough to get a few. Note that all these tiny breadboards don’t have the side power busses like the larger breadboards do. That’s the price you pay for tininess.
Want to hook up a Wii Nunchuck to an Arduino but don’t want to cut up the cord on your Nunchuck? Yeah me too. So I made some of these:
It’s a small PCB that adapts the Wii Nunchuck connector to standard 4-pin header. I call it the “wiichuck adapter”. It plugs directly into the Arduino, no wiring necessary. You can get one too for $4.
This is a BlinkM:
BlinkMs are “smart LEDs”, a type of smart interface component. A BlinkM consists of an ultrabirght RGB LED backed with a microcontroller with built-in knowledge about 24-bit color spaces, color fading, and color pattern generation. All in a package 0.6” wide. You talk to it over I2C, a serial protocol spoken by many different things. (Arduino speaks it, as do Basic Stamps, and your PC) And you can have over 100 BlinkMs on the same serial bus, each individually addressable. Here’s how they can hook up to an Arduino:
BlinkMs are available from SparkFun (US) and Little Bird Electronics (AU). It’s hard to show in just static pictures how fun and easy it is to play with BlinkMs, so here’s a few quick video guides.
A demonstration of one of the example Arduino sketches “BlinkMTester”, which lets you exercise a BlinkM by typing simple commands to the Arduino.
Exampe Code
There are a couple of examples of how to talk to BlinkMs all zipped up in BlinkM_Examples.zip. You can also peruse them unzipped if you like. The examples are predominately for Arduino currently, but any I2C master will work. Some of the examples so far:
BlinkMCommunicator
A simple serial-to-i2c gateway for PC controlling of BlinkM (for instance via Processing or the BlinkM Sequencer)
BlinkMTester
A general tool to play with a single BlinkM
BlinkMMulti
An example showing how to communicate with multiple BlinkMs
BlinkMScriptWriter
A demonstration of how to write BlinkM light scripts with Arduino
BlinkMChuck
Control the hue & brightness of a BlinkM with a Wii Nunchuck
More examples will be added periodically.
For the Arduino examples, a convenience library called BlinkM_funcs.h has been created. Just drop this .h file into your sketch folder and call the functions to start playing with BlinkM.
The complete list of functions is below, though you’ll probably only use a few of them for a particular project.
Mark Allen of Machine Project is teaching an Arduino course using some of the notes from my Bionic Arduino class. He and his students were seeing in Windows XP & 2000, when trying to getting Processing to talk to Arduino, the cryptic error:
gnu.io.PortInUseException: Unknown Application
at
gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
Both his class and Mark and I separately spent a lot of time trying to figure out what the problem was. Eventually we discovered that it’s because the sketch I had written had a setup() like this:
void setup() {
port = new Serial(this, portname, 19200);
size(400,400);
}
but instead should have been like this:
void setup() {
size(400,400);
port = new Serial(this, portname, 19200);
}
Yes, size() must come before new Serial() on Windows or it will not work. There is a bug report describing a similar problem and is marked RESOLVED, INVALID because as the reference documentation for size() states, “The size() function must be the first line in setup()”.
I’ve been using Processing for a long time and I found this feature of size() surprising. I always figured size() to be just a dimensioning function, not a critical part of sketch startup. I’ve seen many sketches that apparently function correctly where size() is located outside of setup() or is not the first statement in setup(). Perhaps the Processing sketch parser should check the sketch before running it to make sure not statements come before size().
I apologize to any Windows users attempting to use the Processing sketches I wrote for Bionic Arduino. I’ve updated the sketches appropriately so the above issue doesn’t come up.