Skip to content

Commit afce312

Browse files
authored
Merge pull request #1372 from kattni/qt-py-essentials
Updating Essentials guide to include QT Py.
2 parents c07c715 + 1e9f0e1 commit afce312

29 files changed

+64
-50
lines changed

CircuitPython_Essentials/CircuitPython_AnalogIn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CircuitPython AnalogIn Demo
1+
"""CircuitPython Essentials Analog In example"""
22
import time
33
import board
44
from analogio import AnalogIn

CircuitPython_Essentials/CircuitPython_AnalogOut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CircuitPython IO demo - analog output
1+
"""CircuitPython Analog Out example"""
22
import board
33
from analogio import AnalogOut
44

CircuitPython_Essentials/CircuitPython_Audio_Out_MP3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials Audio Out MP3 Example"""
12
import board
23
import digitalio
34

CircuitPython_Essentials/CircuitPython_Audio_Out_Tone.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials Audio Out tone example"""
12
import time
23
import array
34
import math

CircuitPython_Essentials/CircuitPython_Audio_Out_Wave.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials Audio Out WAV example"""
12
import time
23
import board
34
import digitalio

CircuitPython_Essentials/CircuitPython_CapTouch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
"""CircuitPython Essentials Capacitive Touch example"""
12
import time
2-
33
import board
44
import touchio
55

CircuitPython_Essentials/CircuitPython_CapTouch_2Pins.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# CircuitPython Demo - Cap Touch Multiple Pins
2-
# Example does NOT work with Trinket M0!
3-
1+
"""CircuitPython Essentials Capacitive Touch on two pins example. Does not work on Trinket M0!"""
42
import time
5-
63
import board
74
import touchio
85

CircuitPython_Essentials/CircuitPython_Continuous_Servo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Continuous Servo Test Program for CircuitPython
1+
"""CircuitPython Essentials Servo continuous rotation servo example"""
22
import time
33
import board
44
import pulseio

CircuitPython_Essentials/CircuitPython_Digital_In_Out.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# CircuitPython IO demo #1 - General Purpose I/O
1+
"""CircuitPython Essentials Digital In Out example"""
22
import time
33
import board
44
from digitalio import DigitalInOut, Direction, Pull
55

6+
# LED setup.
67
led = DigitalInOut(board.D13)
8+
# For QT Py M0. QT Py M0 does not have a D13 LED, so you can connect an external LED instead.
9+
# led = DigitalInOut(board.SCK)
710
led.direction = Direction.OUTPUT
811

9-
# For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express, Itsy M4 Express
12+
# For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express, Itsy M4 Express, QT Py M0
1013
switch = DigitalInOut(board.D2)
1114
# switch = DigitalInOut(board.D5) # For Feather M0 Express, Feather M4 Express
1215
# switch = DigitalInOut(board.D7) # For Circuit Playground Express

CircuitPython_Essentials/CircuitPython_DotStar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CircuitPython demo - Dotstar
1+
"""CircuitPython Essentials DotStar example"""
22
import time
33
import adafruit_dotstar
44
import board
@@ -7,7 +7,7 @@
77
pixels = adafruit_dotstar.DotStar(board.A1, board.A2, num_pixels, brightness=0.1, auto_write=False)
88

99

10-
def wheel(pos):
10+
def colorwheel(pos):
1111
# Input a value 0 to 255 to get a color value.
1212
# The colours are a transition r - g - b - back to r.
1313
if pos < 0 or pos > 255:
@@ -85,7 +85,7 @@ def rainbow_cycle(wait):
8585
for j in range(255):
8686
for i in range(num_pixels):
8787
rc_index = (i * 256 // num_pixels) + j
88-
pixels[i] = wheel(rc_index & 255)
88+
pixels[i] = colorwheel(rc_index & 255)
8989
pixels.show()
9090
time.sleep(wait)
9191

CircuitPython_Essentials/CircuitPython_HID_Keyboard.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# CircuitPython demo - Keyboard emulator
2-
1+
"""CircuitPython Essentials HID Keyboard example"""
32
import time
43

54
import board
@@ -31,7 +30,10 @@
3130
key_pin.pull = digitalio.Pull.UP
3231
key_pin_array.append(key_pin)
3332

33+
# For most CircuitPython boards:
3434
led = digitalio.DigitalInOut(board.D13)
35+
# For QT Py M0:
36+
# led = digitalio.DigitalInOut(board.SCK)
3537
led.direction = digitalio.Direction.OUTPUT
3638

3739
print("Waiting for key pin...")

CircuitPython_Essentials/CircuitPython_HID_Mouse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
"""CircuitPython Essentials HID Mouse example"""
12
import time
2-
33
import analogio
44
import board
55
import digitalio

CircuitPython_Essentials/CircuitPython_I2C_Scan.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# CircuitPython demo - I2C scan
2-
#
1+
"""CircuitPython Essentials I2C Scan example"""
32
# If you run this and it seems to hang, try manually unlocking
43
# your I2C bus from the REPL with
5-
# >>> import board
6-
# >>> board.I2C().unlock()
4+
# >>> import board
5+
# >>> board.I2C().unlock()
76

87
import time
98
import board
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
# CircuitPython Demo - I2C sensor
2-
1+
"""CircuitPython Essentials I2C sensor example using TSL2591"""
32
import time
4-
5-
import adafruit_tsl2561
63
import board
4+
import adafruit_tsl2591
75

86
i2c = board.I2C()
97

108
# Lock the I2C device before we try to scan
119
while not i2c.try_lock():
1210
pass
1311
# Print the addresses found once
14-
print("I2C addresses found:", [hex(device_address)
15-
for device_address in i2c.scan()])
12+
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()])
1613

1714
# Unlock I2C now that we're done scanning.
1815
i2c.unlock()
1916

2017
# Create library object on our I2C port
21-
tsl2561 = adafruit_tsl2561.TSL2561(i2c)
18+
tsl2591 = adafruit_tsl2591.TSL2591(i2c)
2219

2320
# Use the object to print the sensor readings
2421
while True:
25-
print("Lux:", tsl2561.lux)
26-
time.sleep(1.0)
22+
print("Lux:", tsl2591.lux)
23+
time.sleep(0.5)

CircuitPython_Essentials/CircuitPython_Internal_RGB_LED_colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
"""CircuitPython Essentials Internal RGB LED red, green, blue example"""
12
import time
23
import board
34

45
# For Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express
56
import adafruit_dotstar
67
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
7-
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, and Circuit Playground Express
8+
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, Circuit Playground Express, QT Py M0
89
# import neopixel
910
# led = neopixel.NeoPixel(board.NEOPIXEL, 1)
1011

CircuitPython_Essentials/CircuitPython_Internal_RGB_LED_rainbow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
"""CircuitPython Essentials Internal RGB LED rainbow example"""
12
import time
23
import board
34

45
# For Trinket M0, Gemma M0, ItsyBitsy M0 Express and ItsyBitsy M4 Express
56
import adafruit_dotstar
67
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
7-
# For Feather M0 Express, Metro M0 Express, Metro M4 Express and Circuit Playground Express
8+
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, Circuit Playground Express, QT Py M0
89
# import neopixel
910
# led = neopixel.NeoPixel(board.NEOPIXEL, 1)
1011

1112

12-
def wheel(pos):
13+
def colorwheel(pos):
1314
# Input a value 0 to 255 to get a color value.
1415
# The colours are a transition r - g - b - back to r.
1516
if pos < 0 or pos > 255:
@@ -28,5 +29,5 @@ def wheel(pos):
2829
i = 0
2930
while True:
3031
i = (i + 1) % 256 # run from 0 to 255
31-
led.fill(wheel(i))
32-
time.sleep(0.1)
32+
led.fill(colorwheel(i))
33+
time.sleep(0.01)

CircuitPython_Essentials/CircuitPython_Logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
"""CircuitPython Essentials Storage logging example"""
12
import time
2-
33
import board
44
import digitalio
55
import microcontroller
66

7+
# For most CircuitPython boards:
78
led = digitalio.DigitalInOut(board.D13)
9+
# For QT Py M0:
10+
# led = digitalio.DigitalInOut(board.SCK)
811
led.switch_to_output()
912

1013
try:

CircuitPython_Essentials/CircuitPython_Logger_Boot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials Storage logging boot.py file"""
12
import board
23
import digitalio
34
import storage

CircuitPython_Essentials/CircuitPython_NeoPixel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CircuitPython demo - NeoPixel
1+
"""CircuitPython Essentials NeoPixel example"""
22
import time
33
import board
44
import neopixel

CircuitPython_Essentials/CircuitPython_NeoPixel_RGBW.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# CircuitPython demo - NeoPixel RGBW
2-
1+
"""CircuitPython Essentials NeoPixel RGBW example"""
32
import time
43
import board
54
import neopixel

CircuitPython_Essentials/CircuitPython_PWM.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
"""CircuitPython Essentials: PWM with Fixed Frequency example."""
12
import time
23
import board
34
import pulseio
45

6+
# LED setup for most CircuitPython boards:
57
led = pulseio.PWMOut(board.D13, frequency=5000, duty_cycle=0)
8+
# LED setup for QT Py M0:
9+
# led = pulseio.PWMOut(board.SCK, frequency=5000, duty_cycle=0)
610

711
while True:
812
for i in range(100):

CircuitPython_Essentials/CircuitPython_PWM_Piezo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials PWM with variable frequency piezo example"""
12
import time
23
import board
34
import pulseio

CircuitPython_Essentials/CircuitPython_PWM_Piezo_simpleio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials PWM piezo simpleio example"""
12
import time
23
import board
34
import simpleio

CircuitPython_Essentials/CircuitPython_Servo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials Servo standard servo example"""
12
import time
23
import board
34
import pulseio

CircuitPython_Essentials/CircuitPython_UART.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# CircuitPython Demo - USB/Serial echo
2-
1+
"""CircuitPython Essentials UART Serial example"""
32
import board
43
import busio
54
import digitalio
65

6+
# For most CircuitPython boards:
77
led = digitalio.DigitalInOut(board.D13)
8+
# For QT Py M0:
9+
# led = digitalio.DigitalInOut(board.SCK)
810
led.direction = digitalio.Direction.OUTPUT
911

1012
uart = busio.UART(board.TX, board.RX, baudrate=9600)

CircuitPython_Essentials/I2C_Test_Script.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
"""CircuitPython Essentials I2C possible pin-pair identifying script"""
12
import board
23
import busio
34
from microcontroller import Pin
45

6+
57
def is_hardware_I2C(scl, sda):
68
try:
79
p = busio.I2C(scl, sda)
@@ -29,8 +31,5 @@ def get_unique_pins():
2931
for sda_pin in get_unique_pins():
3032
if scl_pin is sda_pin:
3133
continue
32-
else:
33-
if is_hardware_I2C(scl_pin, sda_pin):
34-
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)
35-
else:
36-
pass
34+
if is_hardware_I2C(scl_pin, sda_pin):
35+
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)

CircuitPython_Essentials/PWM_Test_Script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials PWM pin identifying script"""
12
import board
23
import pulseio
34

CircuitPython_Essentials/SPI_Test_Script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials Hardware SPI pin verification script"""
12
import board
23
import busio
34

CircuitPython_Essentials/UART_Test_Script.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""CircuitPython Essentials UART possible pin-pair identifying script"""
12
import board
23
import busio
34
from microcontroller import Pin
@@ -28,8 +29,5 @@ def get_unique_pins():
2829
for rx_pin in get_unique_pins():
2930
if rx_pin is tx_pin:
3031
continue
31-
else:
32-
if is_hardware_uart(tx_pin, rx_pin):
33-
print("RX pin:", rx_pin, "\t TX pin:", tx_pin)
34-
else:
35-
pass
32+
if is_hardware_uart(tx_pin, rx_pin):
33+
print("RX pin:", rx_pin, "\t TX pin:", tx_pin)

0 commit comments

Comments
 (0)