Lab 8-Pico W Introduction
This commit is contained in:
parent
1e1bddf63c
commit
c7ac62b6b3
26 changed files with 8387 additions and 5 deletions
Binary file not shown.
33
Lab08/CircuitPython/Code/blink_external.py
Normal file
33
Lab08/CircuitPython/Code/blink_external.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led15 = digitalio.DigitalInOut(board.GP15)
|
||||
led16 = digitalio.DigitalInOut(board.GP16)
|
||||
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
led15.direction = digitalio.Direction.OUTPUT
|
||||
led16.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
|
||||
while True:
|
||||
print("On")
|
||||
led.value = True #turn on the LED
|
||||
led15.value = True #turn on the LED
|
||||
led16.value = True #turn on the LED
|
||||
time.sleep(1) #wait for one second
|
||||
print("Off")
|
||||
led.value = False #turn off the LED
|
||||
led15.value = False #turn off the LED
|
||||
led16.value = False #turn off the LED
|
||||
time.sleep(1) #wait for one second
|
||||
|
||||
|
||||
|
||||
32
Lab08/CircuitPython/Code/blink_external2.py
Normal file
32
Lab08/CircuitPython/Code/blink_external2.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led15 = digitalio.DigitalInOut(board.GP15)
|
||||
led16 = digitalio.DigitalInOut(board.GP16)
|
||||
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
led15.direction = digitalio.Direction.OUTPUT
|
||||
led16.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
while True:
|
||||
print("Start")
|
||||
led.value = True #turn on the LED
|
||||
led15.value = False #turn on the LED
|
||||
led16.value = True #turn on the LED
|
||||
time.sleep(1) #wait for one second
|
||||
print("Off")
|
||||
led.value = False #turn off the LED
|
||||
led15.value = True #turn off the LED
|
||||
led16.value = False #turn off the LED
|
||||
time.sleep(1) #wait for one second
|
||||
|
||||
|
||||
|
||||
|
||||
43
Lab08/CircuitPython/Code/blink_external_cycle.py
Normal file
43
Lab08/CircuitPython/Code/blink_external_cycle.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led15 = digitalio.DigitalInOut(board.GP15)
|
||||
led16 = digitalio.DigitalInOut(board.GP16)
|
||||
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
led15.direction = digitalio.Direction.OUTPUT
|
||||
led16.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Cycle the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
|
||||
def cycleLED(ledID):
|
||||
ledID.value = True
|
||||
time.sleep(1)
|
||||
ledID.value = False
|
||||
time.sleep(1)
|
||||
|
||||
def turnOffLED(ledID):
|
||||
ledID.value = False
|
||||
|
||||
print("Turn off all LED's")
|
||||
turnOffLED(led)
|
||||
turnOffLED(led15)
|
||||
turnOffLED(led16)
|
||||
|
||||
print("Cycle LEDs")
|
||||
|
||||
while True:
|
||||
|
||||
print("Cycle start")
|
||||
cycleLED(led)
|
||||
cycleLED(led15)
|
||||
cycleLED(led16)
|
||||
|
||||
time.sleep(1) #wait for one second
|
||||
|
||||
44
Lab08/CircuitPython/Code/blink_external_cycle2.py
Normal file
44
Lab08/CircuitPython/Code/blink_external_cycle2.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led15 = digitalio.DigitalInOut(board.GP15)
|
||||
led16 = digitalio.DigitalInOut(board.GP16)
|
||||
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
led15.direction = digitalio.Direction.OUTPUT
|
||||
led16.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Cycle the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
|
||||
def cycleLED(ledID):
|
||||
ledID.value = True
|
||||
time.sleep(1)
|
||||
ledID.value = False
|
||||
time.sleep(1)
|
||||
|
||||
def turnOffLED(ledID):
|
||||
ledID.value = False
|
||||
|
||||
print("Turn off all LED's")
|
||||
turnOffLED(led)
|
||||
turnOffLED(led15)
|
||||
turnOffLED(led16)
|
||||
|
||||
print("Cycle LEDs")
|
||||
|
||||
while True:
|
||||
|
||||
print("Cycle start")
|
||||
cycleLED(led)
|
||||
cycleLED(led15)
|
||||
cycleLED(led16)
|
||||
cycleLED(led15)
|
||||
|
||||
time.sleep(.25) #wait for one second
|
||||
|
||||
48
Lab08/CircuitPython/Code/blink_external_cycle3.py
Normal file
48
Lab08/CircuitPython/Code/blink_external_cycle3.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Cycle the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
|
||||
ledList = ['LED', 'GP15', 'GP16']
|
||||
ledPinList = [
|
||||
digitalio.DigitalInOut(board.LED),
|
||||
digitalio.DigitalInOut(board.GP15),
|
||||
digitalio.DigitalInOut(board.GP16)
|
||||
]
|
||||
|
||||
def cycleLED(ledID,timeDelay):
|
||||
ledID.value = True
|
||||
time.sleep(timeDelay)
|
||||
ledID.value = False
|
||||
time.sleep(timeDelay)
|
||||
|
||||
def turnOffLED(ledPinList):
|
||||
for pinID in ledPinList:
|
||||
pinID.value = False
|
||||
|
||||
|
||||
for pinID in ledPinList:
|
||||
pinID.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("Turn off all LED's")
|
||||
turnOffLED(ledPinList)
|
||||
|
||||
timeDelay = .25
|
||||
print("Cycle LEDs")
|
||||
|
||||
while True:
|
||||
|
||||
print("Cycle start")
|
||||
cycleLED(ledPinList[0],timeDelay)
|
||||
cycleLED(ledPinList[1],timeDelay)
|
||||
cycleLED(ledPinList[2],timeDelay)
|
||||
cycleLED(ledPinList[1],timeDelay)
|
||||
|
||||
# time.sleep(1) #wait for one second
|
||||
|
||||
|
||||
48
Lab08/CircuitPython/Code/blink_external_cycle4.py
Normal file
48
Lab08/CircuitPython/Code/blink_external_cycle4.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Cycle the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
|
||||
ledList = ['LED', 'GP15', 'GP16']
|
||||
ledPinList = [
|
||||
digitalio.DigitalInOut(board.LED),
|
||||
digitalio.DigitalInOut(board.GP15),
|
||||
digitalio.DigitalInOut(board.GP16)
|
||||
]
|
||||
|
||||
ledPattern = [0, 1, 2, 1]
|
||||
|
||||
|
||||
def cycleLED(ledID,timeDelay):
|
||||
ledID.value = True
|
||||
time.sleep(timeDelay)
|
||||
ledID.value = False
|
||||
time.sleep(timeDelay)
|
||||
|
||||
def turnOffLED(ledPinList):
|
||||
for pinID in ledPinList:
|
||||
pinID.value = False
|
||||
|
||||
|
||||
for pinID in ledPinList:
|
||||
pinID.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("Turn off all LED's")
|
||||
turnOffLED(ledPinList)
|
||||
|
||||
timeDelay = .25
|
||||
print("Cycle LEDs")
|
||||
|
||||
while True:
|
||||
print("Cycle start")
|
||||
for ledTarget in ledPattern:
|
||||
cycleLED(ledPinList[ledTarget],timeDelay)
|
||||
|
||||
# time.sleep(1) #wait for one second
|
||||
|
||||
|
||||
21
Lab08/CircuitPython/Code/blink_internal.py
Normal file
21
Lab08/CircuitPython/Code/blink_internal.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("Hello, CircuitPython!")
|
||||
|
||||
while True:
|
||||
|
||||
print("On!")
|
||||
led.value = True
|
||||
time.sleep(1)
|
||||
|
||||
print("Off!")
|
||||
led.value = False
|
||||
time.sleep(1)
|
||||
|
||||
25
Lab08/CircuitPython/Documentation/RunCodeonPowerUp.txt
Normal file
25
Lab08/CircuitPython/Documentation/RunCodeonPowerUp.txt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Run Code on Power Up
|
||||
(From Google AI)
|
||||
|
||||
In CircuitPython, code automatically runs on power-up or reset if the file is named code.py. Alternatively, it will also work if named main.py.
|
||||
|
||||
How it Works
|
||||
When a CircuitPython board powers on, it automatically looks for and executes specific files in order:
|
||||
|
||||
boot.py: This file runs first, if present. It is typically used for initial setup configurations, such as re-assigning pins before the main program starts.
|
||||
|
||||
code.py (or main.py): After boot.py finishes, the board runs the code in this file. This is where your main program loop (e.g., a while True: loop) should reside.
|
||||
|
||||
Steps to Make Your Code Run on Power-up
|
||||
|
||||
Connect your board to your computer via a data-enabled USB cable. It will appear as a USB flash drive named CIRCUITPY.
|
||||
|
||||
Open the code.py file located on the CIRCUITPY drive using a code editor like the Mu editor or VS Code.
|
||||
|
||||
Write or paste your Python code into this file.
|
||||
|
||||
Save the file. As soon as you save the file to the CIRCUITPY drive, the board automatically soft-reboots and runs the newly saved code.
|
||||
|
||||
Power cycle the board. To confirm it runs on power-up, simply unplug the board and plug it back in. The program will start running immediately after the board finishes booting.
|
||||
|
||||
Any code in the code.py file will run every time the device is powered on or reset, without needing a computer connection (unless you want to view the serial output).
|
||||
10
Lab08/CircuitPython/README.md
Normal file
10
Lab08/CircuitPython/README.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# CircuitPython Files
|
||||
|
||||
---
|
||||
Directories & Files
|
||||
---
|
||||
CircuitPython: CircuitPython firmware for the Pico 2 W
|
||||
|
||||
Code: CircuitPython code for the lab.
|
||||
|
||||
Documentation: Any additional documentation files.
|
||||
Loading…
Add table
Add a link
Reference in a new issue