Sunday, July 5, 2009

Arduino IDE Meets Ruby

Scripting languages have evolved a lot in the recent years. Ruby in particular, has had such a significant impact, that there are entire teams dedicated to maintaining it's visual identity across the web.


Designed by Tom Schaub is a widely used logo for the ruby programming language.

Sporting some flashy ruby icons, is the Scripting tab in the Arduino IDE. Upon startup, a listing of your ruby script files is generated from your Sketchbook directory.


Don't look, yet!

Of course there's no scripts in there, you need to crack open your ruby reference and create some. Once you do, you'll see how easy it is to automate repetitive tasks.

Hello_Arduino_World.rb code listing:
puts("Hello Arduino World")
Click RUN and you will get the standard output right to the console:


File I/O
How about writing to a file from a ruby script? Well that's easy:
myFile  = File.new("test.txt","w")

myFile.puts("Writing a line to a text file.")
myFile.puts("And Another.")

myFile.close()



Ruby scripting support is built into the Antipasto Arduino IDE in versions 0.8.11 or greater.



Enjoy!

5 comments:

ryan said...

so does this mean that there is a ruby api for the arduino? what would i use this for?

Chris said...

@Ryan
Yes! The Ruby API will be able to command the IDE.

The Arduino Ruby API link is still being worked on, but the fundamental scripting framework now exists.

Omar's got a short list of implemented API calls, but you will be able to write scripts that look something like this:

Arduino.compile()
Arduino.upload()

myFile = File.new("Arduino_serial_log.txt","w")

while( Arduino.SerialAvailable() ) {
myFile.puts(Arduino.SerialRead())
}

myFile.close()


I'm really excited to see the API get traction over the next couple of releases!

ryan said...

@Chris

So the Ruby API is for interacting with the IDE, not necessarily for generating code that will compile for the Arduino, correct?

mike said...

@ryan

From what I can tell, they are not running anything derived from the ruby code on the Arduino. By providing a ruby interface into the Arduino IDE, you can build things akin to build scripts (send a proprietary config to the device via serial, perhaps) and unit tests (verify that, whilst running, the Arduino performs in an expected fashion).

Thomas Lockney said...

I know I'm a bit late to find this and add to the discussion, but in case you haven't already found it, you should definitely check out RAD (Ruby Arduino Developlment) which lets you write Ruby code that gets translated into Arduino code. It was written by my friend Greg Borenstein and I'm quite sure he would love to hear about your developments.

http://rad.rubyforge.org/