+ All Categories
Home > Technology > Arduino the ruby_way

Arduino the ruby_way

Date post: 14-May-2015
Category:
Upload: austinbv
View: 338 times
Download: 1 times
Share this document with a friend
Description:
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.
Popular Tags:
89
Austin Vance arduino the ruby way Monday, November 5, 12
Transcript
Page 1: Arduino the ruby_way

Austin Vance

arduinothe ruby way

Monday, November 5, 12

Page 2: Arduino the ruby_way

Monday, November 5, 12

Page 3: Arduino the ruby_way

/austinbv

@austinbv

Monday, November 5, 12

Page 4: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 5: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 6: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 7: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 8: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 9: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 10: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 11: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 12: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 13: Arduino the ruby_way

arduino.. what now?

Monday, November 5, 12

Page 14: Arduino the ruby_way

what can you do with it?

Monday, November 5, 12

Page 15: Arduino the ruby_way

can’twhat can you do with it?

Monday, November 5, 12

Page 16: Arduino the ruby_way

can’tWhat can you do with it?

Monday, November 5, 12

Page 17: Arduino the ruby_way

can’tWhat can you do with it?

Monday, November 5, 12

Page 18: Arduino the ruby_way

can’tWhat can you do with it?

Monday, November 5, 12

Page 19: Arduino the ruby_way

can’tWhat can you do with it?

Monday, November 5, 12

Page 20: Arduino the ruby_way

can’tWhat can you do with it?

Monday, November 5, 12

Page 21: Arduino the ruby_way

the ide

Monday, November 5, 12

Page 22: Arduino the ruby_way

the ide

Monday, November 5, 12

Page 23: Arduino the ruby_way

the ide

Monday, November 5, 12

Page 24: Arduino the ruby_way

Burn code

to the

arduino

Monday, November 5, 12

Page 25: Arduino the ruby_way

• standalone• isolated• small

Monday, November 5, 12

Page 26: Arduino the ruby_way

developed by Greg Borenstein

Ruby Arduino Development

RAD

Monday, November 5, 12

Page 27: Arduino the ruby_way

Ruby

class Blinky < ArduinoSketch output_pin 13, :as => :led def loop blink led, 100 endend

Monday, November 5, 12

Page 28: Arduino the ruby_way

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 endend

Monday, November 5, 12

Page 29: Arduino the ruby_way

debuggingoutdated

Monday, November 5, 12

Page 30: Arduino the ruby_way

Talk with

the

Arduino

Monday, November 5, 12

Page 31: Arduino the ruby_way

• standalone• isolated• small

Monday, November 5, 12

Page 32: Arduino the ruby_way

• standalone• isolated• small

Monday, November 5, 12

Page 33: Arduino the ruby_way

• standalone• isolated• small

Monday, November 5, 12

Page 34: Arduino the ruby_way

• standalone• isolated• small

Monday, November 5, 12

Page 35: Arduino the ruby_way

• standalone• small

Monday, November 5, 12

Page 36: Arduino the ruby_way

✓standalone• small

Monday, November 5, 12

Page 37: Arduino the ruby_way

✓standalone✓small

Monday, November 5, 12

Page 38: Arduino the ruby_way

isolation is not import

Monday, November 5, 12

Page 39: Arduino the ruby_way

Monday, November 5, 12

Page 40: Arduino the ruby_way

async

Monday, November 5, 12

Page 41: Arduino the ruby_way

ecto/duinoThe 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

Page 42: Arduino the ruby_way

complex logic

and problems

Monday, November 5, 12

Page 43: Arduino the ruby_way

small C++ library

complex logic

and problems

Monday, November 5, 12

Page 44: Arduino the ruby_way

message passing

Monday, November 5, 12

Page 45: Arduino the ruby_way

?Monday, November 5, 12

Page 46: Arduino the ruby_way

dino

introducing!

Monday, November 5, 12

Page 47: Arduino the ruby_way

Goals• fully tested• easy to extend• great documentation• zero startup time• fun

Monday, November 5, 12

Page 48: Arduino the ruby_way

beginning developmentand use what’s there

thank you duino && node.js

Monday, November 5, 12

Page 49: Arduino the ruby_way

Asynchronous in a synchronous world

Monday, November 5, 12

Page 50: Arduino the ruby_way

Event Machine

Monday, November 5, 12

Page 51: Arduino the ruby_way

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 endend

Monday, November 5, 12

Page 52: Arduino the ruby_way

Monday, November 5, 12

Page 53: Arduino the ruby_way

roll our own• developer control• specific to the gem• zero dependencies

Monday, November 5, 12

Page 54: Arduino the ruby_way

How did it turn out?

Monday, November 5, 12

Page 55: Arduino the ruby_way

class Board

Monday, November 5, 12

Page 56: Arduino the ruby_way

==Monday, November 5, 12

Page 57: Arduino the ruby_way

♥Monday, November 5, 12

Page 58: Arduino the ruby_way

class TxRx

Monday, November 5, 12

Page 59: Arduino the ruby_way

Monday, November 5, 12

Page 60: Arduino the ruby_way

finds the arduino

Monday, November 5, 12

Page 61: Arduino the ruby_way

injected into the board

Monday, November 5, 12

Page 62: Arduino the ruby_way

oh the possibilities

Monday, November 5, 12

Page 63: Arduino the ruby_way

don’t panic

Monday, November 5, 12

Page 64: Arduino the ruby_way

module Components

Monday, November 5, 12

Page 65: Arduino the ruby_way

class < BaseComponent

Monday, November 5, 12

Page 66: Arduino the ruby_way

class Led

Monday, November 5, 12

Page 67: Arduino the ruby_way

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

Page 68: Arduino the ruby_way

board = Board.new(Dino::TxRx.new)led = Led.new(pin: 2, board: board) led.onsleep 2led.off

Monday, November 5, 12

Page 69: Arduino the ruby_way

class Button

Monday, November 5, 12

Page 70: Arduino the ruby_way

def initialize(options={}) self.board.add_digital_hardware(self) self.board.start_readend#...def update(data) case data when UP button_up when DOWN button_down endend

Monday, November 5, 12

Page 71: Arduino the ruby_way

Monday, November 5, 12

Page 72: Arduino the ruby_way

down = proc { led.on }up = proc { led.off } button.down(down)button.up(up)

Monday, November 5, 12

Page 73: Arduino the ruby_way

class Sensor

Monday, November 5, 12

Page 74: Arduino the ruby_way

def initialize(options={}) @data_callbacks = [] @board.add_analog_hardware(self) @board.start_readend def update(data) @data_callbacks.each do |callback| callback.call(data) endend

Monday, November 5, 12

Page 75: Arduino the ruby_way

on_data = proc { |data| puts data} sensor .when_data_received(on_data)

Monday, November 5, 12

Page 76: Arduino the ruby_way

class Stepper

Monday, November 5, 12

Page 77: Arduino the ruby_way

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

Page 78: Arduino the ruby_way

1600.times do stepper.step_cc sleep 0.001end

1600.times do stepper.step_cw sleep 0.001end

Monday, November 5, 12

Page 79: Arduino the ruby_way

and many more

Monday, November 5, 12

Page 80: Arduino the ruby_way

and many more

Monday, November 5, 12

Page 81: Arduino the ruby_way

and many more

Monday, November 5, 12

Page 82: Arduino the ruby_way

and many more

Monday, November 5, 12

Page 83: Arduino the ruby_way

and many more

Monday, November 5, 12

Page 84: Arduino the ruby_way

Lets see it in action

Monday, November 5, 12

Page 85: Arduino the ruby_way

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

Page 86: Arduino the ruby_way

Monday, November 5, 12

Page 87: Arduino the ruby_way

initializer

Monday, November 5, 12

Page 88: Arduino the ruby_way

sinatraboard = Board.new(Dino::TxRx.new)cannon = Led.new(pin: 2, board: board)

put ‘/launch‘ docannon.on

end

Monday, November 5, 12

Page 89: Arduino the ruby_way

/austinbv/dino

@austinbv

Thank You!

Monday, November 5, 12


Recommended