SlideShare a Scribd company logo
高師大跨領域藝術研究所
Coding with
CircuitPython@CPB
主講者:曾令燊
大綱
準備材料
佈線圖
CircuitPython簡介、安裝、實作
Q & A
2
準備材料
 Adafruit Circuit Playground Bluefruit Microcontroller Board
 Adafruit SGP30 Air Quality Sensor Breakout-VOC、eCO2
 PLANTOWER PMSA003 Laser PM2.5 Air Quality Sensor (含G7專用轉接板與連接
線--8pin 1.25mm 轉 2.54mm)
 Lithium Ion Polymer Battery - 3.7V 2000mAh(JST connector) or MB102
Breadboard Power Supply Module 3.3V/5V
 Breadboard
 Dupont Line
 Alligator-clip
 USB cable
3
佈線圖4
CircuitPython簡介
 CircuitPython is a programming language designed to simplify experimenting
and learning to program on low-cost microcontroller boards.
 CircuitPython is based on Python
 Advantage:
 Running quickly
 Easily update your code
 Serial console and REPL
5
CircuitPython安裝
 Follow the step from https://learn.adafruit.com/adafruit-circuit-playground-
bluefruit/circuitpython
 Download the latest UF2 file -- CircuitPython 6.0.0-beta.2
 Double-click the small RESET button in the middle of the CPB
 Drag the adafruit_circuitpython_xxx-6.0.0-xxx.uf2 file to CPLAYBTBOOT
 Download the latest library bundle file -- Bundle Version 6.x
 Copy the following folders and files from the bundle lib folder to the lib folder on
your CIRCUITPY drive
6
Installing Mu Editor
 Download Mu from https://codewith.mu
 Click [Download] -- Windows 64-bit
 Using Mu
7
CircuitPython實作
 Blinking the D13 LED -- https://learn.adafruit.com/adafruit-circuit-playground-
bluefruit/creating-and-editing-code
 Copy Code
 Paste the code into Mu editor
 Save as code.py on your CIRCUITPY drive
 Connecting to the Serial Console – print("Hello, world!")
 The REPL
 Press any key to enter the REPL
 Use Ctrl+D to reload
 Press Ctrl+C to interrupt
 CircuitPython Playground: https://learn.adafruit.com/adafruit-circuit-playground-
bluefruit/circuitpython-playground
8
CircuitPython Essentials
 https://learn.adafruit.com/circuitpython-essentials/circuitpython-essentials
 工欲善其事,必先利其器…一步一腳印…
9
10
CircuitPython(SGP30+PMSA003+Audio)
實作-1
""" Example for using the SGP30 and PM25 with CircuitPython
and the Adafruit library """
import digitalio
import busio
import adafruit_sgp30
import board
import adafruit_pm25
from tool import show_SGP, show_SGP_baseline # for SGP30
from tool import show_PM25 # for PMSA003
from tool import color_chase_1 # for NeoPixel
from tool import play_file # for AudioOut
# 設定 LED 顏色
RED = (255, 0, 0)
GREEN = (0, 255, 0)
OFF = (0, 0, 0)
i2c_bus = busio.I2C(board.SCL, board.SDA, frequency=100000)
# Create library object on I2C port
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus)
print("SGP30 serial #", [hex(i) for i in sgp30.serial])
sgp30.iaq_init()
# sgp30.set_iaq_baseline(co2eq_base, tvoc_base)
# elapsed_sec = 0
reset_pin = None
uart = busio.UART(board.TX, board.RX, baudrate=9600)
pm25 = adafruit_pm25.PM25_UART(uart, reset_pin)
# Enable the speaker
spkrenable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = digitalio.Direction.OUTPUT
spkrenable.value = True
# Make the 2 input buttons
11
CircuitPython(SGP30+PMSA003)實作-2
# Tools
import time
import board
import neopixel
dup = 37 # hyphen
# include audio libraries
try:
from audiocore import WaveFile
except ImportError:
from audioio import WaveFile
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
pixels = neopixel.NeoPixel(
board.NEOPIXEL,
10,
brightness=0.2,
auto_write=False
)
# LED 全亮
def color_chase_all(color, wait):
for i in range(10):
pixels[i] = color
time.sleep(wait)
pixels.show()
12
CircuitPython(SGP30+PMSA003)實作-3
 善用工具:
 簡化程式:將重複的程式碼移至 tool.py 並製作成 function 供主程式 code.py 呼叫,
類似積木的使用方式
13
你(妳)成功了嗎?!
14
Q & A
15

More Related Content

PPTX
MG3130 gesture recognition kit
PPT
Led blinking using TMS320C6745
PPTX
量測儀表聯網
PPT
Interfacing UART with tms320C6745
PPT
Waveform Generation Using TMS320C6745 DSP
PPTX
智慧城市通用交通資訊端點系統
PPT
Switch & LED using TMS320C6745 DSP
PPTX
Tutorial1: mbed開發快速上手
MG3130 gesture recognition kit
Led blinking using TMS320C6745
量測儀表聯網
Interfacing UART with tms320C6745
Waveform Generation Using TMS320C6745 DSP
智慧城市通用交通資訊端點系統
Switch & LED using TMS320C6745 DSP
Tutorial1: mbed開發快速上手

What's hot (20)

PPTX
JavaOne: Using NetBeans RCP to control your Lego [con1702]
PPTX
JavaOne: Using actors for the iInternet of (Lego) Trains [con1709]
PPTX
EuregJUG: Using actors for the internet of (lego) trains
PPT
3D-DRESD ASIDA
PPTX
Smart oven 智慧烤箱
PPTX
Pc 104 series 1 application showcase
PPT
Introduction to tms320c6745 dsp
PDF
IoT of heart rate watchdog
PDF
ADS-B, AIS, APRS cheatsheet
PDF
Mobile Development For Arduino 201 - ConnectTech
PPTX
8051 microcontroller
PDF
AM437x Product on Module
PDF
A High Performance Heterogeneous FPGA-based Accelerator with PyCoRAM (Runner ...
PDF
必見!絶対におすすめの通信業界セッション 5 つ ~秋の GTC 2020~
PDF
Case Study: Large Scale Deployment for Machine Learning with Highspeed Storage
PPT
ETRX3 ZigBee Module: ETRX3
PDF
PyCoRAM: Yet Another Implementation of CoRAM Memory Architecture for Modern F...
PDF
PDF
Black Hat Europe 2015 - Time and Position Spoofing with Open Source Projects
JavaOne: Using NetBeans RCP to control your Lego [con1702]
JavaOne: Using actors for the iInternet of (Lego) Trains [con1709]
EuregJUG: Using actors for the internet of (lego) trains
3D-DRESD ASIDA
Smart oven 智慧烤箱
Pc 104 series 1 application showcase
Introduction to tms320c6745 dsp
IoT of heart rate watchdog
ADS-B, AIS, APRS cheatsheet
Mobile Development For Arduino 201 - ConnectTech
8051 microcontroller
AM437x Product on Module
A High Performance Heterogeneous FPGA-based Accelerator with PyCoRAM (Runner ...
必見!絶対におすすめの通信業界セッション 5 つ ~秋の GTC 2020~
Case Study: Large Scale Deployment for Machine Learning with Highspeed Storage
ETRX3 ZigBee Module: ETRX3
PyCoRAM: Yet Another Implementation of CoRAM Memory Architecture for Modern F...
Black Hat Europe 2015 - Time and Position Spoofing with Open Source Projects
Ad

Similar to Coding with CircuitPython@CPB (20)

PPTX
Raspberry Pi I/O控制與感測器讀取
PDF
SHUTTLE NCBT419 Bay trail REV A - Lenovo LNV 4030 LNV-004.pdf
PDF
Acer Aspire 5349_5749 Quanta ZRL DA0ZRLMB6D0 Rev1A schematic.pdf
PDF
Linux+sensor+device-tree+shell=IoT !
PDF
Getting Started With Raspberry Pi - UCSD 2013
PDF
z61ae.pdf
PDF
Vlsi es-lab-manual
PPT
Ae01 system overview
PDF
I made some more expansion board for M5Stack
DOCX
Stand Alone Programmers -Crystals and Oscillators - componentship.com
PPTX
Innovation with pcDuino
PDF
Introducing the Arduino
PDF
PIC Axe049(print34)
PDF
0393 1 qs_emea_eng_print
PDF
dotFes 2008 TOKYO
PPTX
2014 09 12 Dia Programador Session Materials
PPTX
Pengenalan Perangkat Nokia 7210 SASSx.pptx
PDF
Pilot Raspeberry pi 3g user manual
PPTX
Raspberry-Pi GPIO
PDF
YCAM Workshop Part 1
Raspberry Pi I/O控制與感測器讀取
SHUTTLE NCBT419 Bay trail REV A - Lenovo LNV 4030 LNV-004.pdf
Acer Aspire 5349_5749 Quanta ZRL DA0ZRLMB6D0 Rev1A schematic.pdf
Linux+sensor+device-tree+shell=IoT !
Getting Started With Raspberry Pi - UCSD 2013
z61ae.pdf
Vlsi es-lab-manual
Ae01 system overview
I made some more expansion board for M5Stack
Stand Alone Programmers -Crystals and Oscillators - componentship.com
Innovation with pcDuino
Introducing the Arduino
PIC Axe049(print34)
0393 1 qs_emea_eng_print
dotFes 2008 TOKYO
2014 09 12 Dia Programador Session Materials
Pengenalan Perangkat Nokia 7210 SASSx.pptx
Pilot Raspeberry pi 3g user manual
Raspberry-Pi GPIO
YCAM Workshop Part 1
Ad

Recently uploaded (20)

PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Geodesy 1.pptx...............................................
PPTX
UNIT 4 Total Quality Management .pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
composite construction of structures.pdf
PDF
PPT on Performance Review to get promotions
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
737-MAX_SRG.pdf student reference guides
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Well-logging-methods_new................
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Geodesy 1.pptx...............................................
UNIT 4 Total Quality Management .pptx
Mechanical Engineering MATERIALS Selection
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Foundation to blockchain - A guide to Blockchain Tech
composite construction of structures.pdf
PPT on Performance Review to get promotions
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Fundamentals of safety and accident prevention -final (1).pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Sustainable Sites - Green Building Construction
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
737-MAX_SRG.pdf student reference guides
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
OOP with Java - Java Introduction (Basics)
CH1 Production IntroductoryConcepts.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Well-logging-methods_new................

Coding with CircuitPython@CPB

  • 3. 準備材料  Adafruit Circuit Playground Bluefruit Microcontroller Board  Adafruit SGP30 Air Quality Sensor Breakout-VOC、eCO2  PLANTOWER PMSA003 Laser PM2.5 Air Quality Sensor (含G7專用轉接板與連接 線--8pin 1.25mm 轉 2.54mm)  Lithium Ion Polymer Battery - 3.7V 2000mAh(JST connector) or MB102 Breadboard Power Supply Module 3.3V/5V  Breadboard  Dupont Line  Alligator-clip  USB cable 3
  • 5. CircuitPython簡介  CircuitPython is a programming language designed to simplify experimenting and learning to program on low-cost microcontroller boards.  CircuitPython is based on Python  Advantage:  Running quickly  Easily update your code  Serial console and REPL 5
  • 6. CircuitPython安裝  Follow the step from https://learn.adafruit.com/adafruit-circuit-playground- bluefruit/circuitpython  Download the latest UF2 file -- CircuitPython 6.0.0-beta.2  Double-click the small RESET button in the middle of the CPB  Drag the adafruit_circuitpython_xxx-6.0.0-xxx.uf2 file to CPLAYBTBOOT  Download the latest library bundle file -- Bundle Version 6.x  Copy the following folders and files from the bundle lib folder to the lib folder on your CIRCUITPY drive 6
  • 7. Installing Mu Editor  Download Mu from https://codewith.mu  Click [Download] -- Windows 64-bit  Using Mu 7
  • 8. CircuitPython實作  Blinking the D13 LED -- https://learn.adafruit.com/adafruit-circuit-playground- bluefruit/creating-and-editing-code  Copy Code  Paste the code into Mu editor  Save as code.py on your CIRCUITPY drive  Connecting to the Serial Console – print("Hello, world!")  The REPL  Press any key to enter the REPL  Use Ctrl+D to reload  Press Ctrl+C to interrupt  CircuitPython Playground: https://learn.adafruit.com/adafruit-circuit-playground- bluefruit/circuitpython-playground 8
  • 10. 10
  • 11. CircuitPython(SGP30+PMSA003+Audio) 實作-1 """ Example for using the SGP30 and PM25 with CircuitPython and the Adafruit library """ import digitalio import busio import adafruit_sgp30 import board import adafruit_pm25 from tool import show_SGP, show_SGP_baseline # for SGP30 from tool import show_PM25 # for PMSA003 from tool import color_chase_1 # for NeoPixel from tool import play_file # for AudioOut # 設定 LED 顏色 RED = (255, 0, 0) GREEN = (0, 255, 0) OFF = (0, 0, 0) i2c_bus = busio.I2C(board.SCL, board.SDA, frequency=100000) # Create library object on I2C port sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus) print("SGP30 serial #", [hex(i) for i in sgp30.serial]) sgp30.iaq_init() # sgp30.set_iaq_baseline(co2eq_base, tvoc_base) # elapsed_sec = 0 reset_pin = None uart = busio.UART(board.TX, board.RX, baudrate=9600) pm25 = adafruit_pm25.PM25_UART(uart, reset_pin) # Enable the speaker spkrenable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) spkrenable.direction = digitalio.Direction.OUTPUT spkrenable.value = True # Make the 2 input buttons 11
  • 12. CircuitPython(SGP30+PMSA003)實作-2 # Tools import time import board import neopixel dup = 37 # hyphen # include audio libraries try: from audiocore import WaveFile except ImportError: from audioio import WaveFile try: from audioio import AudioOut except ImportError: try: from audiopwmio import PWMAudioOut as AudioOut except ImportError: pass # not always supported by every board! pixels = neopixel.NeoPixel( board.NEOPIXEL, 10, brightness=0.2, auto_write=False ) # LED 全亮 def color_chase_all(color, wait): for i in range(10): pixels[i] = color time.sleep(wait) pixels.show() 12
  • 13. CircuitPython(SGP30+PMSA003)實作-3  善用工具:  簡化程式:將重複的程式碼移至 tool.py 並製作成 function 供主程式 code.py 呼叫, 類似積木的使用方式 13