I wanted to be able to pass any data to Arduino from my PC or the Internet. There are several ways to do that. The most obvious one is buying an
Ethernet Shield or
Bluetooth module, but they are more expensive than an actual Arduino Uno, so I looked for alternatives.

I wanted to create a web interface to control Arduino, so these
Serial-to-Network libraries seemed like the best solution to do it with PHP since it doesnt support serial connection (well actually there’s a
PHPSerial class for doing that but it didn’t word for me under Mac OSx Lion).

First I tried
SerialIP since it didn’t need any additional software on the host. However the
slattach command was removed in OSx 10.5. I recompiled it from
some source code I found on the Apple Open Source site but that didn’t work either. Compiling
SOCAT and looking for a similar command to attach the serial port to the network seemed too complicated so I passed to the next library.

SerialNet.pde uses Processing, a language based on Java and especially aimed to generate simple graphics, as a proxy. It worked like a charm and I was able to connect to the desired port trough Telnet.

However I wanted a cleaner solution that didn’t need a proxy, and then I found
Ruby SerialPort. It couldn’t be easier. Simply install the gem doing:

sudo gem install ruby-serialport

This is the Ruby code for the “Hello World”, you can find the path to your Arduino under the Tools > Serial Port menu of the Arduino SDK:require ‘rubygems’

Now connect a LED between the pins 13 and GND and upload this code to your Arduino:

Now simply run this using your Terminal to turn on the LED:

ruby yourfile.rb 1

And this to turn it off:

ruby yourfile.rb 0

And now you can even easily create a web interface to control your Arduino project using Rails or the Ruby web framework of your choice 🙂

PS: This has been tested under Mac OSx Lion, but should work under Linux and Windows provided that you have Ruby installed and you write the correct path to the Arduino serial port.