Hi!
Bodo Tasche
  @bitboxer
Endless fun with Arduino and
        Eventmachine
!              !
!
        Eventmachine
                       !
    !
?
?
        Arduino


    ?                 ?!
Source: Wikipedia
Two Parts
1. Hardware
Arduino Uno
Microcontroller               ATmega328

Operating Voltage                5V

Input Voltage (recommended)     7-12V

Input Voltage (limits)          6-20V

Digital I/O Pins                 14

Analog Input Pins                 6

DC Current per I/O Pin          40 mA

DC Current for 3.3V Pin         50 mA

Flash Memory                    32 KB

SRAM                            2 KB

EEPROM                          1 KB

Clock Speed                    16 MHz
2. So ware
http://arduino.cc
Christopher Pike, is
     this you?
const int PIN_LED = 13;

void setup() {
  pinMode(PIN_LED, OUTPUT);
}

void loop() {
  digitalWrite(PIN_LED, HIGH);
  delay(500);
  digitalWrite(PIN_LED, LOW);
  delay(500);
}
Have you brought any fruits or
   vegetables to the mars?

         Two weeks.
const int BAUD_RATE = 9600;

void setup() {
  Serial.begin(BAUD_RATE);
}

void loop() {
  Serial.println(“Hello, world!”);
  delay(1000);
}
Well, well, Private Joker, I don't
believe I heard you correctly!
http://arduino.cc/en/Tutorial/SwitchCase2
void setup() {
  Serial.begin(9600);
  for (int thisPin = 2; thisPin < 7; thisPin++) {
     pinMode(thisPin, OUTPUT);
  }
}
void loop() {
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    switch (inByte) {
    case 'a': digitalWrite(2, HIGH);
              break;
    case 'b': digitalWrite(3, HIGH);
              break;
    case 'c': digitalWrite(4, HIGH);
              break;
    case 'd': digitalWrite(5, HIGH);
              break;
    case 'e': digitalWrite(6, HIGH);
              break;
    default:
      for (int thisPin = 2; thisPin < 7; thisPin++) {
        digitalWrite(thisPin, LOW);
      }
    }
  }
}
Eventmachine
     +
  Arduino
It‘s all about the volume!
Source: Wikipedia
const int POT_PIN = 2;

int val;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int newVal = map(analogRead(POT_PIN), 0, 1023, 7, 0);

    if (val != newVal) {
      val = newVal;
      Serial.println(val);
    }

}
Source: Wikipedia
require 'serialport'

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

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

sp.close
Talk to the hand
require 'rubygems'
require 'serialport'
require 'eventmachine'

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

class DataBuffer < EM::Protocols::LineAndTextProtocol

  def initialize
    puts "hello stranger..."
  end

  def receive_data(data)
    EventMachine::defer do
      $sp.puts data.strip
      send_data($sp.gets)
    end
  end

end

EventMachine::run do
  EventMachine::start_server "127.0.0.1", 8081, DataBuffer
end

sp.close
EventMachine::defer
Don’t write a deferred operation
 that will block forever [...] We
might put in a timer to detect this
$eventmachine_library = :pure_ruby # need to force pure ruby
require 'eventmachine'
gem_original_require 'serialport'
require 'smsrelay/gsmpdu'

module EventMachine
  class EvmaSerialPort < StreamObject
    def self.open(dev, baud, databits, stopbits, parity)                        class << self
      io = SerialPort.new(dev, baud, databits, stopbits, parity)                  def connect_serial(dev, baud, databits, stopbits, parity)
      return(EvmaSerialPort.new(io))                                                EvmaSerialPort.open(dev, baud, databits, stopbits, parity).uuid
    end                                                                           end
                                                                                end
    def initialize(io)
      super                                                                     def EventMachine::open_serial(dev, baud, databits, stopbits, parity,
    end                                                                                                       handler=nil)
                                                                                  klass = if (handler and handler.is_a?(Class))
    ##                                                                                  handler
    # Monkeypatched version of EventMachine::StreamObject#eventable_read so           else
    # that EOFErrors from the SerialPort object (which the ruby-serialport              Class.new( Connection ) {handler and include handler}
    # library uses to signal the fact that there is no more data available            end
    # for reading) do not cause the connection to unbind.                         s = connect_serial(dev, baud, databits, stopbits, parity)
    def eventable_read                                                            c = klass.new s
       @last_activity = Reactor.instance.current_loop_time                        @conns[s] = c
       begin                                                                      block_given? and yield c
         if io.respond_to?(:read_nonblock)                                        c
           10.times {                                                           end
             data = io.read_nonblock(4096)
              EventMachine::event_callback uuid, ConnectionData, data           class Connection
           }                                                                      # This seems to be necessary with EventMachine 0.12.x
         else                                                                     def associate_callback_target(sig)
           data = io.sysread(4096)                                                  return(nil)
           EventMachine::event_callback uuid, ConnectionData, data                end
         end                                                                    end
       rescue Errno::EAGAIN, Errno::EWOULDBLOCK, EOFError                     end
         # no-op
       rescue Errno::ECONNRESET, Errno::ECONNREFUSED
         @close_scheduled = true
         EventMachine::event_callback uuid, ConnectionUnbound, nil
       end
    end
  end




          https://github.com/eventmachine/eventmachine/wiki/Code-Snippets
If you build it...
Last.fm




http://blog.last.fm/2008/08/01/quality-control
github




http://urbanhonking.com/ideasfordozens/2010/05/19/the_github_stoplight/
by-nc-nd by seanb.murphy http://www.flickr.com/photos/greenstorm/2425378283
Weather station
Infrared Sender/Receiver
Improve your
„green thumb“
CAN-bus

Connect your Arduino with your car
Gong-o-bot
Gong-o-bot
fritzing.org/projects/
fritzing.org/shop/starter-kit/
Find a hackerspace!
delicious.com/bitboxer/arduino
Don‘t be evil




                Source: Wikipedia
Be good!




           Source: Wikipedia
ank you!

Endless fun with Arduino and Eventmachine

  • 1.
  • 2.
    Bodo Tasche @bitboxer
  • 4.
    Endless fun withArduino and Eventmachine
  • 5.
    ! ! ! Eventmachine ! !
  • 6.
    ? ? Arduino ? ?!
  • 7.
  • 8.
  • 9.
  • 11.
  • 12.
    Microcontroller ATmega328 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 14 Analog Input Pins 6 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA Flash Memory 32 KB SRAM 2 KB EEPROM 1 KB Clock Speed 16 MHz
  • 13.
  • 15.
  • 16.
  • 18.
    const int PIN_LED= 13; void setup() { pinMode(PIN_LED, OUTPUT); } void loop() { digitalWrite(PIN_LED, HIGH); delay(500); digitalWrite(PIN_LED, LOW); delay(500); }
  • 19.
    Have you broughtany fruits or vegetables to the mars? Two weeks.
  • 20.
    const int BAUD_RATE= 9600; void setup() { Serial.begin(BAUD_RATE); } void loop() { Serial.println(“Hello, world!”); delay(1000); }
  • 21.
    Well, well, PrivateJoker, I don't believe I heard you correctly!
  • 22.
  • 23.
    void setup() { Serial.begin(9600); for (int thisPin = 2; thisPin < 7; thisPin++) { pinMode(thisPin, OUTPUT); } }
  • 24.
    void loop() { if (Serial.available() > 0) { int inByte = Serial.read(); switch (inByte) { case 'a': digitalWrite(2, HIGH); break; case 'b': digitalWrite(3, HIGH); break; case 'c': digitalWrite(4, HIGH); break; case 'd': digitalWrite(5, HIGH); break; case 'e': digitalWrite(6, HIGH); break; default: for (int thisPin = 2; thisPin < 7; thisPin++) { digitalWrite(thisPin, LOW); } } } }
  • 25.
    Eventmachine + Arduino
  • 26.
    It‘s all aboutthe volume!
  • 27.
  • 28.
    const int POT_PIN= 2; int val; void setup() { Serial.begin(9600); } void loop() { int newVal = map(analogRead(POT_PIN), 0, 1023, 7, 0); if (val != newVal) { val = newVal; Serial.println(val); } }
  • 29.
  • 30.
    require 'serialport' sp =SerialPort.new('/dev/tty.your-usb-device', 9600, 8, 1, 0) loop do line = sp.gets if line puts "New volume : #{line}" `osascript -e "set volume #{line}"` end end sp.close
  • 31.
  • 32.
    require 'rubygems' require 'serialport' require'eventmachine' $sp = SerialPort.new('/dev/tty.your-usb-device', 9600, 8, 1, 0) class DataBuffer < EM::Protocols::LineAndTextProtocol def initialize puts "hello stranger..." end def receive_data(data) EventMachine::defer do $sp.puts data.strip send_data($sp.gets) end end end EventMachine::run do EventMachine::start_server "127.0.0.1", 8081, DataBuffer end sp.close
  • 33.
  • 34.
    Don’t write adeferred operation that will block forever [...] We might put in a timer to detect this
  • 35.
    $eventmachine_library = :pure_ruby# need to force pure ruby require 'eventmachine' gem_original_require 'serialport' require 'smsrelay/gsmpdu' module EventMachine class EvmaSerialPort < StreamObject def self.open(dev, baud, databits, stopbits, parity) class << self io = SerialPort.new(dev, baud, databits, stopbits, parity) def connect_serial(dev, baud, databits, stopbits, parity) return(EvmaSerialPort.new(io)) EvmaSerialPort.open(dev, baud, databits, stopbits, parity).uuid end end end def initialize(io) super def EventMachine::open_serial(dev, baud, databits, stopbits, parity, end handler=nil) klass = if (handler and handler.is_a?(Class)) ## handler # Monkeypatched version of EventMachine::StreamObject#eventable_read so else # that EOFErrors from the SerialPort object (which the ruby-serialport Class.new( Connection ) {handler and include handler} # library uses to signal the fact that there is no more data available end # for reading) do not cause the connection to unbind. s = connect_serial(dev, baud, databits, stopbits, parity) def eventable_read c = klass.new s @last_activity = Reactor.instance.current_loop_time @conns[s] = c begin block_given? and yield c if io.respond_to?(:read_nonblock) c 10.times { end data = io.read_nonblock(4096) EventMachine::event_callback uuid, ConnectionData, data class Connection } # This seems to be necessary with EventMachine 0.12.x else def associate_callback_target(sig) data = io.sysread(4096) return(nil) EventMachine::event_callback uuid, ConnectionData, data end end end rescue Errno::EAGAIN, Errno::EWOULDBLOCK, EOFError end # no-op rescue Errno::ECONNRESET, Errno::ECONNREFUSED @close_scheduled = true EventMachine::event_callback uuid, ConnectionUnbound, nil end end end https://github.com/eventmachine/eventmachine/wiki/Code-Snippets
  • 36.
  • 37.
  • 38.
  • 39.
    by-nc-nd by seanb.murphyhttp://www.flickr.com/photos/greenstorm/2425378283
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
    Don‘t be evil Source: Wikipedia
  • 52.
    Be good! Source: Wikipedia
  • 53.

Editor's Notes

  • #2 \n
  • #3 I am Bodo Tasche and I am working...\n
  • #4 \n
  • #5 In my spare time i have endless...\n
  • #6 That should be known to everyone here, right? &amp;#x201E;event-processing library for Ruby&amp;#x201C;\n
  • #7 That&amp;#x2018;s where the interesting stuff begins :)\n
  • #8 - open-source electronics prototyping platform\n-Project began 2005 in Italy to create a device for controlling student-built interaction design projects\n- Fork of &amp;#x201E; Wiring&amp;#x201C; by Hernando Barragan\n
  • #9 \n
  • #10 \n
  • #11 Different hardware designs, all under creative commons share alike\n
  • #12 I am using the arduino uno board, it&amp;#x2018;s the most common board\nInput/output Pins, USB, Reset Button\n
  • #13 this is the spec...that&amp;#x2018;s a &amp;#x201E;32 kb is enough for everyone&amp;#x201C; :)\n
  • #14 \n
  • #15 Open Source Editor, the language arduino is using is called processing, \nui gpl / libraries under lgpl .... rite ruby -&gt; processing\n
  • #16 \n
  • #17 Okay, now lets dive into a few examples. The hello world in the \nhardware world usually is a blinking led. That always reminds \nme on that guy in the black wheel chair thing from star trek...beep\n
  • #18 \n
  • #19 setup - init the environment of the arduino - input/output pins\nloop - the event loop\nwrite this into the editor, compile it and upload it to the arduino that is attached by usb\n
  • #20 lets try to communicate\n
  • #21 This prints hello world to the serial port every second. the arduino editor can show this in the serial monitor\n
  • #22 \n
  • #23 \n
  • #24 \n
  • #25 \n
  • #26 why not build everything inside of the arduino?\nmemory constraints,lazy,faster,cheaper\n
  • #27 \n
  • #28 \n
  • #29 \n
  • #30 \n
  • #31 Buffer the data, store it somewhere...\n
  • #32 You could even use the eventmachine as a proxy between a webbrowser and the arduino\n
  • #33 \n
  • #34 \n
  • #35 \n
  • #36 \n
  • #37 \n
  • #38 This shows the response time of the webservers pointer\n
  • #39 Contiues integration, first attempt with pc, than transformed to use an ethernet shield\ngithub repo for the code :)\n
  • #40 or go more extreme: signal horn :)\n
  • #41 you could build a simple weather station with this\narduino as data collection utility for temperature, pressure, moisture...\ncombine it with the data from the web and calculate your own weather\n
  • #42 \n
  • #43 put moisture sensors into the soil of your plants and when the\nmoisture drops a certain limit, let it send you a mail or even better:\npump water into the pot\n
  • #44 Petroel Heads? Read the turbocharger pressure and other things\n
  • #45 \n
  • #46 \n
  • #47 Fritzing is a software to document the designs you are creating \nyou can find tons of projects, schematics and sources on fritzing.org.\nyou can use that as inspiration and mix those ideas and create something new\n\n
  • #48 \n
  • #49 55 Euro, everything you need to start developing....dingfabrik, bausteln\n
  • #50 \n
  • #51 i have tagged a few more things in my delicious account\n
  • #52 \n
  • #53 \n
  • #54 \n