Upgrade to Pro — share decks privately, control downloads, hide ads and more …

arduino the ruby way

Austin
November 02, 2012

arduino the ruby way

Writing software is great, websites, applications, and scripts are things we interact with every day. What about writing software that we can interact with in the physical world? From automated sprinkler systems that turn off when you pull into your drive way, to scoreboards at the company foosball table physical computing opens a door for the innovator inside every software engineer.
It's too hard
Not true, there are amazing libraries and compilers that let us write software for Arduinos in the best language, Ruby. Think about it no C, no headers, and no static types, just plain old ruby. That is a good deal.

In this talk I will go over a few of the most popular Ruby libraries for interacting with an Arduino, talk about some basics of each library and then spend time on how these libraries and Arduino can interact to create applications that respond in the physical world. There will be t-shirts shot from a robotic cannon.

Austin

November 02, 2012
Tweet

Other Decks in Technology

Transcript

  1. Ruby class Blinky < ArduinoSketch output_pin 13, :as => :led

    def loop blink led, 100 end end Monday, November 5, 12
  2. Ruby compiles to C #include <WProgram.h> #include <SoftwareSerial.h> void loop();

    void setup(); int main(); int led(); void loop(); int _led = 13; int led() { return _led; } void setup() { pinMode(13, OUTPUT); } void blink(int pin, int ms) { digitalWrite( pin, HIGH ); delay( ms ); digitalWrite( pin, LOW ); delay( ms ); } int main() { init(); setup(); for( ;; ) { loop(); } return 0; } void loop() { blink(led(), 100); } class Blinky < ArduinoSketch output_pin 13, :as => :led def loop blink led, 100 end end Monday, November 5, 12
  3. ecto/duino The Arduino listens for low-level signals over a serial

    port, while we abstract all of the logic on the Node side. “ ” Monday, November 5, 12
  4. Goals • fully tested • easy to extend • great

    documentation • zero startup time • fun Monday, November 5, 12
  5. EM.run do board = RubyDuino::Board.new board.callback do board.send_message '0013001' do

    EM::add_periodic_timer 0.5 do board.send_message “0013#{blink}” end end end end Monday, November 5, 12
  6. down = proc { led.on } up = proc {

    led.off } button.down(down) button.up(up) Monday, November 5, 12
  7. def initialize(options={}) @data_callbacks = [] @board.add_analog_hardware(self) @board.start_read end def update(data)

    @data_callbacks.each do |callback| callback.call(data) end end Monday, November 5, 12
  8. def step_cc digital_write(Board::HIGH, pins[:dir]) digital_write(Board::HIGH, pins[:step]) digital_write(Board::LOW, pins[:step]) end def

    step_cw digital_write(Board::LOW, pins[:dir]) digital_write(Board::HIGH, pins[:step]) digital_write(Board::LOW, pins[:step]) end Monday, November 5, 12
  9. use it with any ruby script reporter = proc {

    if system('./build') green.on && red.off else green.off && red.on end } button.down(reporter) Monday, November 5, 12
  10. sinatra board = Board.new(Dino::TxRx.new) cannon = Led.new(pin: 2, board: board)

    put ‘/launch‘ do cannon.on end Monday, November 5, 12