This articles was published on 2013-05-20
Two month ago I ported mruby to the Arduino Due. That was quite awesome at a first glance but it didn’t took long for me to realise that the workflow is actually not satisfiable.
Running mruby on a Microcontroller is in so far quite annoying that the write, compile, upload and execute cycle is just to long and so not Ruby-like.
In Ruby-land you actually write your program and execute it immediately. No compilation, no uploading. Instead: direct feedback.
For mruby on a Microcontroller you actually have to:
mrbcfor your host
libmruby.afor your target by using
Compiling and Uploading will take you easily up to several minutes. And you only get the feedback you have implemented and compiled.
So all in all we have cross-compiled mruby to Arduino Due and the result is that now our workflow is much more complicated, slower and less flexible. What a success… :-(
Instead of giving up on this stupid idea I decided to target the problem from a new angle. Why do we actually have to follow the same workflow our C colleagues have to go?
Actually we don’t have to. Quite exactly a year ago I implemented the
mirb, the mruby Interactive Ruby Shell. With this shell it is possible to execute Ruby code directly, kind of like the original IRB. So as a happy birthday gift to my mirb implementation from last year I transformed the mirb into a native ARM application which can run directly on the Arduino Due. I replaced the command line interface with the serial interface so that I can communicate serial directly to it. And so I can now execute pure Ruby directly on my Microcontroller:
boviAir:~ daniel$ sudo screen /dev/cu.usbmodemfa131 IAS - Interactive Arduino Shell This is a very early version, please test and report errors. Thanks :) > 1 + 1 => 2 > Led.high! => nil > Led.low! => nil >
This example is actually turning on and off the led on pin 13!
After playing over the last couple of days with this concept I totally fall in love with it. Finally I’m feeling like a Rubyist when programming my Microcontrollers. As you see there is no need for (native or cross) compilation, no need to upload anything and no need to have any kind of development tools on your machine. The only thing you need is a serial terminal and you are ready to go. Enter your code and it will be executed. It is a REPL for an Arduino.