Interfacing...
Arduino and Ruby
The SerialPort gem seems to do the job.
simplest example
Here's a simple example of how to read from the arduino (inefficiently) via ruby using the SerialPort gem. You may have to change the port_str param (or use an integer for that param as port number). See the readme within the ruby-serialport download.
#simplest ruby program to read from arduino serial,
#using the SerialPort gem
#(http://rubygems.org/gems/serialport)
require "serialport"
#params for serial port
port_str = "/dev/ttyUSB0" #may be different for you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
#just read forever
while true do
printf("%c", sp.getc)
end
sp.close #see note 1
- note 1: As with the File api, you can instead use SerialPort.new() or .open() with a block to have the resource automatically closed for you (more robust).
Arduino gem is a prototyping API for Arduino in Ruby. Helps prototype Arduino programs quickly from the computer, without the need to burn programs to the board frequently. It's a "burn once, write many programs" solution.
See also
others using the SerialPort gem: