arduino development with ruby · `ocascript -e "set volume #{line}"` end end sp.close...

19
Arduino development with Ruby Julius Markūnas

Upload: others

Post on 05-Aug-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Arduino development with Ruby

Julius Markūnas

Page 2: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

What is Arduino

● Hardware

● Software

● Fun

Page 3: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Arduino Hardware

● 8-16 Mhz processor

● 14 digital I/O pins

● 6 analog inputs

● 6 PWM outputs

● 32k flash

● 2k RAM

● Shields

Page 4: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Arduino Shields

● Ethernet Shield

● Wi-Fi Shield

● GSM Shield

● Motor Shield

● Digit Shield

● NFC Shield

● And many more...

Page 5: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Arduino Software

● Arduino IDE

● C like language

Page 6: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Arduino Hello Worldint ledPin = 13; // LED connected to digital pin 13

void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}

void loop(){ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}

Page 7: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Arduino and Ruby

1. RAD

2. SerialPort

3. Firmata

4. Dino

Page 8: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

RAD

● Compiles to C

● Outdated

● Unmaintained

● Ruby 1.8.7

● Does not play well with Linux

Page 9: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

RAD

class MyProject < ArduinoSketch output_pin 13, :as => led def loop blink led, 500 endend

$ rake make:upload

Page 10: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

SerialPort

● Not designed for arduino

● Direct access

● Required USB cable connection

Page 11: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

SerialPortrequire 'serialport'

sp = SerialPort.new('/dev/tty.usb-device', 9600, 8, 1, 0)

loop do line = sp.gets if line puts "New volume: #{line}" `ocascript -e "set volume #{line}"` endend

sp.close

Page 12: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Firmata

● Designed by arduino

● Access to all components

● Low level

● Requires USB cable connection

Page 13: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Firmataarduino = ArduinoFirmata.connectpin_num = 11

loop do 0.upto(255) do |i| arduino.analog_write pin_num, i sleep 0.01 end

255.downto(0) do |i| arduino.analog_write pin_num, i sleep 0.01 endend

Page 14: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Dino

● Most ruby like

● Good for prototyping

● Well maintained, documented

● Requires USB cable connection

Page 15: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Dino

board = Dino::Board.new(Dino::TxRx.new)led = Dino::Components::Led.new(pin: 13, board: board)

[:on, :off].cycle do |switch| led.send(switch) sleep 0.5end

Page 16: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Fun - Github stoplight

http://urbanhonking.com/ideasfordozens/2010/05/19/the_github_stoplight/

Page 17: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Fun - Led coat

http://rgbledcoat.blogspot.com/

Page 19: Arduino development with Ruby · `ocascript -e "set volume #{line}"` end end sp.close Firmata Designed by arduino Access to all components Low level Requires USB cable connection

Fun - Demo

Led Cube