Saturday Morning BreakfastSerial: Hacking Arduinos in Python (Swift)

Saturday Morning BreakfastSerial: Hacking Arduinos in Python (Swift)

3b085ba94fee217d7656971b0cb4cf00?s=128

PyCon Canada

August 14, 2013
Tweet

Transcript

  1. BREAKFAST SATURDAY MORNING SERIAL by @SwiftAlphaOne

  2. Note: I’m not Ryan Gosling @SwiftAlphaOne

  3. ARDUINO! Let’s talk about

  4. Why are developers cuckoo for arduino?

  5. SIMPLE API

  6. Giraffe Add Tiger Head Tigeraffe Arduino is Open Source

  7. None
  8. EVERYWHERE Now Available

  9. LOTS OF EXAMPLES

  10. GR-R-REAT! Arduino is

  11. 1 2 3 4 USB Serial Port Ground & Power

    Digital Pins Analog Pins ARDUINO 101
  12. HELLO WORLD “ ”

  13. Download the IDE http://arduino.cc/en/main/software

  14. Wire up a LED

  15. Blink 1: Arduino int led = 13; void setup() {

    pinMode(led, OUTPUT); } void loop() { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000); }
  16. Prototyping in C, Hey kids! is totally fun and easy.

    “ ” - The Trix Rabbit
  17. Friends don’t let Friends PROGRAM IN C.

  18. THE INTERNETS? How do I talk to “ ”

  19. #include <Ethernet.h> #include <SPI.h> EthernetClient client; String data = '{"foo":"bar"}';

    void setup() { Ethernet.begin({0x90,0xA2,0xDA,0x00,0x55,0x8D}); } void loop() { if (client.connect("www.someapi.com",80)) { client.println("POST /api/v1/endpoints HTTP/1.1"); client.println("Host: www.someapi.com"); client.println("Content-Type: application/json"); client.print("Content-Length: "); client.println(data.length()); client.println(); client.print(data); client.println(); } }
  20. #include <Ethernet.h> #include <SPI.h> EthernetClient client; String data = '{"foo":"bar"}';

    void setup() { Ethernet.begin({0x90,0xA2,0xDA,0x00,0x55,0x8D}); } void loop() { if (client.connect("www.someapi.com",80)) { client.println("POST /api/v1/endpoints HTTP/1.1"); client.println("Host: www.someapi.com"); client.println("Content-Type: application/json"); client.print("Content-Length: "); client.println(data.length()); client.println(); client.print(data); client.println(); } } LOL
  21. HORSEPOWER Limited .

  22. A BETTER WAY! There must be

  23. Feature Wishlist Language Agnostic Cross Platform Talks to the Internets

    Complex Processing
  24. FIRMATA http://firmata.org Follow your nose!

  25. from pyfirmata import Arduino from time import sleep board =

    Arduino('/dev/cu.usbmodem1411') ledPin = board.board.digital[13] while 1: ledPin.write(1) sleep(1) ledPin.write(0) sleep(1) Blink 2: pyFirmata
  26. Johnny-Five ? Javascript Ruby Python

  27. Cookies for breakfast!? Python ^

  28. BREAKFASTSERIAL http://github.com/theycallmeswift/BreakfastSerial

  29. $ pip install BreakfastSerial

  30. from BreakfastSerial import Arduino, Led board = Arduino() led =

    Led(board, 13) led.blink(1000) Blink 3: BreakfastSerial
  31. None
  32. Feature Wishlist Language Agnostic Cross Platform Talks to the Internets

    Complex Processing
  33.  Language Agnostic  Cross Platform  Talks to the

    Internets  Complex Processing Feature Wishlist
  34. Buttons, LEDs, & Sensors. “ ” Servos & buzzers too.

    Lots of new components, added by devs like you!
  35. SRSLY THO, I ACCEPT PULLS http://github.com/theycallmeswift/BreakfastSerial

  36. M OAR!

  37. ARDUINO.IO No, really. It’s coming. Go sign up. http://arduino.io

  38. THANK YOU @SwiftAlphaOne theycallmeswift.com