arduino the ruby way

2c85484c7e19760334d44c29caba7823?s=47 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.

2c85484c7e19760334d44c29caba7823?s=128

Austin

November 02, 2012
Tweet

Transcript

  1. Austin Vance arduino the ruby way Monday, November 5, 12

  2. Monday, November 5, 12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    12
  21. the ide Monday, November 5, 12

  22. the ide Monday, November 5, 12

  23. the ide Monday, November 5, 12

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

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

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

    5, 12
  27. Ruby class Blinky < ArduinoSketch output_pin 13, :as => :led

    def loop blink led, 100 end end Monday, November 5, 12
  28. 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
  29. debugging outdated Monday, November 5, 12

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

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

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

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

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

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

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

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

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

  39. Monday, November 5, 12

  40. async Monday, November 5, 12

  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
  42. complex logic and problems Monday, November 5, 12

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

    12
  44. message passing Monday, November 5, 12

  45. ? Monday, November 5, 12

  46. dino introducing! Monday, November 5, 12

  47. Goals • fully tested • easy to extend • great

    documentation • zero startup time • fun Monday, November 5, 12
  48. beginning development and use what’s there thank you duino &&

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

  50. Event Machine Monday, November 5, 12

  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
  52. Monday, November 5, 12

  53. roll our own •developer control •specific to the gem •zero

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

  55. class Board Monday, November 5, 12

  56. == Monday, November 5, 12

  57. ♥ Monday, November 5, 12

  58. class TxRx Monday, November 5, 12

  59. Monday, November 5, 12

  60. finds the arduino Monday, November 5, 12

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

  62. oh the possibilities Monday, November 5, 12

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

  64. module Components Monday, November 5, 12

  65. class < BaseComponent Monday, November 5, 12

  66. class Led Monday, November 5, 12

  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
  68. board = Board.new(Dino::TxRx.new) led = Led.new(pin: 2, board: board) led.on

    sleep 2 led.off Monday, November 5, 12
  69. class Button Monday, November 5, 12

  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
  71. Monday, November 5, 12

  72. down = proc { led.on } up = proc {

    led.off } button.down(down) button.up(up) Monday, November 5, 12
  73. class Sensor Monday, November 5, 12

  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
  75. on_data = proc { |data| puts data } sensor .when_data_received(on_data)

    Monday, November 5, 12
  76. class Stepper Monday, November 5, 12

  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
  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
  79. and many more Monday, November 5, 12

  80. and many more Monday, November 5, 12

  81. and many more Monday, November 5, 12

  82. and many more Monday, November 5, 12

  83. and many more Monday, November 5, 12

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

  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
  86. Monday, November 5, 12

  87. initializer Monday, November 5, 12

  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
  89. /austinbv/dino @austinbv Thank You! Monday, November 5, 12