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.
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 :)
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:
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.
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.
Boarduino — the small breadboard-compatible Arduino clone I demonstrated
Simple Message System — an Arduino library that provides a simple ASCII messaging protocol. Look for Ruby bindings Real Soon Now™
Prototyping Shield — Note that Sparkfun also sells a ProtoShield. Lady Ada’s is far superior.
Arduino clones — There are a number of Arduino-compatible boards that are cheaper or have different design goals. I didn’t talk about these, but check out Freeduino and the Bare Bones Board
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.
Boarduino — Adafruit. 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 ;)
Protoshield — Adafruit 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 modules — Digi-Key or Mouser. Maybe other places too, but they’re who I’ve used.
XBee Shield — NKC 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 :)
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.
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
1234
>> 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:
1234567891011121314
>> b = 5=> 5>> b + 10=> 15>> exitsuperx ~...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?
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:
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.
.................................................................................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.
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:
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:
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.
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!
Not that I expect this to impact a lot of people or anything, but I wanted to let the intertubes know that I’m in the process of migrating services to a new machine. This may mean some downtime for bleything.net webservices (including this blog, the george demo, etc) as well as subversion and trac.
Also, I cut over my email services Friday morning, but hosed the config on the new box. If you emailed me and it bounced between about 7 and 10 PST Friday, it’s because I’m a biig idiot. Plz to re-send.
I know that back in December I’d have some news to post soon. This is not that news, but it’s news of a different type! The Rails Cookbook* is shipping, a fact that no doubt everyone reading this already knew.
What you might not know is that it contains three recipes written by yours truly. If you pick up a copy, look for these recipes:
Deploying with Capistrano When You Cannot Access Your SCM
Deploying Your Application To Multiple Environments with Capistrano
Increasing Performance by Caching Post-Processed Content
I should point out that the “can’t access SCM” uses code that’s based on Jim Morris’s work here. I thought I had mentioned that in the recipe itself, but it’s not in my review copy. Jim, if you’re reading this, I apologize for not giving you the credit due.
My experience with the topics covered in all three recipes came from real problems that I dealt with during my time at EDGE Design. If there is interest, I can talk in more detail about the problems and solutions.
I reviewed the book as well, and there’s some really cool stuff in there. It’s up through Rails 1.2, so if (like me) you like to learn from a cookbook-style thing, it’d be a good option to get caught up with the new stuff going on in Rails. Check it out!
Update: tweaked theProcto trace returns by default as well, and tell you what kind of call happened. Also tweaked the order of fields.
Just a quick little snippet to make up for my extended absence. This is probably old news to a lot of readers, but someone should get some value out of this.
Sometimes, you need to trace execution through your script. In my case, I’m debugging some tweaks to ActiveRecord::Migration and something is getting hosed along the way. Kernel#set_trace_func to the rescue!
Drop the following in your .irbrc, fire up irb, call enable_trace, and then whatever you’re trying to do:
1234567891011121314151617
defenable_trace( event_regex = /^(call|return)/, class_regex = /IRB|Wirble|RubyLex|RubyToken/ ) puts "Enabling method tracing with event regex #{event_regex.inspect} and class exclusion regex #{class_regex.inspect}" set_trace_func Proc.new{|event, file, line, id, binding, classname| printf "[%8s] %30s %30s (%s:%-2d)\n", event, id, classname, file, line if event =~ event_regex and classname.to_s !~ class_regex }returnenddefdisable_trace puts "Disabling method tracing" set_trace_func nilend
For bonus points, you can pass in alternate regexes depending on what you want to capture. Out of the box, it’ll only show you Ruby method calls, and will exclude anything that comes from a class matched by the class_regex parameter. Check out
For the past couple of weeks, my blog has been dead. I’m sure a number of you got curious why the RSS feed wasn’t updating and ventured to http://blog.bleything.net, only to find that I had left a bitchy message about how Typo was screwed up.
Well, those sentiments still apply, but I’m back in the blogging business. Today I finally migrated my blog to Mephisto. There are still some outstanding issues (permalinks, sections, etc) but for the moment, I’m rolling again.
I’d like to take this opportunity to remind everyone that you really ought to be reading my blog via the FeedBurner feed, which you can snag here. As soon as I get a little more comfortable with Mephisto and get a style worked out, I’ll be removing references to the built-in RSS feeds in favor of that… so switch now or I’ll force you to later ;)
I’ve got some news and some code to post, but it’ll have to wait for tomorrow. Cheers!
Recently I’ve noticed an uptick in the amount of bounces I’ve been getting… apparently someone is sending spam with my domain as the From: address. I’m sure this isn’t a new problem, just a new one for me.
Just this morning, in the time it took me to drive from home to work (about 20 minutes) I received 751 bounces. I suspect today is not going to be a good day for my spam counts.
Can anyone suggest a good solution to this problem? One thing I know I have to do is get rid of my catchall address. That’s a long process, though, because I’ve been taking advantage of it for years and I have about a billion services I need to change email addresses on.