A fellow BlinkM enthusiast over at the ThingM GetSatisfaction board asked whether it was possible to control a BlinkM on an Arduino from Max/MSP. I’ve been playing with Max/MSP in conjunction with my newly-completed Monome 40h kit, so I decided to take a stab at it. Here’s the comment I posted on GetSatisfaction:

Turns out it’s actually really, really easy!

Add a swatch. Send its left outlet to a “prepend 1 0 4 0 99”, and send prepend’s outlet to a serial object. For me, my Arduino showed up as port b (send “print” to serial to get a list in the max window), so I set up the serial with “serial b 19200”.

Program BlinkMCommunicator onto the Arduino, drop the BlinkM in the normal position, and you’re set. It’s so easy!

I expanded upon that simple patch and came up with this one, that includes sliders and a menu to select which port to talk to. The menu is not of my design; it was yoinked from Arduino2Max from the Arduino Playground.

Look for more Max/MSP fun soon. I’m really digging this environment.

(I can hear you all going “wtf does that subject line mean”... bear with me)

I recently picked up a monome 40h kit. Assembly was a breeze, but I ordered LEDs from China and they’re not here yet. I’m super anxious to start using my new toy, but it’s hard to tell what’s going on unless you can see the button pads light up.

So what is the enterprising hacker to do? Fake it? OKAY!

I’ve been hacking around with OSC lately… it’s a really cool, extremely flexible network protocol for device control and the like. Read more about it right here on the wikipedia. One of the cool things about the Monome setup is that while the physical device communicates using a serial protocol over USB, the applications communicate via OSC.

Anyway, blah de blah. What I did was use the oscP5 library to intercept the messages between the Monome router and applications. I update the grid based on those messages, and then pass them on to the destination recipient. It works surprisingly well! Here’s a screenshot of the sketch in use, running the flin application:

Remember that input is happening on my real monome. The black disc is a button that I was pressing when I took the screenshot.

This is early software, and as such has problems and limitations. Here’s a copy/paste from the README:

Known Bugs / Issues / Didn’t Do Yet

  • Only supports the 40h (and maybe the 64, I dunno)
  • High CPU usage due to render strategy
  • Doesn’t (yet) support rotation
  • Doesn’t support input… probably won’t as I’m not intending to write an emulator, but we’ll see.
  • Does not yet support the full OSC dictionary… coming soon?
  • Sometimes cells will get “stuck” on during a transition until the next time that cell is updated.

So that’s about it. You can get it from my Subversion:

svn co http://svn.bleything.net/monome/Monome_Display_Proxy

Details about how to use it are in the README. Please email me if you have any troubles.

Wiimote And BlinkM Are love

February 1st, 2008

Long time no blog. Sorry. Tonight I’m going to write about something a little different than normal. There will be no Ruby in this post! Consider yourself warned.

It should be obvious from my recent posts that I dabble in the dark arts of hardware hacking. I recently found out about (and promptly ordered) a new little toy called a BlinkM. BlinkMs are basically smart LEDs… they’re an RGB LED with a small microcontroller that you can interact with over the I2C protocol.

Tod E. Kurt, one of the guys behind the BlinkM, posted some example code which included details on how to use the guts of a Nintendo Wii Nunchuck controller to fiddle with the BlinkM. I decided to take that one step further (or one step back, depending on your point of view) and hack together a similar control without requiring you to take your nunchuck apart.

My setup requires a lot of pieces. First, the Wii remote itself with a connected nunchuck. Next, the DarwiinOSC branch/fork of DarwiinRemote. OSC, for what it’s worth, is Open Sound Control is a networked sound control protocol, sort of like MIDI over the network. It allows devices to send all sorts of information in easy to digest packets.

I’m reading the OSC messages with Processing, the environment on which Arduino based their GUI. In turn, Processing is doing some math on the sensor readings and feeding them to an Arduino via a serial connection. That Arduino is controlling the BlinkM. Complicated? Eh, not as bad as it sounds!

The best way to understand what’s going on is to see it in action. Here’s a short video I created demonstrating the hack:


Some Technical Details

  • I had a hell of a time figuring out the magic dance to get the BlinkM initialized and ready for commands. I ended up doing a gross hack which you’ll see in the code below, wherein I set the fade speed inside the update loop. Gross? Gross. For some reason, every time the BlinkM starts up, the fade speed resets to 0.
  • I’m using the oscP5 library for Processing to read the OSC messages. OSC is a damn cool protocol! I wonder if there is Ruby code to read/write it…
  • The translation of the (x,y) coordinates of the nunchuck’s joystick to displayable colors took some thinkin’. I absolutely suck at math so anything that I did right is purely by chance, heh. I ended up converting the rectangular coordinates to polar coordinates. This is convenient because the polar coordinates look like (r,θ), where r is the distance from the origin and θ is the angle from the origin axis. This maps pretty cleanly onto brightness and hue, respectively, and to make things even easier, the BlinkM can take an HSB-formatted color. I just set the saturation to full-bore and ran with it.
  • The BlinkM examples from Tod that I previously mentioned include a sketch called BlinkMCommunicator, which sets up a simple serial <-> I2C translator in the Arduino. I used this to communicate between Processing and the BlinkM.

The Code

The code is available over here. Unfortunately my syntax highlighter doesn’t like Java, so you’ll have to cope with it being monochrome :)

Astute readers will recall that during RubyConf last year, I posted about a little irb hack I’d written that allowed for shell-style history viewing and replay. There was a problem with it, however… replayed lines that made assignments didn’t work. So if you tried to replay

1
2
3
4
>> b = 5
=> 5
>> b + 10
=> 15

... you’d get …

NameError: undefined local variable or method `b' for main:Object
        from (irb):1

... which sucks. This has now been fixed! Witness:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>> b = 5
=> 5
>> b + 10
=> 15
>>  exit

superx ~...personal/toys/irbhistory > irb
>> h
[0937] b = 5
[0938] b + 10
[0939] h
=> nil
>> h! 937,938
=> 15

So that’s pretty cool, yeah? You can get the updated code here. It’s also in subversion, here.

Thanks to Giles Bowkett for pointing out a mis-feature that resulted in all evals returning nil, when you’d probably want them to return in the usual way. This is fixed now :)

Fun with Greasemonkey

July 18th, 2007

For the past few months, I’ve been learning Javascript. One of the fun things about learning Javascript is when you get to start playing with Greasemonkey. If you’re not familiar, Greasemonkey is a Firefox extension that allows you to write Javascript that executes inside the context of a page once it’s been loaded… effectively allowing you to manipulate pages before you see them. If you’ve never played with Greasemonkey, I highly recommend it. It’s great fun!

The real purpose of this post, though, is to share with you a couple of userscripts I’ve written:

I’ll very likely be writing more scripts as time goes on. I’ll keep posting them on this page. You can also get them from userscripts.org.