(Arduino Serial Ruby on YouTube)
For the last month or so, Brett and Marcus from Tables Turned and I have been meeting weekly to teach ourselves Physical Computing, the use of micro-controllers like those found in cell phones and Roombas to build all kinds of interactive projects, from multimedia installations to scientific equipment.
We’re using Arduino, a cheap and simple micro-controller chip and programming framework that’s great for beginners. Between the three of us, we’ve got lots of ambitious projects we’d like to build, from immersive sound installations to wifi-enabled street walking robots, but in order to learn the basics, we’re starting with a pretty simple project: building our own version of the children’s toy Simon. If you’re interested, you can follow our progress on the ComputerKraft wiki.
The two videos I’ve posted here show some early experiments we tried out while learning the ropes. The one below is amongst the first things we ever tried: reading the analog input from a knob and using its position to light up a changing number of LEDs.
The video at the top is from this week and I’m pretty proud of it. It shows a Ruby program running on my computer that reads input from a user and then lights up a different LED depending on what number it receives. This doesn’t sound too impressive; after all, it’s just another ‘hello world’. But the elements involved are really exciting to me. With them in place, pretty much anything you can do in Ruby scripts, Arduino can know about — reading RSS feeds, looking for files, user input, etc. Plus, from here, it doesn’t take much more to get the interaction to flow both ways: when Arduino does something or senses something, it can get sent off to a Ruby program and from thence to files, the web etc.
If you’re curious to know more about the technical details, you can check out the Ruby/serial demo page on the ComputerKraft wiki. It’s got both the Ruby and C source code as well as an explanation of the hardware and links for downloading the ruby/serialport library (which does, in fact, work on OS X even though their documentation gives you little confidence that it would). Or, if Ruby’s not your thing, you can check out Todbot’s C code for doing this manually from the command line to accomplish something similar.
Tagged: arduino, ruby, serial, physical+computing, microcontroller, computerkraft
This is very cool. Ruby Ajax sites + Arduino are next!
So why don’t you guys bring some of your magic tricks down to the next dorkbotpdx meeting? http://dorkbot.org/dorkbotpdx
Hi Greg,
I’ve just started to play around with Arduino myself. I read your post on Arduino and Ruby and followed your example. As a ruby developer I’m wondering if there’s a way to skip the Arduino sketch and write the whole thing in Ruby? Will I have to write an Arduino sketch everytime I want to use Ruby?
If you have any other examples please let me know. I hope to write a small set of Ruby to Arduino examples once I become some what familiar with the serialport library.
Thanks for the great content!
Jose
Jose —
Unfortunately there’s no way to get Ruby code into such a constrained environment as the Arduino’s microcontroller, so you’re stuck with C and the sketches. Since Ruby’s implemented in C, I guess that someone way smarter than me might be able to write a Ruby library that would compile into Arduino-compatible C, but I’ve never heard of such a thing.
For most basic purposes, the C needed for Arduino sketches is really not so bad. The Arduino folks wrote kind of a nice DSL for all the basic functions like reading input and sending output. I learned enough C to feel pretty comfortable in about an hour.
Hi, did you run into any hitches compiling ruby/serialport for OSX? I am trying to do so on my mac mini (10.4.9) with xcode installed, but I get an error message when i run extconf.rb, complaining about a missing file.
I just watched a couple of you-tube videos demonstration RAD – Ruby Arduino Development, (see ruby forge) where someone has indeed created a way of turning ruby into Arduino’s C.
Yes, anonymous, it’s true! There’s now a way to program the Arduino in Ruby. It’s my own project! Here’s the post about it:
http://www.urbanhonking.com/ideasfordozens/archives/2007/07/rad_the_first_s_9.html
And here’s the presentation I gave on it at FOSCON:
http://atduskmusic.com/rad_presentation