Circuit Playground Circuit Python
& The Thonny IDE
Jan 12, 2025
STEAM Clown ™ Productions
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Teachers: Before You Present
2
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Licensing & Attribution
My Open Source Philosophy - I have come to realize that I’m really not competing with other teachers. Maybe I have some local competition, �but in reality, if a student is not coming to my class or my school, then I’m not competing with other teachers in any way… If you work more than a �District away, then we really are not competitors. Let's Share... Collaborate... Help each other... I, and you, may have sweat blood and tears developing a lesson plan, a lab, or presentation… There is an ENORMOUS unpaid value there… I get that… I don’t begrudge teachers who are trying to sell their collateral… I’m just saying that is not what I’m going to do. This is my plan… I’m going to share virtually everything I develop. Join Me!!! See More
CC BY-NC-SA 4.0
https://creativecommons.org/licenses/by-nc-sa/4.0/
https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
GNU Public License & EUPL (European Union Public Licence)
Any included or linked Programming Code Is licensed under GNU General Public License v3.0 & and / or licensed under EUPL 1.2 or later
See the Appendix for Additional Licensing & Attribution Information
3
Please maintain this slide with any modifications you make:
This content is licensed as Open Source / Creative Commons: A Specific use license has been provided to Entities & Organizations listed in the Appendix
Much of the content in these slides is a Re-Telling of material provided by many open source and creative commons internet resources. There are so many Awesome sites, that are open source sites for teaching STEAM Curriculum. I have modified them some, to work better for my Mechatronics Engineering class. I have even used AI and ChatGPT, and Other open-source technical sites.
Other Contributors: My teacher friends, with additional content.
Dec 15, 2024
See Sourced Sites In The Appendix
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Sponsorship Page
I would like to thank <Your Company or Organization Here> for their generous support of my classroom and curriculum development. <Your Company or Organization Here> has <Your value proposition, call to action, & related content and message>
How to Provide a Stipend: You can send something to my personal PayPal.Me Account, Venmo Account, or my Patrion Account, even Buy Stuff On My Amazon Classroom Wishlist, donate to my DonorsChoose projects, or contact me at TopClown@STEAMClown.org, if you want to contribute another way.
(If you would like to sponsor this presentation, please contact TopClown@STEAMClown.org )
4
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Resources & Materials Needed
5
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Objective, Overview, & Introduction
CircuitPython is a streamlined version of Python designed specifically for microcontrollers. It simplifies programming by allowing users to write, edit, and run Python code directly on compatible hardware. CircuitPython is optimized for constrained environments like microcontrollers, focusing on quick prototyping, hardware interaction, and ease of us
6
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
What You Will Know...
Prior Knowledge & Certifications
What You Will Know & Be Able To Do
7
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
How You Will Be Measured
8
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Essential Questions
9
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Essential Questions
"Why is CircuitPython a powerful tool for learning how to interact with hardware and sensors?"
"How does using CircuitPython prepare us for future careers in engineering, technology, and innovation?"
10
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
New Words or Concepts...
11
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
New Words or Concepts...
12
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
👉 Open A Python IDE:
13
print("Hisssssssssss")
Try This 👉
Replit - PythonTutor - Shell
Bookmark This 👉
Try This 👉
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Introduction to Circuit Python on �- Circuit Playground Express (aka CPX)�- Circuit Playground Blue (aka CPB)
14
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
CPB is a Programmable Microcontroller
15
Circuit Playground Blue (CPB) is an excellent platform for students for learn electronics and programming.
Unlike other microcontrollers where you have to purchase additional electronic components, CPB has numerous built-in components that you can incorporate into your code from the day 1.
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Some Of The Great Goodies Baked In To Each Circuit Playground Bluefruit:
16
Click
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
17
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Additional Resources
18
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
19
What is CircuitPython?
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
CircuitPython is based on Python
Python is the fastest growing programming language. It's used everywhere. It supports modules and packages which means it's easy to reuse your code for other projects. It has a built in interpreter which means there are no extra steps, like compiling, to get your code to work. And of course, Python is Open Source Software which means it's free for anyone to use, modify or improve upon.
CircuitPython adds hardware (Microcontroller) support to all of these amazing features. If you already have Python knowledge, you can easily apply that to using CircuitPython. If you have no previous experience, it's really simple to get started!
20
How do I connect Hardware Pins?�How do i Blink and LED?�How do I read an UltraSonic Sensor?�How do I turn a Motor or Servo?
Circuit Python has the Libraries and functions to do that.
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
CircuitPython is a programming language designed for programming microcontrollers, which are small, low-cost computers embedded into various devices. It is a variant or subset of the Python programming language adapted to run on microcontrollers and small single-board computers. CircuitPython aims to make it easy for beginners and non-programmers to get started with hardware projects. Here are some key differences between CircuitPython and regular Python:
It's important to note that CircuitPython and regular Python are not mutually exclusive. They serve different purposes, and the choice between them depends on the specific requirements of a project. Regular Python is better suited for general-purpose programming on desktops and servers, while CircuitPython is ideal for programming microcontrollers in embedded systems and electronics projects.
21
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python
22
Download & install
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Plug CPX/CPB to your Computer
23
ProTip: After you plug the USB cable into your CPX/CPB, Never Unplug It!!!!
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Check!
�
24
Reset Button
You may need to press the reset button twice, fast… This should have the Circuit Playground show up as a drive
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Check - Boot_out.txt
25
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Check - Boot_out.txt
26
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Check
27
Can't See CPLAYBOOT or CIRCUITPY
You may need to press the reset button twice, fast… This should have the Circuit Playground show up as a drive
Press Reset Button fast twice
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
CPLAYBTBOOT
28
You may need to press the reset button twice, fast… This should have the Circuit Playground show up as a drive
Reset Button
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Download Circuit Python
29
Click
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Download Circuit Python
30
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Download The Latest Bluefruit .uf2 File
31
Look in Downloads
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Connect CPX/CPB to Your PC/Mac
32
2) Verify that all LEDs are changed to solid green.
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Flash Your CPX
33
3) Wait until your CPX reboots
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Confirm!
34
New CIRCUITPY USB drive
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
CIRCUITPY - WooHooo
35
Reset Button
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
CIRCUITPY Show Up As A Drive
36
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
code.py is the File to Edit Your Python In
37
code.py
What Are We Going To Edit It With? IDE?
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
38
Circuit Python Online IDE
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python Online IDE
39
Bookmark it!
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python Online IDE
40
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python Online IDE
41
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python Online IDE
42
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python Online IDE
43
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Your CPX always runs the Python code file called code.py. Let's open it on your editor.
44
Open "code.py"
Your CPX/CPB always runs the Python code file called code.py - Let's open it in your editor.
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Python Editor
45
Click on code.py
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Python Editor
46
1. Enter your name here
3. See your new output here
2. Click on > (run) button.
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Syntax Error
47
Missing " on the left side
Your IDE will say you have SyntaxError
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Syntax Error
48
Flashes twice every 5 seconds
Flashing green means your code ended without error
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Terminal print("Hi") Error
49
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Your First Circuit Python Code
50
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Blink
# Save on CPX/CPB as code.py
# Blinks the top right RED LED
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.1)
led.value = False
time.sleep(0.1)
51
Click
Paste it into your "code.py" file
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Python Online IDE
52
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Click to "Save & Run"
53
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
54
Is It Blinking?
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Control C�Control D
55
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
STOP & RELOAD
56
To reload code.py and run whatever is in there, do CTRL-D
Most likely, you'll be writing code that runs forever (meaning in infinite loop). To stop your code from running forever, you can do CTRL-C
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
LAB #1 Blink
57
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
58
lib?
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
You Need Some Libraries…
�
59
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
You Don't Need Everything…
Pro Tip: Only load the libraries you are actually using. Why?
Copy the following folders and files from the bundle lib folder to the lib folder on your CIRCUITPY drive:
60
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
61
Thonny?
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Thonny!!!!!!!!!!!!!!!!!!!!
62
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
63
1) Click on the Windows Version
2) Installer with 64-bit � Python 4.1.7
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Setup Thonny To Point To the CPX/CPB and CircuitPython
64
1) Tools → Options
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Setup Thonny To Point To the CPX/CPB and CircuitPython
65
2) Interpreter
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Setup Thonny To Point To the CPX/CPB and CircuitPython
66
3) Select The Circuit Python Interpreter
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Setup Thonny To Point To the CPX/CPB and CircuitPython
67
4) Select The Circuit Python Interpreter
CircuitPython (generic)
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Setup Thonny To Point To the CPX/CPB and CircuitPython
68
5) Select Port - Try To Detect Automatically Probably will work, but if not select the appropriate USB port
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Setup Thonny To Point To the CPX/CPB and CircuitPython
69
6) Leave These All checked
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Edit Your First Circuit Playground Python File
70
1) File → Open or New
2) Select code.py
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Playground CPX/CPB - Blink
Simple Blink program that blinks the top right RED LED
71
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.1)
led.value = False
time.sleep(0.1)
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Circuit Playground CPX/CPB - Blink
Simple Blink program that blinks the top right RED LED
72
#import time
from time import sleep
from adafruit_circuitplayground import cp
print("Hello <Your Name>")
while True:
cp.red_led = True
sleep(0.5)
cp.red_led = False
sleep(0.5)
Alternate Code, using different Library options
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
LAB #2 Blink
73
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Summary
74
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Let's Check Your Understanding
75
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Thank You…
Questions?
76
Jim Burnham (AKA STEAM Clown)
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Reference Slides
77
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Links for Students
78
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Appendix
79
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Education Standards
California 2013 CTE Standards
Next Generation Science Standards (NGSS)
80
80
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Appendix : Primary Sources & Attribution for Material Used
81
Please maintain this slide with any modifications you make
Additional Attribution & Sources:
STEAM Clown™ - License & Attribution Creative Commons License CC-BY-NC-SA 4.0 - Much of this interpretation is primarily the Intellectual Property of Jim Burnham, TopClown, at STEAMClown.org, I may have used other sources, and in that Re-Telling, I have made my best attempt to properly attribute, or reference any of these sources or works. They are probably listed below. I’m a Super Huge proponent of Open Source - Find out more...
Please maintain this slide with any modifications you make:
This content is licensed as Open Source / Creative Commons: A Specific use license has been provided to the Silicon Valley education Foundation & Silicon Valley CTE
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
Image Reference & Sources
82
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions
What To Fix, Add, Or Change
Presentation Planning:
83
© Copyright - STEAM Clown TM
Creative Commons Licenses - BY-NC-SA 4.0
STEAM Clown TM Productions