Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sinatra sample #8

Open
shokai opened this issue Oct 24, 2012 · 5 comments
Open

add sinatra sample #8

shokai opened this issue Oct 24, 2012 · 5 comments

Comments

@shokai
Copy link
Owner

shokai commented Oct 24, 2012

control arduino via HTTP

shokai added a commit that referenced this issue Oct 24, 2012
@shokai shokai closed this as completed Oct 25, 2012
@chrusttt
Copy link

it is not working for me always (sometimes does:)) but mostly i got error:
Errno::EAGAIN: Resource temporarily unavailable - write would block
running on 1.9.3 but tried on 1.9.2 also

@shokai
Copy link
Owner Author

shokai commented Dec 1, 2012

thank you for report. I'll check it.

@shokai shokai reopened this Dec 1, 2012
@shokai
Copy link
Owner Author

shokai commented Mar 13, 2013

on Linux OS, dissable nonblocking IO

arduino = ArduinoFirmata.connect '/dev/tty.usb-device-name', :nonblock_io => false

@shokai shokai closed this as completed Mar 13, 2013
@jbhatab
Copy link

jbhatab commented Oct 24, 2013

I have been playing around with this gem and have been having trouble with the sinatra script.

$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'rubygems'
require 'sinatra'
require 'eventmachine'
require 'arduino_firmata'

arduino = ArduinoFirmata.connect nil, :nonblock_io => true
arduino.pin_mode 13, ArduinoFirmata::OUTPUT

get '/' do
  redirect './on'
end

get '/on' do
  arduino.digital_write 13, true
  "<p><a href='./off'>LED OFF</a></p>"
end

get '/off' do
  arduino.digital_write 13, false
  "<p><a href='./on'>LED ON</a></p>"
end

This is the code I'm currently using, which does end in a sinatra page and supposed connection altough the led doesn't light up when I go to /on. I did remove :eventmachine => true because it was causing an error but I don't think it was even used in this code.

I have also tried setting :nonblock_io to false but then the ruby script just gets stuck at this line:
arduino = ArduinoFirmata.connect 'dev/tty.usbmodem1411', :nonblock_io => false

And I have gotten blink led to work. Does it have to do with the fact that I dont have a loop or do I need to use a special firmata for the arduino besides standard_firmata?

@shokai shokai reopened this Oct 25, 2013
@marciok
Copy link

marciok commented Feb 9, 2014

The sinatra example it only works if I connect to the arduino each call like:

get '/on' do
  arduino = ArduinoFirmata.connect
  analog = arduino.analog_read(0)
  arduino.digital_write 13, ArduinoFirmata::HIGH
  "<p>analog : #{analog}</p><p><a href='./off'>LED OFF</a></p>"
end

get '/off' do
  arduino = ArduinoFirmata.connect
  analog = arduino.analog_read(0)
  arduino.digital_write 13, ArduinoFirmata::LOW
  "<p>analog : #{analog}</p><p><a href='./on'>LED ON</a></p>"
end

which is not correct.
I can't figure out what is wrong, I tried to update firmata but nothing happend.

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

No branches or pull requests

4 participants