Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Saturday Morning BreakfastSerial: Hacking Arduinos in Python (Swift)

Saturday Morning BreakfastSerial: Hacking Arduinos in Python (Swift)

PyCon Canada

August 14, 2013
Tweet

More Decks by PyCon Canada

Other Decks in Education

Transcript

  1. BREAKFAST
    SATURDAY MORNING SERIAL
    by @SwiftAlphaOne

    View full-size slide

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

    View full-size slide

  3. ARDUINO!
    Let’s talk about

    View full-size slide

  4. Why are developers
    cuckoo for arduino?

    View full-size slide

  5. Giraffe Add Tiger Head Tigeraffe
    Arduino is Open Source

    View full-size slide

  6. EVERYWHERE
    Now Available

    View full-size slide

  7. LOTS OF EXAMPLES

    View full-size slide

  8. GR-R-REAT!
    Arduino is

    View full-size slide

  9. 1
    2
    3
    4
    USB Serial Port
    Ground & Power
    Digital Pins
    Analog Pins
    ARDUINO 101

    View full-size slide

  10. HELLO WORLD
    “ ”

    View full-size slide

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

    View full-size slide

  12. Wire up a LED

    View full-size slide

  13. Blink 1: Arduino
    int led = 13;
    void setup() {
    pinMode(led, OUTPUT);
    }
    void loop() {
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
    }

    View full-size slide

  14. Prototyping in C,
    Hey kids!
    is totally fun and easy.


    - The Trix Rabbit

    View full-size slide

  15. Friends don’t let Friends
    PROGRAM IN C.

    View full-size slide

  16. THE INTERNETS?
    How do I talk to


    View full-size slide

  17. #include
    #include
    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();
    }
    }

    View full-size slide

  18. #include
    #include
    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

    View full-size slide

  19. HORSEPOWER
    Limited
    .

    View full-size slide

  20. A BETTER WAY!
    There must be

    View full-size slide

  21. Feature Wishlist
    Language Agnostic
    Cross Platform
    Talks to the Internets
    Complex Processing

    View full-size slide

  22. FIRMATA
    http://firmata.org
    Follow your
    nose!

    View full-size slide

  23. 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

    View full-size slide

  24. Johnny-Five
    ?
    Javascript Ruby Python

    View full-size slide

  25. Cookies for breakfast!?
    Python
    ^

    View full-size slide

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

    View full-size slide

  27. $ pip install BreakfastSerial

    View full-size slide

  28. from BreakfastSerial import Arduino, Led
    board = Arduino()
    led = Led(board, 13)
    led.blink(1000)
    Blink 3: BreakfastSerial

    View full-size slide

  29. Feature Wishlist
    Language Agnostic
    Cross Platform
    Talks to the Internets
    Complex Processing

    View full-size slide

  30. Language Agnostic
    Cross Platform
    Talks to the Internets
    Complex Processing
    Feature Wishlist

    View full-size slide

  31. Buttons, LEDs, & Sensors.


    Servos & buzzers too.
    Lots of new components,
    added by devs like you!

    View full-size slide

  32. SRSLY THO, I ACCEPT PULLS
    http://github.com/theycallmeswift/BreakfastSerial

    View full-size slide

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

    View full-size slide

  34. THANK YOU
    @SwiftAlphaOne
    theycallmeswift.com

    View full-size slide