At this years Sketching in Hardware conference, I gave a talk on the general approach I used to create LinkM, ThingM’s USB-to-I2C adapter for programming and controlling BlinkMs. I called it “Hacking USB HID for Easy Tethered Ubicomp” (4.8MB PDF) to give it a form that fit within some of the larger issues I’ve been dealing with in creating easily usable ubiquitous computing devices.
USB has many different (and confusing) aspects to it. I’ve long advocated the creation of a set of libraries and patterns to make “driverless” USB a reality. A sort of training wheels for USB. At the time I called this USB on Rails”, poking fun at RoR.
To me the key to this ease-of-use was the HID class in USB. No driver is needed when plugging in something like a mouse or keyboard. Other built-in device class drivers include CDC (modems), Mass storage, audio (headset), and video (webcam).
While researching HID, trying to make LinkM a “USB on Rails” project, I found that the biggest hurdle was a consistent host-side USB API that would let one write one set of code that could easily be ported to Mac OS X, Windows, and Linux. Libusb works well enough for Unix-like OSes like Linux and Mac OS X, but the Windows variant libusb-win32 required a driver install. So I put HID away.
For many months I investigated using CDC instead of HID because it maps down to a serial port on modern operating systems. Unfortunately, CDC has two main problems. For the “serial port emulation” mode, mapping to serial port semantics is problematic for a USB device that can be removed at will. If a device is removed while it is still “connected”, the OS and application can get confused or crash. Also, the CDC driver implementation seems brittle on Mac OS X. Some CDC devices can work fine, others wouldn’t. I can see now why FTDI and similar vendors use a custom driver for their USB-to-serial chips.
With that, I took both of those projects, generalized them slightly, then specialized them for LinkM and made them the core of the LinkM project. You can view the resulting source at the LinkM Googlecode project.
(click any photo to go to larger version on Flickr)
We were in the Maker Shed building, right underneath the Arduino banner, so we got lots of awesome questions about Arduino. The most common: “So I just picked up this thing that says ‘works with Arduino’…well, what *is* Arduino?” It was so great to see so many people interested in building their own gizmos.
By far the most fun demo we had was TwitM, the Twitter-controlled BlinkM. Using LinkM, a couple BlinkMs, and a Processing sketch, I had it so anyone who tweeted anything with the keyword “makerfaire” made one BlinkM flash. If you tweeted “blinkm colorname”, where colorname was any color in the X11 color names or a hex color code RRGGBB, the other BlinkM would turn that color. Because of the streaming Twitter API, these changes happened instantly; it was really something to see.
Kim and Mike made up some really nice “walltext” describing the various demos we had up.
A big hit was MaxM controlling RGB LED flexible circuit tape, using the same techniques I used for the Crystal Monster.
This was about regular busy at the Faire. There were many times when it got way more packed.
(as a few had noticed, I had an error in the schematic shown. It’s been updated, thanks!)
A recent question from a friend who made a really cool BlinkM hoodie was: How can you turn a momentary button press into an on/off toggle?
There are tons of ways to do this if you like getting into electronics. Most all work off of some flip-flop like principle. And while I could have suggested a true flip-flop chip, I thought it would be cooler if you could use a 555 timer chip (which contains a single flip-flop and a couple of comparators). After scouring my childhood collection of Forrest Mims electronics books and a few 555 timer devoted websites (two of the best I found were: http://www.bowdenshobbycircuits.info/ & http://www.kpsec.freeuk.com/555timer.htm), I cobbled together the following circuit based off a few almost-what-I-wanted examples.
This is what it looks like in use:
The schematic is pretty straightforward, but does use a bit of feedback trickery to get the toggle functionality:
(old incorrect version here)
The parts cost is pretty low. The 555 timer chip can be had for about $0.43, the 2N3904 transistor for ~$0.40, and various resistors & capacitors are essentially free if you have them.
The circuit has 3 external two-pin connections: 5V&Gnd, button input, and the two pins of the thing to switch. In this case, the switched thing is a power supply to a BlinkM.
By changing the transistor to a beefier one, you can switch much larger loads. The little 2N3904 transistor in there now can switch around 200mA, but a bigger NPN or FET transistor and you could switch a few amps.
It can be made pretty small on a tiny breadboard (courtesy of FunGizmos.com) like this:
It’s not the greatest for battery-powered applications. When “off” it draws about 4-6mA, depending on the brand of 555 timer chip you use. When on it draws that plus whatever power the switched device draws. Best to put a proper power switch on the battery pack to eliminate this quiescent drain.
One of the challenges of working with I2C (aka “two-wire” or “TWI” or “Wire”) devices is knowing the I2C address of the device. Older devices have a fixed address, or a “choose one-of-four” approach. But newer I2C devices have fully programmable addresses, leading to cases of not knowing what address a device is at.
Fortunately, there’s a technique one can use to “scan” an I2C bus and determine these addresses. Conceptually it’s very similar to a network “ping”. Below is an Arduino sketch “I2CScanner.pde” that turns an Arduino into an I2C bus scanner.
When loaded up on an Arduino, the sketch will immediately scan the I2C network, showing which addresses are responding.
For example, the above output is from an I2C bus with four slave devices on it (one BlinkM MaxM, three regular BlinkMs). (Notice the 2 pull-up resistors on SDA & SCL. This is needed for longer bus lengths)
One thing to notice about the I2CScanner output is that although there are four devices on the bus, only three addresses were detected. This is because unlike IP networks and “ping”, you can’t tell if two devices have the same address. They’ll both respond to commands sent to them just fine, you just can’t read back data from them.
How it works
In I2C, the first byte transmitted/written by the master to a slave is the address of the slave. If there is a slave at that address, the slave will signal the I2C bus, otherwise it leaves it alone. We can use this to implement a bus scanner.
The Arduino “Wire” library utilizes a set of C functions called “twi.c”. One of those functions is “twi_writeTo()”. This function is used to both send the address of the slave down the bus and also to write data to slaves. It returns 0 if it was able to successfully transmit a byte or non-zero if it couldn’t. Since the very first write to a slave is its address, a very simple bus scanner using it would be:
void scanI2CBus(byte from_addr, byte to_addr) {
byte data = 0; // not used, just a ptr to feed to twi_writeTo()
for( byte addr = from_addr; addr < = to_addr; addr++ ) {
byte rc = twi_writeTo(addr, &data, 0, 1);
if( rc == 0 ) {
Serial.printl("device found at address ");
Serial.println(addr,DEC);
}
}
}
In the I2CScanner sketch, this function is extended a bit to support a callback function. The callback function is called with the result of every address scan. In I2CScanner, this callback function is called "scanFunc()" and just prints out "found!" or nothing, but it could be modified to do more complex tasks like doing additional I2C transactions to figure out what kind of device it is, or setting all the devices to a known state, etc.
If you want a slightly different look for your Halloween pumpkin or skull, you can pretty quickly whip something up with a few servos and an Arduino. Here’s a set of Scary Shifty Servo Eyeballs, for instance:
It looks around randomly…what’s over there!… wait, what’s that!
As you can probably tell it’s a pretty simple arrangement (click for bigger):
The Crystal Monster is an art piece created by Beverly Tang and Tod E. Kurt (me). It’s on display in the Continental Gallery on 4th & Spring St in downtown Los Angeles. The shape and structure of the Crystal Monster are Beverly’s design. I created the lighting and the electronics. It’s made from over 400 sheets of laser-cut acrylic, more that 240 feet of LED tape (>2200 RGB LEDs!), and around 500 steel rods and other steel hardware. It’s approximately 12 feet long and 10 feet wide and hovers 10 feet above your head. It’s got an Arduino brain and 18 BlinkM MaxMs (one per segment) to let it flutter color patterns up and down its length.
Some of my photos (click on any to go to the Flickr set):
It was first installed at the Ball-Nogues studio in Downtown Los Angeles as part of their participation in Downtown L.A. Art Walk, and lived there for a few months.
Then it moved to its mostly-permanent location at the Continental Gallery at 4th & Spring in Downtown Los Angeles.
It’s right on the corner, so you can really see it just from walking by on the street.
The electronics consist of 18 BlinkM MaxMs driven by a single Arduino, all powered by an ATX power supply. The Arduino has an IR remote control receiver so the Monster’s behavior can be controlled from afar.
A single BlinkM MaxM can easily drive a 5 meter (16 ft) roll of the flexible RGB SMD LED tape that’s used for architectural lighting. Each roll contains 150 RGB LEDs.
Each LED in the tape is a SMD RGB "5050" LED, capable of putting out about 6000mcd. The spacing between LEDs is 3.3cm (~1.25").
Every 3 LEDs is a cut mark with solder tabs so you can cut or join pieces of tape.
Max current for a 5m roll is about 1.9 Amps. I did a quick test of MaxM driving three rolls at about 6A and it seemed fine.
This stuff is really cool. I’ve been buying it from this really great seller on ebay named "sunnytech".
Here’s what you can do with it. Each of the 15 sections contains between 1 and 3 rolls of the tape.
Random experiments, circuits, code, rapid prototyping examples, sometimes things to buy, and occasionally tunes by Tod E. Kurt.
Reach me at tod [at] todbot.com
Crash Space
Crash Space is a Los Angeles-based hackerspace. Come visit! Become a member! Learn Arduino or how to solder!
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.
ThingM
A device studio that lives at the intersections of ubiquitous computing, ambient intelligence, industrial design, and materials science.
Recent Comments