Arduino and Ruby on Leopard

June 01, 2009 - 4 Comments - arduino ruby tools

The Backstory: I spent the majority of my last Saturday at the Maker Faire, an event centered around showing off all the amazing things that people have made themselves. Everything you can think of got due coverage, from robotics to custom musical instruments to automated fabrication to clothes and food. It was a great event and I’d recommend anyone with the hacker spirit to check it out next year.

While I was there, one of the focal points of my interest was around all the amazing things being done with the Arduino, a small circuit board with a microcontroller, programmable through USB. I had read about it before, first I believe in connection with Archaeopteryx, the probabilistic step-sequencer from the venerable and widely-hated Giles Bowkett. My curiosity was already primed and ready by the time I discovered the Arduino starter kit, which included sensors, LEDs, jumper wires, a book, and other assorted things I needed to begin pursuing my long-dissuaded desire to hack around with physical computing.

Of course, rarely can a new course of creativity be explored without my asking myself, “Cool, but can it be done in Ruby?” Thanks to the awesome RAD project, yes it can! But not without a small bit of fixing. What follows is details on how I got RAD working on Leopard to get down to the business of hardware hacking.

Step 1: Install the Arduino IDE and drivers

Download them here, then run the install package. Drag the arduino-0015 directory to your Applications directory (your version may be different, and this may not make a difference). Now, to install the drivers, find the drivers directory in your installation and run the install package appropriate to your machine (choose the Intel package if you have a newer Intel Mac). The installer will have you restart your machine.

Step 2: Install RAD

sudo gem install rad. Simple!

Step 3: Check your ParseTree version

The current version of RAD does not work with the latest version of the ParseTree gem. To get it working, you will need to make sure that 2.2.0 is the latest version you have on your machine. sudo gem install ParseTree -v "2.2.0" will get you the right version. Now do sudo gem list to see if you have a later version. If so, uninstall it with sudo gem uninstall ParseTree -v "[YOUR VERSION]".

Step 4: Create your first RAD project

Now you can create a RAD project just like it says on RAD’s homepage. Just run rad project_name, then edit config/hardware.yml and config/software.yml. You can find the correct serial_port by plugging your Arduino into your USB port, running the Arduino IDE, going to the Tools menu, then seeing the list of serial ports available; i used the one that looked like /dev/cu.usbserial-A6008cPM; yours may be different.

Step 5: Configure the project for the ATMEGA328

Take a look at your Arduino, and you should see a sticker with a label on it indicating the model of microcontroller your Arduino has. The newest Arduino uses the ATMEGA328, for which you’ll need to do some special configuring in your RAD project.

First, in your hardware.yml file, change the mcu entry to atmega328p. This will enable the compilation process to work correctly.

Now, find the makefile.erb file in your project (CMD-T in TextMate) and search for UPLOAD_RATE (line 77 in mine). You will want to change that entry to 57600. Now uploading your sketch to the microcontroller should go smoothly.

Step 6: Do something cool

You should now be good to go! Edit your sketch in project_name.rb, check out the examples, go nuts! All of the syntax you see in typical, non-Ruby Arduino sketches will work just the same in your Ruby sketches. There are some caveats with what Ruby you can use, but it’s easy to figure out for the most part by reading through the examples. After getting everything set up, I managed to work through Getting Started with Arduino in one morning, followed up by some tinkering of my own.

If you find any difficulty following this setup procedure, please let me know and I’ll update this post so it can be as helpful as possible. Now go crazy, do some cool hardware hacks, and post them to your blog! Maybe one day you will have something cool to show off at Maker Faire, Burning Man, or other creative outlet of your choice.

Comments

The Web is collaborative. Isn't it great?

759198b2dc1a352419d218c164510c8b?s=50

Gabriel said:

Hey Chris, shouldn’t it be ParseTree v. 2.2.0, as indicated here, on the RAD Google Group ?

11611e595f8866809b075a8e718e7600?s=50

Chris Vincent said:

Ah, thank you for pointing that out, Gabriel! I have fixed the version number in the post.

5a837592409354297424994e8d62f722?s=50

Ryan Davis said:

ruby2c just got released with a switch over to ruby_parser. RAD should be released shortly behind ruby2c (don’t update until it does!). Once that happens then Step 3 should be null and void.

11611e595f8866809b075a8e718e7600?s=50

Chris Vincent said:

Great news, Ryan! Thanks for helping to keep this post up-to-date. :)

Say Your Peace

Textile is allowed. Be polite. Be rude. I don't really give a fuck.

Your email will be kept safe and will never be publicly displayed.

 

Wha...?

11611e595f8866809b075a8e718e7600

Chris Vincent is a 20-something drummer, producer, and engineer from the Bay Area. This is where he writes whatever the hell he wants whenever the hell he wants to write it. Check your expectations at the home page.

Available for hire!

Looking for a top-notch Rubyist for contract? Check my resumé and drop me a line!

Obligatory tag cloud

me san francisco bicycling ruby tdd css tools iphone games rails facebooker queue facebooker facebook arduino activerecord sql css tools development process company culture spam akismet bluepill god

Recent posts

Feed me

Atom is cool.

Get in touch

Questions, comments, ideas?
Let's talk.

Unabashed self-promotion

Recommend Me