This gem is a prototyping API for Arduino in Ruby. Helps prototype Arduino programs quickly from the computer, without the need to burn to the board frequently.
- Install the gem:
gem install arduino
- Load arduino.pde onto your Arduino dev board (just once and for all).
- Import the arduino gem:
#Arduino.new(port, baudrate) board = Arduino.new("/dev/ttyUSB1")
Port is something like "/dev/ttyUSB0" on linux and COM*x* (COM1/COM2) on windows. Baudrate is optional. It is 115200 by default.
The output pins must be set explicitly.
You don't need to declare input pins since digital pins are input by default according to the page on the Arduino site - http://www.arduino.cc/en/Tutorial/DigitalPins
trueif pin state is high, else it returns
Arduino.analogRead(pin)- returns the analog value
Arduino.analogRead(pin, value)- sets the analog value
Arduino.turnOff - sets all the pins to low state
Arduino.close - closes serial connection. Using this makes sure that you won't have to disconnect & reconnect the Arduino again to recover the serial port.
# This is the blink program. require "arduino" #specify the port Baudrate is optional and set to 115200 by default board = Arduino.new("/dev/ttyUSB1") #declare output pins board.output(13) #perform operations 10.times do board.setHigh(13) sleep(1) board.setLow(13) sleep(1) end
© 2010 Akash Manohar firstname.lastname@example.org under the MIT License
Thanks to the following people:
- @unsymbol - for fixing the Ubuntu reset problem