Skip to content

Instantly share code, notes, and snippets.

@letsbreelhere
Created September 1, 2012 21:07
Show Gist options
  • Save letsbreelhere/3587353 to your computer and use it in GitHub Desktop.
Save letsbreelhere/3587353 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'serialport'
port_str = "/dev/tty.usbmodemfa131"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
set sp: SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
post '/' do
settings.sp.putc("a\r\n")
'Success!'
end
@srbiv
Copy link

srbiv commented Sep 1, 2012

Care to explain what this does? Any setup?

@letsbreelhere
Copy link
Author

The only set up is probably changing port_str to the name of the USB device on your box. The rest of the params are pretty standard (and the baud rate of 9600 is specified in the Arduino part as well), and the only writing going on in this case is the #putc method. Also, Arduino seems to only read a string once it gets a CRLF (\r\n).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment