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 :)

RubyConf stuff

November 16th, 2007

Well. RubyConf was two weeks ago now and I still haven’t completely wrapped my head around it. It was a different experience this year than last (understanding that last year was my first RubyConf), and I’m not sure whether I liked it better. I would have preferred a single track, although I completely acknowledge the reasons why multitrack made sense… I just didn’t like having to make decisions between two talks I really wanted to see, which happened at pretty much every junction.

I particularly enjoyed Ryan Davis’s and Eric Hodel’s talks, which both more or less boiled down to them talking about the tactics they use to write more/better code. That’s the kind of thing I really like to hear about: the ways that other people boost their productivity and output quality. In this case, the people were experts, but it’s fun to hear from newbies too, as they almost always bring new perspective.

Another highlight was Laurent Sansonetti’s talk on how Apple loves Ruby. I can’t really explain how totally awesome this was. Apple really does love Ruby, and the stuff you can do in Leopard with Ruby is astounding. You’ll just have to watch the video.

Speaking of which, one totally awesome thing that may not be universally known is that Confreaks recorded (almost) every session and are publishing the videos on their website. It’s a lot of video to process so things are a little slow in coming, but eventually all of the conference videos will be here. They’ve already published all of the RejectConf presentations... you can see my 3 minutes on IRB history (now with more working) here. The code is available here.

I’ve also arranged to get the raw camera captures for my talk and I’ll be putting together a video of my presentation in a different format later. On that topic, the slides for my presentation are available at this link. They’re under the Creative Commons Attribution-Noncommercial-Share Alike 3.0... the video on Confreaks will be as well, which is slightly different than what their pages say. The non-commercial clause is the only exception.

Also as promised, below is a list of links to the stuff I talked about:

Serial Hardware

  • Keyspan USA-19HS USB -> serial adapter — the best USB/serial adapter I’ve found. About $40.
  • FTDI FT232R USB -> UART chip — These are only available in surface-mount packaging. You can get one on a breakout board from Sparkfun, if you need it by itself. See the Buy Some Gear section.
  • FTDI TTL232R USB -> UART cables — these are USB cables with embedded FT232Rs, available in various configurations. Necessary if you’re using a Boarduino (see below) and handy to have around for other purposes as well.

X10 Home Automation

  • x10-cm17a gem / project page
  • CM17A FireCracker kit — The FireCracker control module, one appliance module, one transceiver/lamp module, and a remote. Note that these are much cheaper on eBay. See links in the Buy Some Gear section below.

BetaBrite LED sign

Arduino development boards

XBee Radios

  • other xbee modules are pin-compatible, so pick the one that best suits your need, and remember that the Series 1 doesn’t fully support ZigBee
  • Arduino xbee shield

Buy some gear!

  • Keyspan USA-19HS — Froogle it or just hit up your local computer store. I got mine at CompUSA.
  • FTDI FT232R — Available on a breakout board from Sparkfun, or from Digi-Key and Mouser as a bare part.
  • FTDI TTL232R — Available in all configurations direct from FTDI, or in most configurations from Digi-Key and Mouser. If you’re doing a Boarduino, though, your best bet is Adafruit, because you can get a little price break if you get it bundled…
  • X10 gear — eBay. Try this search for “x10 firecracker”.
  • BetaBrite — Apparently they’re sold at Sam’s Club. We don’t have those in Oregon so I can’t confirm. I got mine from eBay. I use this search, which catches both “BetaBrite” and “Beta Brite”. You may be able to find other retailers too.
  • Arduino — Lots of options here. Sparkfun is a good one, but I prefer Adafruit. I recommend the Starter Pack, which comes with an Arduino, ProtoShield kit, battery, wall wart, USB cable, and some goodies to play with.
  • BoarduinoAdafruit. Be sure to tick the box to add the TTL232 cable if you need one. You’re going to have to solder this one… if you just don’t feel like it, email me and we can talk ;)
  • ProtoshieldAdafruit again. There’s also the Sparkfun one, but it’s more expensive and poorly designed (see the last paragraph in the description on Sparkfun to see what I mean)
  • XBee modulesDigi-Key or Mouser. Maybe other places too, but they’re who I’ve used.
  • XBee ShieldNKC Electronics, who sells on eBay as nkc_store. I’ve been very pleased with their service. NKC also sells some Arduino clones, for what it’s worth. Sparkfun sells exactly the same thing (albeit with an XBee module) for $80, which is highway robbery. Here’s the link, though, if you feel like throwing your money away :)

RubyConf 2007

October 8th, 2007

So the big (to me) announcement: I’ve been invited to speak at RubyConf 2007 next month! My presentation is called “Controlling Electronics with Ruby”, and you can read the proposal here. It’s going to be fun; I’ll be bringing along some hardware to demonstrate with :)

Also, for my own benefit I put together a calendar of the RubyConf sessions. It’s available here, feel free to grab it. You can probably subscribe to it using iCal or whatever, and if there are changes in the agenda, I’ll update it. It should contain timezones for everything, but I might have missed one or two, so please let me know if it’s wacky for you.

That’s all. See you in Charlotte!

On behalf of the entire LAIKA Information Technology department, it is my great pleasure to announce the release of a number of projects developed by the Information Systems group:

  • Athenaeum — A “live” web view of the contents of a Delicious Library
  • Growl Notifier — A plugin for CruiseControl.rb that sends build notifications to one or more Growl daemons.
  • Linen — A framework for building command-line interfaces
  • TextMate Bundle — Some of us use TextMate. This bundle includes some helpful commands and snippets that we wrote.
  • ThingFish — A network-accessable datastore with extensible metadata
    Please note that the ThingFish release is alpha quality, and much has changed between the current download and trunk. Watch for a new release Real Soon™

These projects were all developed to fit needs within our organization, but designed to be useful outside LAIKA as well. They’re released under the BSD license, and are therefore free to use, in every sense of the word.

Where To Get It

The primary source for LAIKA Open Source software is opensource.laika.com. This is a Trac instance, and is the main point of contact for all LAIKA open source projects. Check here first. File bugs here. Read documentation here :)

Downloads will also be hosted at RubyForge, so any of our projects that are available as gems will be installable via the normal gem mechanism. You can view our project page at laika.rubyforge.org and download our files at here.

About LAIKA

LAIKA is an animation studio based in Portland, Oregon (USA). We are currently working on two feature films and a large number of commercial projects. More information is available at laika.com

About LAIKA IS

LAIKA’s Information Systems group is a team of programmers, database administrators, and tech writers inside the Information Technology department. We make the shiny tools that help the rest of LAIKA do their jobs more easily, ease the sharing of information between groups, and solve mission-critical problems (like picking a place to go to lunch).

We believe in open source software. Many of the tools we use in-house are open source, and we feel strongly that we should give back whenever possible.

LAIKA’s IS department is:

  • Ben Bleything
  • Jeff Davis
  • Michael Granger
  • Steven J. Hall
  • Jeremiah Jordan
  • Myra Lavenue
  • Mahlon E. Smith
  • Anthony Roberts
  • Kim Wallmark

How to Contact Us

If you’ve got problems with the code, please file appropriate bugs in our Trac instance. If you’ve got general questions or comments, please email opensource AT laika, dot com.

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 :)

Once again, PDX.rb will be hosting an evening of wide-ranging talks about Ruby. This year the focus is on people doing strange things with Ruby. Strange, of course, is anything that’s just a little bit outside the usual. If you’ve created a new Ruby-based interface for hacking on your brand-new internet-enabled phone (rPhone anyone?) or composed your latest bit of metaprogramming magic, we’d love to hear about it.

We’ll be keeping the event open-ended and freeform. We’ll use the lightning-talk-inspired approach and give each presenter the opportunity to cram whatever they can into 10 minutes. Make it interesting and you might even get an extra minute or two. We’ve already selected 7 speakers, but there will be a few slots left open until the actual event.

Our speakers are:

  • Greg Borenstein — programming Arduino boards with Ruby
  • Lennon Day-Reynolds — Speaker’s Discretion
  • Giles Bowkett — Creating programmatic MIDI music with Ruby
  • John Lam — Running Ruby on the CLR
  • Ola Bini — JRuby!
  • Ian Dees — Radical Test Portability
  • Luke Kanies — Using Racc to write a real Domain Specific Language
  • You
  • ... or possibly… YOU

This is all taking place Tuesday, July 24th (hey, that’s today!) at 7:30 pm. The location is Holocene (map), here in beautiful Portland, Oregon.

There will be plenty of Ruby fun going on and lots of socializing with fellow Rubyists. Last year, FOSCON II was overflowing. We’ve found a new venue to fit you all in, so why miss it? Oh yeah, did I mention the free pizza?

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.

DorkbotPDX 0x00

June 16th, 2007

Since I primarily talk about Ruby here, you may not know that I’m also a hardware hacker… a beginner, in the scheme of things, but a hardware hacker nonetheless. Cool hardware hackers the world over have a group called Dorkbot:”http://dorkbot.org. Here in Portland we’ve got our own chapter: Dorkbot PDX, organized primarily by fellow Rubyist Thomas Lockney.

Dorkbot PDX is about to hold its first official event. Included below is the announcement. As it says, if you’re a hacker, painter, engineer or sculptor, musician or maker, you’ll fit right in. Come join us!

Dorkbot PDX 0×00

Come join DorkbotPDX, people doing strange things with electricity, for our inaugural event at Vendetta on June 24th at 5pm. If you’re a hacker, painter, engineer or sculpture, musician or maker you’ll fit right in. We bring together the tech and art worlds and enjoy it all over a pint of beer. We’ll have presentations and performances by these fine folks:

  • Jason Plumb is a software engineer by day…hardware hacker, reverse engineer, and experimental sound geek by night. He will provide an overview of the Essential Reality P5 glove controller and explain how it can be used with free and open-source software to create and manipulate sound.
  • Jesse Fox studied music composition and physics at Bates College before getting a Master’s Degree from the Center for Computer Research in Music and Acoustics at Stanford University. He will discuss his involvement with the League of Electronic Musical Urban Robots (LEMUR) and describe the detailed techincal recreation of George Antheil’s “Ballet Mecanique”, which includes xylophones, bass drums, tam-tam, pianists, electric bells, a siren, airplane propellers, and a volley of player pianos.
  • Donald Delmar Davis, principal research anarchist at D3 Laboratories, will overview the deconstruction of Arduino and Wiring platforms to create artistic robot platforms with AVR microcontrollers. “AI Begins With Self Destruction”
  • paint & copter create multi-media experiences of regurgitated and improvised media. By synthesizing live and pre-manipulated video feeds, field recordings and live instrumentation, Paint and Copter filter cultural noise and reprocess it into a new, mesmerizing thread.

We will also have a brief open-mic of sorts referred to as Open Dork. This is a show and tell where you can have the mic for a few minutes to discuss your latest project, vent about frustrations trying to get your art grant or tell us about the intricacies of the color blue. It’s your time to tell us what you think we need to hear.

Festivities will begin at 5pm and you can expect them to last until they kick us out. Please bring yourself, your friends and any thing you’d like to share.

http://dorkbotpdx.org/wiki/dorkbotpdx_0×00

........................................................................ .........dorkbot: people doing strange things with electricity.......... ......................... http://dorkbot.org ........................... ........................................................................

By this point, I would suspect that most Firefox readers who are reading this know about Greasemonkey. If not, go forth and read. I additionally suspect the same is true for Twitter. If not, you know what to do.

One thing that annoys me about Twitter is the avatar display on a user’s page. If I’m looking at (for instance) Geoff’s page, I see a lot of little tiny icons that I don’t recognize. I find myself hovering over each to see if they’re someone I know so I can click and friend them. I got sick of the hover delay, so I decided to fix it. I wrote a userscript that puts each users’ name next to their avatar image, and puts each on its own line.

I’d never worked with Greasemonkey, and only recently started playing with Javascript, so it was an experience. I was able to find a cool little XPath helper on the Greasemonkey wiki, which helped immensely. The code to actually do the manipulation is only about 10 lines long.

If you’re interested, you can grab the latest and greatest version of the script by clicking here. I should also plug my toys repository… it’s got all manner of fun junk laying about. Check it out with svn co http://svn.bleything.net/toys.

I’m damn sick of comment spam. To that end, I’ve set Mephisto to turn off commenting after 3 months and disabled comments for all articles older than that. You can always email me, it’s my first name at my last name dot net.

Fun with hpricot

May 15th, 2007

Those who know me personally know that I’m a pretty huge video game nerd. I’ve been wanting to learn hpricot better, so I decided to combine the two interests. I give you vgdod.rb, which goes and scrapes info about Amazon Video Games’ Deal of the Day. It could probably be optimized, and the XPath could likely be better, but it gets the job done!

It was interesting to try to write XPath for HTML that I didn’t control… this was the first time I’ve had that particular joy, and it was a good exercise. I think we (web developers, that is) sometimes forget that other people might want to manipulate our HTML at some point. Anyway, the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env ruby

%w(rubygems hpricot open-uri shorturl).each {|g| require g}
def fetch(url = '') ; return Hpricot(open("http://www.amazon.com" + url)) ; end

vg_url = fetch.at("a[text()=Video Games]")[:href]
dotd_img = fetch(vg_url).search("img").select {|e| e[:src] =~ /deal-of-the-day/}.first
dotd = fetch(dotd_img.parent[:href])

# title -- platform -- price -- url
printf "%s -- %s -- %s -- %s",
  dotd.at("//div.buying//b.sans").inner_text.strip,
  dotd.search("//b.price").last.inner_text.strip,
  dotd.search("//div[@class=buying]")[3].inner_text.gsub(/(\&nbsp;|\s|Platform:)/, ''),
  WWW::ShortURL.shorten("http://www.amazon.com#{dotd_img.parent[:href]}")

I have been getting absolutely slammed with stupid drug spam. Mephisto’s spam moderation stuff is pretty good, but the sheer volume required me to go down to the console to take care of the problem:

1
2
3
4
5
regex = /viagra|cialis|xanax|levitra|tramidol|valium|\
carisoprodol|tramadol|nexium|ultracet|allegra|\
zoloft|hoodia|snitz|ultram|levaquin|augmentin|\
prednisone|phentermine|fioricet|diethyproprion/i
Comment.find_all.select {|c| c.body =~ regex}.map(&:destroy).size

I was building the regex as I went along so I don’t have an exact count, but that probably deleted 500 comments. Much easier to moderate the other crap now.

Still alive; Feed redirects

April 19th, 2007

Dear readers,

Yes, I’m still alive. I’ve been insanely busy at my new(ish) job with LAIKA Inc, where I’ve been slinging Ruby since December. More about that later. I’m working on preparing a library I wrote at LAIKA for release, but until that’s finalized, I should probably keep it under my hat.

Also, I’ve set up rewrite rules to redirect my feeds to FeedBurner, inspired by Geoff’s recent post on the topic. If you notice anything funky about the feeds, please let me know!