Skip to content

Instantly share code, notes, and snippets.

@savannahniles
Created December 10, 2013 23:05
Show Gist options
  • Save savannahniles/7902051 to your computer and use it in GitHub Desktop.
Save savannahniles/7902051 to your computer and use it in GitHub Desktop.
A Simple Ruby Program to Read Arduino serial over bluetooth and send an email, (say, to use IFTTT).
#simplest ruby program to read from arduino serial,
#using the SerialPort gem
#(http://rubygems.org/gems/serialport)
require "serialport"
require "pony"
#params for serial port
port_str = "/dev/tty.supershoesBT1-SPP" #may be different for you
#port_str = "/dev/tty.usbmodemfd121" #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
while (i = sp.gets) do # see note 2
puts i
#puts "String"
#puts i.class #String
#email people here
Pony.mail(:to => '[email protected]', :from => '[email protected]', :subject => "#MLPartyMachine", :body => "On " + Time.now.strftime("%B %d at %I:%M %p") + ", people partied. #MLPartyMachine")
end
end
sp.close #see note 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment