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

preso.pdf

Nina Zakharenko
May 05, 2019
2.1k

 preso.pdf

Nina Zakharenko

May 05, 2019
Tweet

Transcript

  1. Slides: bit.ly/pythonhardware
    Nina Zakharenko
    @nnja
    Light Up Your Life --
    With Python & LEDs!
    @nnja

    View Slide

  2. #PyCon2019
    @nnja
    Livetweet
    @nnja

    View Slide

  3. Software doesn't have to be serious
    @nnja

    View Slide

  4. (Hardware doesn't have to be serious either)
    @nnja

    View Slide

  5. View Slide

  6. ➜ whoami?
    » long time software engineer
    » newly minted hardware enthusiast
    Python at Microsoft: aka.ms/pycon2019
    @nnja

    View Slide

  7. Python
    on hardware?
    Photo by David Clode on Unsplash
    @nnja

    View Slide

  8. Look in your swag bag
    !"#
    @nnja

    View Slide

  9. a few other devices that run python

    View Slide

  10. HalloWing m0 - (a spooky development kit)
    @nnja

    View Slide

  11. MicroPython &
    CircuitPython
    » MicroPython is a variant of
    Python 3 designed to run of
    microcontrollers.
    » Runs within just 256k of
    code space and 16k of RAM.
    » CircuitPython is an education
    friendly Adafruit fork of
    MicroPython
    » Both are open source!
    @nnja

    View Slide

  12. Adafruit Circuit
    PlayGround
    Express
    Learning Platform -
    Cost: $25->
    @nnja

    View Slide

  13. Python's Batteries Included Philosophy
    “The Python distribution has maintained the
    philosophy of "batteries included" -- having
    a rich and versatile standard library which
    is immediately available, without making the
    user download separate packages.
    This gives the Python language a head start
    in many projects.”
    PEP 206

    View Slide

  14. Circuit
    Playground
    Express Tour
    @nnja

    View Slide

  15. How do we
    Light up
    RGB LEDs?
    @nnja

    View Slide

  16. RGB LEDs
    RGB LEDs have one LED of each
    color - red, green, and blue.
    By combining the amount and
    intensity of these three
    colors (255 * 255 * 255) you
    can produce over 16 million
    color variations!
    image: randomnerdtutorials.com

    View Slide

  17. @nnja

    View Slide

  18. @nnja

    View Slide

  19. @nnja

    View Slide

  20. @nnja

    View Slide

  21. @nnja

    View Slide

  22. How do we program it?
    » Plug it in with a data + charge USB cable
    » See a CircuitPython drive?
    » on Mac OS in /Volumes/CIRCUITPY
    » Otherwise, install CircuitPython
    » Create or edit a code.py (or main.py) file in the
    root directory.
    »
    !
    Your code reloads & runs instantly!
    @nnja

    View Slide

  23. from adafruit_circuitplayground.express import cpx
    RED = (255, 0, 0)
    cpx.pixels.brightness = 0.1
    while True: # Keep looping forever..
    cpx.pixels.fill(RED)
    @nnja

    View Slide

  24. from adafruit_circuitplayground.express import cpx
    cpx.button_a # Button A Pressed? True or False
    cpx.button_b # Button B Pressed? True or False
    learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/

    View Slide

  25. from adafruit_circuitplayground.express import cpx
    RED = (255, 0, 0)
    BLUE = (0, 0, 255)
    cpx.pixels.brightness = 0.1
    while True: # Keep looping forever...
    if cpx.button_a:
    cpx.pixels.fill(RED)
    elif cpx.button_b:
    cpx.pixels.fill(BLUE)
    else:
    cpx.pixels.fill(0)
    @nnja

    View Slide

  26. # Cycle between Red, Green, Blue each time a button is pressed
    from adafruit_circuitplayground.express import cpx
    import time
    RED = (255, 0, 0) # 255 Red, 0 Green, 0 Blue
    GREEN = (0, 255, 0) # 0 Red, 255 Green, 0 Blue
    BLUE = (0, 0, 255) # 0 Red, 0 Green, 255 Blue
    cpx.pixels.brightness = 0.1
    my_colors = [RED, GREEN, BLUE]
    color_pos = 0
    while True: # Keep looping forever...
    cpx.pixels.fill(my_colors[color_pos])
    if cpx.button_a or cpx.button_b: # Button A or B was pressed
    color_pos = (color_pos + 1) % len(my_colors)
    time.sleep(0.2) # Sleep, to make the button less sensitive

    View Slide

  27. @nnja

    View Slide

  28. I
    !
    Programming
    with Visual Studio
    Code
    + The Python
    Extension
    $ # To open on Mac OS
    $ code /Volumes/CIRCUITPY/
    Note: Visual Studio Code and the Python extension is made by Microsoft
    @nnja

    View Slide

  29. Programming with Mu Editor:
    a simple Python editor for beginner programmers

    View Slide

  30. Investigating with print()
    my_colors = [("Red", RED), ("Green", GREEN), ("Blue", BLUE)]
    color_pos = 0
    while True: # Keep looping forever...
    name, color = my_colors[color_pos]
    cpx.pixels.fill(color)
    if cpx.button_a or cpx.button_b: # Button A or B was pressed
    color_pos = (color_pos + 1) % len(my_colors)
    next_name, _ = my_colors[color_pos]
    print("Changing color from %s to %s" % (name, next_name))
    time.sleep(0.2) # Sleep, to make the button less sensitive
    @nnja

    View Slide

  31. View print outs & errors
    via the serial console
    » To see print()s or errors, you need to receive
    output from the Circuit Playground Express by
    opening a connection to the serial console.
    »
    !
    You won't see any output without it.
    @nnja

    View Slide

  32. easy serial console:
    with mu editor
    The easiest way to connect to the serial console is
    the serial button in the mu editor toolbar.
    @nnja

    View Slide

  33. advanced serial console:
    the terminal
    On Mac OS, can use the terminal and screen program to
    connect to the serial console on the Circuit
    Playground Express.
    $ ls /dev/tty.* # Select the usbmodem
    $ screen /dev/tty.usbmodem141401 # yours will be different!
    To quit screen, press ctrl+a followed by k
    @nnja

    View Slide

  34. View Slide

  35. Powering Your
    Projects [1/2]
    » micro USB (same port for
    power & programming)
    » from a computer, portable
    phone charger, or wall
    » battery packs (JST connector)
    » need minimum 3.5V DC.
    Power with 3 household AAA
    batteries + enclosure with
    correct connector.

    View Slide

  36. Powering Your Projects [2/2]
    » lithium polymer (li-poly)
    batteries
    » warning: only for advanced
    users
    » small, lightweight, energy
    dense, fragile
    » needs special care!
    » don't heat, puncture, or
    bend
    »
    !
    for kids w/o supervision
    » requires special charging

    View Slide

  37. Putting it all together
    » Adafruit demo code: bit.ly/initial_cpe
    » Demo covers majority of features, prints sensor
    readings, etc.
    » Flag you can set to turn the Circuit Playground
    Express into a piano
    !
    using capacitive touch
    pads!

    @nnja

    View Slide

  38. Microsoft Make Code
    »

    Coding not required

    »

    Hardware not required

    » (incudes built in
    emulator)
    makecode.adafruit.com
    @nnja

    View Slide

  39. 90% of students said
    the micro:bit showed
    them that anyone can
    code.
    microbit.org/en/2017-07-07-bbc-stats/

    View Slide

  40. 86% of students said
    the micro:bit made
    Computer Science
    more interesting.
    microbit.org/en/2017-07-07-bbc-stats/

    View Slide

  41. microbit.org/en/2017-07-07-bbc-stats/

    View Slide

  42. Let's make new
    clubhouses
    Leah Buechley and Benjamin Mako Hill - LilyPad in the Wild

    View Slide

  43. Find projects
    · Adafruit Guides
    · Microsoft Make Code
    · Instructables
    ← solder-free Circuit
    PlayGround Express Jack-o-
    Lantern
    learn.adafruit.com/circuit-playground-jack-o-lantern

    View Slide

  44. Anybody can learn!
    Start with an Hour of Code. http:/
    /code.org
    © Code.org. Code.org®, the CODE logo and Hour of Code™ are trademarks of Code.org
    “You can be a
    creator and an artist,
    not just a consumer.”
    Madison Maxey,
    founder of
    Loomia,
    a smart-fabric
    technology
    company
    madisonmaxey.com

    View Slide

  45. @the_gella
    Maker: Angela Sheehan - gellacraft.com

    View Slide

  46. @nnja

    View Slide

  47. github.com/nnja/pyearrings

    View Slide

  48. Our inventions
    mirror our
    secret wishes.
    -- Lawrence Durrell
    Photo by Pepe Reyes on Unsplash

    View Slide

  49. start something new...
    @nnja

    View Slide

  50. ... (almost new)
    !
    @nnja

    View Slide

  51. Share your projects:
    #PythonHardware
    @nnja

    View Slide

  52. CircuitPython at PyCon?
    Today: Open space
    room 22 @ 5pm
    Tomorrow:
    CircuitPython Sprints
    @ 9am
    @nnja

    View Slide

  53. ! "
    bit.ly/python-class
    @nnja

    View Slide

  54. Thank You!
    @nnja
    Slides: bit.ly/pythonhardware
    *Additional resources on the next slide

    View Slide

  55. Resources
    » Circuit PlayGround Express Library -
    learn.adafruit.com/circuitpython-made-easy-on-
    circuit-playground-express/
    » Circuit Python Essentials -
    cdn-learn.adafruit.com/downloads/pdf/circuitpython-
    essentials.pdf
    » AdaFruit Python Compatible m0
    www.adafruit.com/?q=m0 and m4 www.adafruit.com/?q=m4
    @nnja

    View Slide