Just got back from this month’s ORUG, where Matthew Williams gave a presentation on using Ruby to control an Arduino. Matt is a very natural speaker, and the presentation was great. He even demoed a bartending robot he built, which should be featured on Make very soon.
I took notes during the presentation, and they are as follows, with links where possible.
Matthew Williams
Physical Computing with Ruby and Arduino
Arduino is an open-source board
There’s Bluetooth Arduino boards
There’s an Arduino board that was developed in a circular shape. People have combined this with conductive thread and sewn it into clothing. Someone even integrated this with some LEDs into their clothing and made a shirt with turn signals for biking.
Matt showed a video of a Wii nunchuck integrated with an Arduino, hooked up to some servos, and made a robotic puppet that works just by moving the nunchuck (not the control stick, just the accelerometer motion).
There’s also a YouTube video with someone who built a 1-wheel Segway-esque skateboard. Matt claims there are only about 50 lines of code controlling this device.
So, onto the Ruby Arduino Framework.
http://rad.rubyforge.org/ << outdated
http://github.com/atduskgreg/rad/ << more up to date
Matt says that the Arduino Google Group is fantastic.
[Tim: The Arduino IDE looks a *lot* like the Processing IDE (the Java-based graphics language).]
RubyToC – Ruby To C project; converts your Ruby code into C++, then compile it into Arduino bytecode. Then, there are Rake tasks which will load it onto the board for you. Most — but not all — of the Arduino API has been ported to Ruby.
RAD Methods
input_pin(s)
output_pin(s)
digitalWrite | digitalRead
analogWrite | analogRead
serial_print | serial_read
He mentions a slick trick for controlling the 7-segment LED displays. Since there’s 7 segments, you need to set 7 values separately, OR just create an array of those, and set them all with a single assignment.
Coming soon to RAD framework:
- Testing
- Arduino Simulator (for testing)
- Better RubyToC support (there’s a few hacks required because ToC isn’t perfect)
- More “out of the box” support
Arduino “shields”
Shields are boards that can be plugged directly on top of the Arduino that add major new functionality.
Where to buy? Only $34.95 at
http://www.sparkfun.com
http://www.makezine.com (Matt strongly recommends subscribing to Make, says the dead trees copy is excellent)
Cheaper versions are available, but they either have components removed, or you must assemble it yourself
Make published a “get started with Arduino” kit, about $80, includes project info, the Arduino, extra parts. Most of the parts required for the project are included in the kit.
Barduino – DRINK MIXING ROBOT (created by Matt, who is clearly demonstrating his aptitude as a proper geek)
He used windshield washer pumps, $9/each
Matt created a DSL for describing drinks
drink ‘Screwdriver’ do
serve_in ‘Highball Glass’
ingredients do
2.ounces :vodka
5.ounces :orange_juice
end
end
Matt mentioned a hack, some functions that accept only one param will get converted (by RubyToC) to functions that accept none, so, the following line fixes it
def dispense(pump)
foo = pump + 0 /* This is the fix */
…
end
For more Ruby Arduino…
RubyConf 2008, Friday, 10:25 – 11:05, Room 3
Greg Borenstein — author of the Ruby Arduino framework — is presenting
Questions:
Can you “brick” an Arduino?
Not via code, but you could put too much power into it and fry it. Matt thinks there’s a little surge protection on it.
Can you sync Arduinos?
He’s seen something like it, and thinks that the serial comm lines would make it fairly easy to do.