Skip to content

Updating Essentials guide to include QT Py. #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CircuitPython_Essentials/CircuitPython_AnalogIn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CircuitPython AnalogIn Demo
"""CircuitPython Essentials Analog In example"""
import time
import board
from analogio import AnalogIn
Expand Down
2 changes: 1 addition & 1 deletion CircuitPython_Essentials/CircuitPython_AnalogOut.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CircuitPython IO demo - analog output
"""CircuitPython Analog Out example"""
import board
from analogio import AnalogOut

Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/CircuitPython_Audio_Out_MP3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials Audio Out MP3 Example"""
import board
import digitalio

Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/CircuitPython_Audio_Out_Tone.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials Audio Out tone example"""
import time
import array
import math
Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/CircuitPython_Audio_Out_Wave.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials Audio Out WAV example"""
import time
import board
import digitalio
Expand Down
2 changes: 1 addition & 1 deletion CircuitPython_Essentials/CircuitPython_CapTouch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""CircuitPython Essentials Capacitive Touch example"""
import time

import board
import touchio

Expand Down
5 changes: 1 addition & 4 deletions CircuitPython_Essentials/CircuitPython_CapTouch_2Pins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# CircuitPython Demo - Cap Touch Multiple Pins
# Example does NOT work with Trinket M0!

"""CircuitPython Essentials Capacitive Touch on two pins example. Does not work on Trinket M0!"""
import time

import board
import touchio

Expand Down
2 changes: 1 addition & 1 deletion CircuitPython_Essentials/CircuitPython_Continuous_Servo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Continuous Servo Test Program for CircuitPython
"""CircuitPython Essentials Servo continuous rotation servo example"""
import time
import board
import pulseio
Expand Down
7 changes: 5 additions & 2 deletions CircuitPython_Essentials/CircuitPython_Digital_In_Out.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# CircuitPython IO demo #1 - General Purpose I/O
"""CircuitPython Essentials Digital In Out example"""
import time
import board
from digitalio import DigitalInOut, Direction, Pull

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

# For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express, Itsy M4 Express
# For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express, Itsy M4 Express, QT Py M0
switch = DigitalInOut(board.D2)
# switch = DigitalInOut(board.D5) # For Feather M0 Express, Feather M4 Express
# switch = DigitalInOut(board.D7) # For Circuit Playground Express
Expand Down
6 changes: 3 additions & 3 deletions CircuitPython_Essentials/CircuitPython_DotStar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CircuitPython demo - Dotstar
"""CircuitPython Essentials DotStar example"""
import time
import adafruit_dotstar
import board
Expand All @@ -7,7 +7,7 @@
pixels = adafruit_dotstar.DotStar(board.A1, board.A2, num_pixels, brightness=0.1, auto_write=False)


def wheel(pos):
def colorwheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
Expand Down Expand Up @@ -85,7 +85,7 @@ def rainbow_cycle(wait):
for j in range(255):
for i in range(num_pixels):
rc_index = (i * 256 // num_pixels) + j
pixels[i] = wheel(rc_index & 255)
pixels[i] = colorwheel(rc_index & 255)
pixels.show()
time.sleep(wait)

Expand Down
6 changes: 4 additions & 2 deletions CircuitPython_Essentials/CircuitPython_HID_Keyboard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# CircuitPython demo - Keyboard emulator

"""CircuitPython Essentials HID Keyboard example"""
import time

import board
Expand Down Expand Up @@ -31,7 +30,10 @@
key_pin.pull = digitalio.Pull.UP
key_pin_array.append(key_pin)

# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.D13)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT

print("Waiting for key pin...")
Expand Down
2 changes: 1 addition & 1 deletion CircuitPython_Essentials/CircuitPython_HID_Mouse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""CircuitPython Essentials HID Mouse example"""
import time

import analogio
import board
import digitalio
Expand Down
7 changes: 3 additions & 4 deletions CircuitPython_Essentials/CircuitPython_I2C_Scan.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# CircuitPython demo - I2C scan
#
"""CircuitPython Essentials I2C Scan example"""
# If you run this and it seems to hang, try manually unlocking
# your I2C bus from the REPL with
# >>> import board
# >>> board.I2C().unlock()
# >>> import board
# >>> board.I2C().unlock()

import time
import board
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
# CircuitPython Demo - I2C sensor

"""CircuitPython Essentials I2C sensor example using TSL2591"""
import time

import adafruit_tsl2561
import board
import adafruit_tsl2591

i2c = board.I2C()

# Lock the I2C device before we try to scan
while not i2c.try_lock():
pass
# Print the addresses found once
print("I2C addresses found:", [hex(device_address)
for device_address in i2c.scan()])
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()])

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

# Create library object on our I2C port
tsl2561 = adafruit_tsl2561.TSL2561(i2c)
tsl2591 = adafruit_tsl2591.TSL2591(i2c)

# Use the object to print the sensor readings
while True:
print("Lux:", tsl2561.lux)
time.sleep(1.0)
print("Lux:", tsl2591.lux)
time.sleep(0.5)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""CircuitPython Essentials Internal RGB LED red, green, blue example"""
import time
import board

# For Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express
import adafruit_dotstar
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, and Circuit Playground Express
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, Circuit Playground Express, QT Py M0
# import neopixel
# led = neopixel.NeoPixel(board.NEOPIXEL, 1)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""CircuitPython Essentials Internal RGB LED rainbow example"""
import time
import board

# For Trinket M0, Gemma M0, ItsyBitsy M0 Express and ItsyBitsy M4 Express
import adafruit_dotstar
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
# For Feather M0 Express, Metro M0 Express, Metro M4 Express and Circuit Playground Express
# For Feather M0 Express, Metro M0 Express, Metro M4 Express, Circuit Playground Express, QT Py M0
# import neopixel
# led = neopixel.NeoPixel(board.NEOPIXEL, 1)


def wheel(pos):
def colorwheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
Expand All @@ -28,5 +29,5 @@ def wheel(pos):
i = 0
while True:
i = (i + 1) % 256 # run from 0 to 255
led.fill(wheel(i))
time.sleep(0.1)
led.fill(colorwheel(i))
time.sleep(0.01)
5 changes: 4 additions & 1 deletion CircuitPython_Essentials/CircuitPython_Logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""CircuitPython Essentials Storage logging example"""
import time

import board
import digitalio
import microcontroller

# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.D13)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.switch_to_output()

try:
Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/CircuitPython_Logger_Boot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials Storage logging boot.py file"""
import board
import digitalio
import storage
Expand Down
2 changes: 1 addition & 1 deletion CircuitPython_Essentials/CircuitPython_NeoPixel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CircuitPython demo - NeoPixel
"""CircuitPython Essentials NeoPixel example"""
import time
import board
import neopixel
Expand Down
3 changes: 1 addition & 2 deletions CircuitPython_Essentials/CircuitPython_NeoPixel_RGBW.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# CircuitPython demo - NeoPixel RGBW

"""CircuitPython Essentials NeoPixel RGBW example"""
import time
import board
import neopixel
Expand Down
4 changes: 4 additions & 0 deletions CircuitPython_Essentials/CircuitPython_PWM.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""CircuitPython Essentials: PWM with Fixed Frequency example."""
import time
import board
import pulseio

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

while True:
for i in range(100):
Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/CircuitPython_PWM_Piezo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials PWM with variable frequency piezo example"""
import time
import board
import pulseio
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials PWM piezo simpleio example"""
import time
import board
import simpleio
Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/CircuitPython_Servo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials Servo standard servo example"""
import time
import board
import pulseio
Expand Down
6 changes: 4 additions & 2 deletions CircuitPython_Essentials/CircuitPython_UART.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# CircuitPython Demo - USB/Serial echo

"""CircuitPython Essentials UART Serial example"""
import board
import busio
import digitalio

# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.D13)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT

uart = busio.UART(board.TX, board.RX, baudrate=9600)
Expand Down
9 changes: 4 additions & 5 deletions CircuitPython_Essentials/I2C_Test_Script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""CircuitPython Essentials I2C possible pin-pair identifying script"""
import board
import busio
from microcontroller import Pin


def is_hardware_I2C(scl, sda):
try:
p = busio.I2C(scl, sda)
Expand Down Expand Up @@ -29,8 +31,5 @@ def get_unique_pins():
for sda_pin in get_unique_pins():
if scl_pin is sda_pin:
continue
else:
if is_hardware_I2C(scl_pin, sda_pin):
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)
else:
pass
if is_hardware_I2C(scl_pin, sda_pin):
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)
1 change: 1 addition & 0 deletions CircuitPython_Essentials/PWM_Test_Script.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials PWM pin identifying script"""
import board
import pulseio

Expand Down
1 change: 1 addition & 0 deletions CircuitPython_Essentials/SPI_Test_Script.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials Hardware SPI pin verification script"""
import board
import busio

Expand Down
8 changes: 3 additions & 5 deletions CircuitPython_Essentials/UART_Test_Script.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CircuitPython Essentials UART possible pin-pair identifying script"""
import board
import busio
from microcontroller import Pin
Expand Down Expand Up @@ -28,8 +29,5 @@ def get_unique_pins():
for rx_pin in get_unique_pins():
if rx_pin is tx_pin:
continue
else:
if is_hardware_uart(tx_pin, rx_pin):
print("RX pin:", rx_pin, "\t TX pin:", tx_pin)
else:
pass
if is_hardware_uart(tx_pin, rx_pin):
print("RX pin:", rx_pin, "\t TX pin:", tx_pin)