Slide 1

Slide 1 text

Light Up Your Life -- With Python & LEDs! Live Coders Conf 2 2020 Slides: nina.to/lcc-leds (download for links) Code: nina.to/lcc-cpx-code Nina Zakharenko @nnja nnjaio Photo by Sandro Katalina on Unsplash

Slide 2

Slide 2 text

whoami? nnjaio @nnja nnja ✏ nina.to » I've been a software engineer for over a decade. » For the past two years I've focusing on Python at Microsoft as a Cloud Developer Advocate » where my goal is to make azure and vs code easier @nnja - nnjaio - nina.to/lcc-leds

Slide 3

Slide 3 text

Where To Start When You're Just Getting Started » Hardware Options » Programming LEDs » Debugging with print() » Tools » Libraries » Projects @nnja - nnjaio - nina.to/lcc-leds

Slide 4

Slide 4 text

some of my projects

Slide 5

Slide 5 text

Hardware Options » Raspberry Pi Zero W » Small Development Kit w/ wireless and bluetooth connectivity » BBC micro:bit » computing device aimed at learning » Adafruit - m0 and m4 line of devices » & lots more... @nnja - nnjaio - nina.to/lcc-leds

Slide 6

Slide 6 text

@nnja - nnjaio - nina.to/lcc-leds

Slide 7

Slide 7 text

@nnja - nnjaio - nina.to/lcc-leds

Slide 8

Slide 8 text

Adafruit Circuit PlayGround Express Learning Platform - Cost: $25 @nnja - nnjaio - nina.to/lcc-leds

Slide 9

Slide 9 text

Python's Batteries Included Philosophy “The Python source distribution has long 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 @nnja - nnjaio - nina.to/lcc-leds

Slide 10

Slide 10 text

CircuitPlaygroundExpress Tour

Slide 11

Slide 11 text

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 - nnjaio - nina.to/lcc-leds

Slide 12

Slide 12 text

Libraries » Many available » Need to be in the lib folder » Download from: git.io/circuitpythonlib » ! We're interested in adafruit_circuitplayground.express, so we can interact with the board. @nnja - nnjaio - nina.to/lcc-leds

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

RGB LEDs RGB LEDs have one LED of each color - red, green, and blue. By combining the amount and intensity of these colors (255 * 255 * 255) you can produce over 16 million color variations! image source: randomnerdtutorials.com/electronics-basics-how-do-rgb-leds-work/

Slide 15

Slide 15 text

Neopixels in action @nnja - nnjaio - nina.to/lcc-leds

Slide 16

Slide 16 text

# 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

Slide 17

Slide 17 text

@nnja - nnjaio - nina.to/lcc-leds

Slide 18

Slide 18 text

How to program it? » Plug it in with a data + charge USB cable » See a CircuitPython drive? » on Mac OS in /Volumes/CIRCUITPY » Otherwise, install CircuitPython » Next, edit & save the code.py (or main.py) file. Your code runs instantly! ! @nnja - nnjaio - nina.to/lcc-leds

Slide 19

Slide 19 text

@nnja - nnjaio - nina.to/lcc-leds

Slide 20

Slide 20 text

I ! Programming with Visual Studio Code + The Python Extension $ # To open on Mac OS $ code /Volumes/CIRCUITPY/ @nnja - nnjaio - nina.to/lcc-leds

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Investigating with print statements 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 - nnjaio - nina.to/lcc-leds

Slide 23

Slide 23 text

View print statements & errors via the serial console » To see print() statements or errors, you need to receive output from the Circuit Play Ground Express by opening a connection to the serial console. » ! You won't see any output without it. @nnja - nnjaio - nina.to/lcc-leds

Slide 24

Slide 24 text

easy serial console: with mu editor The easiest way to connect to the serial console is the serial button in the my editor toolbar. @nnja - nnjaio - nina.to/lcc-leds

Slide 25

Slide 25 text

@nnja - nnjaio - nina.to/lcc-leds

Slide 26

Slide 26 text

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.board_name 115200 # `115200` is the baud rate. To quit screen, press ctrl+a followed by k. Or, learn how to connect via the terminal in other OSes

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

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.

Slide 29

Slide 29 text

Powering Your Projects [2/2] » lithium polymer (li-poly) batteries » warning: only for advanced users » small, lightweight, energy dense, fragile » needs special care! » cannot be heated, punctured, or bent » ! for kids w/o supervision » requires additional charger

Slide 30

Slide 30 text

Putting it all together » Adafruit demo code: bit.ly/initial_cpe » Initial directory: bit.ly/initial_cpe_dir » Demo covers a majority of the features, prints out sensor readings, etc. » There's even a flag you can set to turn the Circuit Playground Express into a little piano using the capacitive touch pads! @nnja - nnjaio - nina.to/lcc-leds

Slide 31

Slide 31 text

Microsoft Make Code ✨ Coding not required ✨ makecode.adafruit.com incudes built in emulator learn.adafruit.com/circuit-playground-express-con-badge/

Slide 32

Slide 32 text

VS Code Device Simulator Express Extension Allows you to run CircuitPython without the hardware! @nnja - nnjaio - nina.to/lcc-leds

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Next Steps » Buy (or borrow) a device of your choice or use the VS Code simulator extension or MakeCode emulator » Pick your editor (Visual Studio Code, Mu, etc..) » Write your own code » Use a library » Or start with a shared project ... start with Python on hardware in no time! @nnja - nnjaio - nina.to/lcc-leds

Slide 35

Slide 35 text

github.com/nnja/pyearrings

Slide 36

Slide 36 text

Thank You! @nnja nnjaio Python @ Microsoft: nina.to/lcc-msft Code: nina.to/lcc-cpx-code *Additional resources on the next slide

Slide 37

Slide 37 text

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 Devices @nnja - nnjaio - nina.to/lcc-leds