Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Hi!
Bodo Tasche  @bitboxer
Endless fun with Arduino and        Eventmachine
!              !!        Eventmachine                       !    !
??        Arduino    ?                 ?!
Source: Wikipedia
Two Parts
1. Hardware
Arduino Uno
Microcontroller               ATmega328Operating Voltage                5VInput Voltage (recommended)     7-12VInput Volta...
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); ...
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...
Well, well, Private Joker, I dontbelieve 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...
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, ...
Source: Wikipedia
require serialportsp = SerialPort.new(/dev/tty.your-usb-device, 9600, 8, 1, 0)loop do  line = sp.gets  if line    puts "Ne...
Talk to the hand
require rubygemsrequire serialportrequire eventmachine$sp = SerialPort.new(/dev/tty.your-usb-device, 9600, 8, 1, 0)class D...
EventMachine::defer
Don’t write a deferred operation that will block forever [...] Wemight put in a timer to detect this
$eventmachine_library = :pure_ruby # need to force pure rubyrequire eventmachinegem_original_require serialportrequire sms...
If you build it...
Last.fmhttp://blog.last.fm/2008/08/01/quality-control
githubhttp://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
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
Endless fun with Arduino and Eventmachine
Endless fun with Arduino and Eventmachine
Endless fun with Arduino and Eventmachine
Endless fun with Arduino and Eventmachine
Upcoming SlideShare
Loading in …5
×

Endless fun with Arduino and Eventmachine

4,903 views

Published on

This is the talk I gave

Published in: Technology, Business
  • Be the first to comment

Endless fun with Arduino and Eventmachine

  1. 1. Hi!
  2. 2. Bodo Tasche @bitboxer
  3. 3. Endless fun with Arduino and Eventmachine
  4. 4. ! !! Eventmachine ! !
  5. 5. ?? Arduino ? ?!
  6. 6. Source: Wikipedia
  7. 7. Two Parts
  8. 8. 1. Hardware
  9. 9. Arduino Uno
  10. 10. Microcontroller ATmega328Operating Voltage 5VInput Voltage (recommended) 7-12VInput Voltage (limits) 6-20VDigital I/O Pins 14Analog Input Pins 6DC Current per I/O Pin 40 mADC Current for 3.3V Pin 50 mAFlash Memory 32 KBSRAM 2 KBEEPROM 1 KBClock Speed 16 MHz
  11. 11. 2. So ware
  12. 12. http://arduino.cc
  13. 13. Christopher Pike, is this you?
  14. 14. 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);}
  15. 15. Have you brought any fruits or vegetables to the mars? Two weeks.
  16. 16. const int BAUD_RATE = 9600;void setup() { Serial.begin(BAUD_RATE);}void loop() { Serial.println(“Hello, world!”); delay(1000);}
  17. 17. Well, well, Private Joker, I dontbelieve I heard you correctly!
  18. 18. http://arduino.cc/en/Tutorial/SwitchCase2
  19. 19. void setup() { Serial.begin(9600); for (int thisPin = 2; thisPin < 7; thisPin++) { pinMode(thisPin, OUTPUT); }}
  20. 20. 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); } } }}
  21. 21. Eventmachine + Arduino
  22. 22. It‘s all about the volume!
  23. 23. Source: Wikipedia
  24. 24. 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); }}
  25. 25. Source: Wikipedia
  26. 26. require serialportsp = 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}"` endendsp.close
  27. 27. Talk to the hand
  28. 28. require rubygemsrequire serialportrequire 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 endendEventMachine::run do EventMachine::start_server "127.0.0.1", 8081, DataBufferendsp.close
  29. 29. EventMachine::defer
  30. 30. Don’t write a deferred operation that will block forever [...] Wemight put in a timer to detect this
  31. 31. $eventmachine_library = :pure_ruby # need to force pure rubyrequire eventmachinegem_original_require serialportrequire smsrelay/gsmpdumodule 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
  32. 32. If you build it...
  33. 33. Last.fmhttp://blog.last.fm/2008/08/01/quality-control
  34. 34. githubhttp://urbanhonking.com/ideasfordozens/2010/05/19/the_github_stoplight/
  35. 35. by-nc-nd by seanb.murphy http://www.flickr.com/photos/greenstorm/2425378283
  36. 36. Weather station
  37. 37. Infrared Sender/Receiver
  38. 38. Improve your„green thumb“
  39. 39. CAN-bus
  40. 40. Gong-o-bot
  41. 41. Gong-o-bot
  42. 42. fritzing.org/projects/
  43. 43. fritzing.org/shop/starter-kit/
  44. 44. Find a hackerspace!
  45. 45. delicious.com/bitboxer/arduino
  46. 46. Don‘t be evil Source: Wikipedia
  47. 47. Be good! Source: Wikipedia
  48. 48. ank you!

×