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. Austin Vance
    arduino
    the ruby
    way
    Monday, November 5, 12

    View full-size slide

  2. Monday, November 5, 12

    View full-size slide

  3. /austinbv
    @austinbv
    Monday, November 5, 12

    View full-size slide

  4. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  5. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  6. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  7. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  8. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  9. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  10. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  11. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  12. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  13. arduino.. what now?
    Monday, November 5, 12

    View full-size slide

  14. what can you do with it?
    Monday, November 5, 12

    View full-size slide

  15. can’t
    what can you do with it?
    Monday, November 5, 12

    View full-size slide

  16. can’t
    What can you do with it?
    Monday, November 5, 12

    View full-size slide

  17. can’t
    What can you do with it?
    Monday, November 5, 12

    View full-size slide

  18. can’t
    What can you do with it?
    Monday, November 5, 12

    View full-size slide

  19. can’t
    What can you do with it?
    Monday, November 5, 12

    View full-size slide

  20. can’t
    What can you do with it?
    Monday, November 5, 12

    View full-size slide

  21. the ide
    Monday, November 5, 12

    View full-size slide

  22. the ide
    Monday, November 5, 12

    View full-size slide

  23. the ide
    Monday, November 5, 12

    View full-size slide

  24. Burn code
    to the
    arduino
    Monday, November 5, 12

    View full-size slide

  25. •standalone
    •isolated
    •small
    Monday, November 5, 12

    View full-size slide

  26. developed by Greg Borenstein
    Ruby Arduino Development
    RAD
    Monday, November 5, 12

    View full-size slide

  27. Ruby
    class Blinky < ArduinoSketch
    output_pin 13, :as => :led
    def loop
    blink led, 100
    end
    end
    Monday, November 5, 12

    View full-size slide

  28. Ruby compiles to C
    #include
    #include
    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

    View full-size slide

  29. debugging
    outdated
    Monday, November 5, 12

    View full-size slide

  30. Talk with
    the
    Arduino
    Monday, November 5, 12

    View full-size slide

  31. •standalone
    •isolated
    •small
    Monday, November 5, 12

    View full-size slide

  32. •standalone
    •isolated
    •small
    Monday, November 5, 12

    View full-size slide

  33. •standalone
    •isolated
    •small
    Monday, November 5, 12

    View full-size slide

  34. •standalone
    •isolated
    •small
    Monday, November 5, 12

    View full-size slide

  35. •standalone
    •small
    Monday, November 5, 12

    View full-size slide

  36. ✓standalone
    •small
    Monday, November 5, 12

    View full-size slide

  37. ✓standalone
    ✓small
    Monday, November 5, 12

    View full-size slide

  38. isolation is not import
    Monday, November 5, 12

    View full-size slide

  39. Monday, November 5, 12

    View full-size slide

  40. async
    Monday, November 5, 12

    View full-size slide

  41. 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

    View full-size slide

  42. complex logic
    and problems
    Monday, November 5, 12

    View full-size slide

  43. small C++ library
    complex logic
    and problems
    Monday, November 5, 12

    View full-size slide

  44. message passing
    Monday, November 5, 12

    View full-size slide

  45. ?
    Monday, November 5, 12

    View full-size slide

  46. dino
    introducing!
    Monday, November 5, 12

    View full-size slide

  47. Goals
    • fully tested
    • easy to extend
    • great documentation
    • zero startup time
    • fun
    Monday, November 5, 12

    View full-size slide

  48. beginning development
    and use what’s there
    thank you duino && node.js
    Monday, November 5, 12

    View full-size slide

  49. Asynchronous in a synchronous
    world
    Monday, November 5, 12

    View full-size slide

  50. Event Machine
    Monday, November 5, 12

    View full-size slide

  51. 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

    View full-size slide

  52. Monday, November 5, 12

    View full-size slide

  53. roll our own
    •developer control
    •specific to the gem
    •zero dependencies
    Monday, November 5, 12

    View full-size slide

  54. How did it turn out?
    Monday, November 5, 12

    View full-size slide

  55. class Board
    Monday, November 5, 12

    View full-size slide

  56. ==
    Monday, November 5, 12

    View full-size slide


  57. Monday, November 5, 12

    View full-size slide

  58. class TxRx
    Monday, November 5, 12

    View full-size slide

  59. Monday, November 5, 12

    View full-size slide

  60. finds the arduino
    Monday, November 5, 12

    View full-size slide

  61. injected into the board
    Monday, November 5, 12

    View full-size slide

  62. oh the possibilities
    Monday, November 5, 12

    View full-size slide

  63. don’t panic
    Monday, November 5, 12

    View full-size slide

  64. module Components
    Monday, November 5, 12

    View full-size slide

  65. class < BaseComponent
    Monday, November 5, 12

    View full-size slide

  66. class Led
    Monday, November 5, 12

    View full-size slide

  67. def initialize(options={})
    super(options)
    set_pin_mode(:out)
    digital_write(Board::LOW)
    end
    def on
    digital_write(Board::HIGH)
    end
    def off
    digital_write(Board::LOW)
    end
    Monday, November 5, 12

    View full-size slide

  68. board =
    Board.new(Dino::TxRx.new)
    led =
    Led.new(pin: 2, board: board)
    led.on
    sleep 2
    led.off
    Monday, November 5, 12

    View full-size slide

  69. class Button
    Monday, November 5, 12

    View full-size slide

  70. def initialize(options={})
    self.board.add_digital_hardware(self)
    self.board.start_read
    end
    #...
    def update(data)
    case data
    when UP
    button_up
    when DOWN
    button_down
    end
    end
    Monday, November 5, 12

    View full-size slide

  71. Monday, November 5, 12

    View full-size slide

  72. down = proc { led.on }
    up = proc { led.off }
    button.down(down)
    button.up(up)
    Monday, November 5, 12

    View full-size slide

  73. class Sensor
    Monday, November 5, 12

    View full-size slide

  74. 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

    View full-size slide

  75. on_data = proc { |data|
    puts data
    }
    sensor
    .when_data_received(on_data)
    Monday, November 5, 12

    View full-size slide

  76. class Stepper
    Monday, November 5, 12

    View full-size slide

  77. 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

    View full-size slide

  78. 1600.times do
    stepper.step_cc
    sleep 0.001
    end
    1600.times do
    stepper.step_cw
    sleep 0.001
    end
    Monday, November 5, 12

    View full-size slide

  79. and many more
    Monday, November 5, 12

    View full-size slide

  80. and many more
    Monday, November 5, 12

    View full-size slide

  81. and many more
    Monday, November 5, 12

    View full-size slide

  82. and many more
    Monday, November 5, 12

    View full-size slide

  83. and many more
    Monday, November 5, 12

    View full-size slide

  84. Lets see it in action
    Monday, November 5, 12

    View full-size slide

  85. 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

    View full-size slide

  86. Monday, November 5, 12

    View full-size slide

  87. initializer
    Monday, November 5, 12

    View full-size slide

  88. sinatra
    board = Board.new(Dino::TxRx.new)
    cannon =
    Led.new(pin: 2, board: board)
    put ‘/launch‘ do
    cannon.on
    end
    Monday, November 5, 12

    View full-size slide

  89. /austinbv/dino
    @austinbv
    Thank You!
    Monday, November 5, 12

    View full-size slide