Endless fun with Arduino and Eventmachine

  • 4,306 views
Uploaded on

This is the talk I gave

This is the talk I gave

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,306
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
26
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • I am Bodo Tasche and I am working...\n
  • \n
  • In my spare time i have endless...\n
  • That should be known to everyone here, right? „event-processing library for Ruby“\n
  • That‘s where the interesting stuff begins :)\n
  • - 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 „ Wiring“ by Hernando Barragan\n
  • \n
  • \n
  • Different hardware designs, all under creative commons share alike\n
  • I am using the arduino uno board, it‘s the most common board\nInput/output Pins, USB, Reset Button\n
  • this is the spec...that‘s a „32 kb is enough for everyone“ :)\n
  • \n
  • Open Source Editor, the language arduino is using is called processing, \nui gpl / libraries under lgpl .... rite ruby -> processing\n
  • \n
  • 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
  • \n
  • 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
  • lets try to communicate\n
  • This prints hello world to the serial port every second. the arduino editor can show this in the serial monitor\n
  • \n
  • \n
  • \n
  • \n
  • why not build everything inside of the arduino?\nmemory constraints,lazy,faster,cheaper\n
  • \n
  • \n
  • \n
  • \n
  • Buffer the data, store it somewhere...\n
  • You could even use the eventmachine as a proxy between a webbrowser and the arduino\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • This shows the response time of the webservers pointer\n
  • Contiues integration, first attempt with pc, than transformed to use an ethernet shield\ngithub repo for the code :)\n
  • or go more extreme: signal horn :)\n
  • 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
  • \n
  • 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
  • Petroel Heads? Read the turbocharger pressure and other things\n
  • \n
  • \n
  • 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
  • \n
  • 55 Euro, everything you need to start developing....dingfabrik, bausteln\n
  • \n
  • i have tagged a few more things in my delicious account\n
  • \n
  • \n
  • \n

Transcript

  • 1. Hi!
  • 2. Bodo Tasche @bitboxer
  • 3. Endless fun with Arduino and Eventmachine
  • 4. ! !! Eventmachine ! !
  • 5. ?? Arduino ? ?!
  • 6. Source: Wikipedia
  • 7. Two Parts
  • 8. 1. Hardware
  • 9. Arduino Uno
  • 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. 2. So ware
  • 12. http://arduino.cc
  • 13. Christopher Pike, is this you?
  • 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. Have you brought any fruits or vegetables to the mars? Two weeks.
  • 16. const int BAUD_RATE = 9600;void setup() { Serial.begin(BAUD_RATE);}void loop() { Serial.println(“Hello, world!”); delay(1000);}
  • 17. Well, well, Private Joker, I dontbelieve I heard you correctly!
  • 18. http://arduino.cc/en/Tutorial/SwitchCase2
  • 19. void setup() { Serial.begin(9600); for (int thisPin = 2; thisPin < 7; thisPin++) { pinMode(thisPin, OUTPUT); }}
  • 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. Eventmachine + Arduino
  • 22. It‘s all about the volume!
  • 23. Source: Wikipedia
  • 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. Source: Wikipedia
  • 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. Talk to the hand
  • 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. EventMachine::defer
  • 30. Don’t write a deferred operation that will block forever [...] Wemight put in a timer to detect this
  • 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. If you build it...
  • 33. Last.fmhttp://blog.last.fm/2008/08/01/quality-control
  • 34. githubhttp://urbanhonking.com/ideasfordozens/2010/05/19/the_github_stoplight/
  • 35. by-nc-nd by seanb.murphy http://www.flickr.com/photos/greenstorm/2425378283
  • 36. Weather station
  • 37. Infrared Sender/Receiver
  • 38. Improve your„green thumb“
  • 39. CAN-bus
  • 40. Gong-o-bot
  • 41. Gong-o-bot
  • 42. fritzing.org/projects/
  • 43. fritzing.org/shop/starter-kit/
  • 44. Find a hackerspace!
  • 45. delicious.com/bitboxer/arduino
  • 46. Don‘t be evil Source: Wikipedia
  • 47. Be good! Source: Wikipedia
  • 48. ank you!