Lab 8-Pico W Introduction
This commit is contained in:
parent
1e1bddf63c
commit
c7ac62b6b3
26 changed files with 8387 additions and 5 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -107,10 +107,8 @@ ipython_config.py
|
||||||
#pdm.lock
|
#pdm.lock
|
||||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
# in version control.
|
# in version control.
|
||||||
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
.pdm.toml
|
.pdm.toml
|
||||||
.pdm-python
|
|
||||||
.pdm-build/
|
|
||||||
|
|
||||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
__pypackages__/
|
__pypackages__/
|
||||||
|
|
@ -160,5 +158,6 @@ cython_debug/
|
||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
.idea/
|
||||||
|
.DS_store
|
||||||
|
|
||||||
|
|
|
||||||
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.
|
||||||
8
Lab08/Doumentation/README.md
Normal file
8
Lab08/Doumentation/README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Lab08 Documentation
|
||||||
|
Introduction to the Pico W.
|
||||||
|
|
||||||
|
Pin diagrams, web links, and other information.
|
||||||
|
---
|
||||||
|
Directories & Files
|
||||||
|
---
|
||||||
|
RP-008315-DS-1-PicoW-A4-Pinout.pdf: Pinout diagram for the Pico 2 W.
|
||||||
7763
Lab08/Doumentation/RP-008315-DS-1-PicoW-A4-Pinout.pdf
Normal file
7763
Lab08/Doumentation/RP-008315-DS-1-PicoW-A4-Pinout.pdf
Normal file
File diff suppressed because one or more lines are too long
27
Lab08/MicroPython/Code/blink_external.py
Normal file
27
Lab08/MicroPython/Code/blink_external.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||||
|
|
||||||
|
led = machine.Pin('LED', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP15
|
||||||
|
led15 = machine.Pin('GP15', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP16
|
||||||
|
led16 = machine.Pin('GP16', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
26
Lab08/MicroPython/Code/blink_external2.py
Normal file
26
Lab08/MicroPython/Code/blink_external2.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||||
|
|
||||||
|
led = machine.Pin('LED', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP15
|
||||||
|
led15 = machine.Pin('GP15', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP16
|
||||||
|
led16 = machine.Pin('GP16', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("On")
|
||||||
|
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
|
||||||
|
|
||||||
39
Lab08/MicroPython/Code/blink_external_cycle.py
Normal file
39
Lab08/MicroPython/Code/blink_external_cycle.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||||
|
|
||||||
|
led = machine.Pin('LED', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP15
|
||||||
|
led15 = machine.Pin('GP15', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP16
|
||||||
|
led16 = machine.Pin('GP16', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
41
Lab08/MicroPython/Code/blink_external_cycle2.py
Normal file
41
Lab08/MicroPython/Code/blink_external_cycle2.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||||
|
|
||||||
|
led = machine.Pin('LED', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP15
|
||||||
|
led15 = machine.Pin('GP15', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP16
|
||||||
|
led16 = machine.Pin('GP16', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
|
||||||
|
def cycleLED(ledID,timeDelay):
|
||||||
|
ledID.value(True)
|
||||||
|
time.sleep(timeDelay)
|
||||||
|
ledID.value(False)
|
||||||
|
time.sleep(timeDelay)
|
||||||
|
|
||||||
|
def turnOffLED(ledID):
|
||||||
|
ledID.value(False)
|
||||||
|
|
||||||
|
print("Turn off all LED's")
|
||||||
|
turnOffLED(led)
|
||||||
|
turnOffLED(led15)
|
||||||
|
turnOffLED(led16)
|
||||||
|
|
||||||
|
timeDelay = .25
|
||||||
|
print("Cycle LEDs")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
print("Cycle start")
|
||||||
|
cycleLED(led,timeDelay)
|
||||||
|
cycleLED(led15,timeDelay)
|
||||||
|
cycleLED(led16,timeDelay)
|
||||||
|
cycleLED(led15,timeDelay)
|
||||||
|
|
||||||
|
# time.sleep(1) #wait for one second
|
||||||
|
|
||||||
44
Lab08/MicroPython/Code/blink_external_cycle3.py
Normal file
44
Lab08/MicroPython/Code/blink_external_cycle3.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||||
|
|
||||||
|
ledList = ['LED', 'GP15', 'GP16']
|
||||||
|
ledPinList = [
|
||||||
|
machine.Pin('LED', machine.Pin.OUT), #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP15
|
||||||
|
machine.Pin('GP15', machine.Pin.OUT), #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
# Configure GP16
|
||||||
|
machine.Pin('GP16', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
]
|
||||||
|
|
||||||
|
def cycleLED(ledID,timeDelay):
|
||||||
|
ledID.value(True)
|
||||||
|
time.sleep(timeDelay)
|
||||||
|
ledID.value(False)
|
||||||
|
time.sleep(timeDelay)
|
||||||
|
|
||||||
|
def turnOffLED(ledID):
|
||||||
|
ledID.value(False)
|
||||||
|
|
||||||
|
print("Turn off all LED's")
|
||||||
|
#turnOffLED(led)
|
||||||
|
#turnOffLED(led15)
|
||||||
|
#turnOffLED(led16)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
42
Lab08/MicroPython/Code/blink_external_cycle4.py
Normal file
42
Lab08/MicroPython/Code/blink_external_cycle4.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||||
|
|
||||||
|
# These are the Pin names.
|
||||||
|
ledList = ['LED', 'GP15', 'GP16']
|
||||||
|
|
||||||
|
# Internal LED, GP15, GP16 as Pin Objects
|
||||||
|
ledPinList = [ machine.Pin('LED', machine.Pin.OUT), machine.Pin('GP15', machine.Pin.OUT), machine.Pin('GP16', machine.Pin.OUT) ]
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
18
Lab08/MicroPython/Code/blink_internal.py
Normal file
18
Lab08/MicroPython/Code/blink_internal.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Micropython version of the blink program
|
||||||
|
|
||||||
|
import machine
|
||||||
|
import time
|
||||||
|
|
||||||
|
print("\nMicroPython example code")
|
||||||
|
print("Blink the onboard LED\n")
|
||||||
|
|
||||||
|
led = machine.Pin('LED', machine.Pin.OUT) #configure LED Pin as an output pin and create and led object for Pin class
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("On")
|
||||||
|
led.value(True) #turn on the LED
|
||||||
|
time.sleep(1) #wait for one second
|
||||||
|
print("Off")
|
||||||
|
led.value(False) #turn off the LED
|
||||||
|
time.sleep(1) #wait for one second
|
||||||
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
Run Code on Power Up
|
||||||
|
(From Google AI)
|
||||||
|
|
||||||
|
To run a MicroPython script automatically on power-up, you must
|
||||||
|
save your code to the device's filesystem with the specific filename main.py. The board's bootloader is programmed to look for this file and execute its contents after finishing its initial setup process.
|
||||||
|
|
||||||
|
Steps to Save and Run Code on Power-up
|
||||||
|
The general process involves connecting your board to a computer, accessing its file system, and saving your script with the required name.
|
||||||
|
|
||||||
|
Connect your board: Plug your MicroPython board (like a Raspberry Pi Pico or ESP32) into your computer via USB.
|
||||||
|
|
||||||
|
Open your IDE/Editor: Use a MicroPython-compatible IDE like Thonny to connect to the board's serial port.
|
||||||
|
|
||||||
|
Save your file as main.py:
|
||||||
|
In Thonny, write your code in the editor window.
|
||||||
|
Go to File > Save as.
|
||||||
|
Select the option to save the file to the "Raspberry Pi Pico"
|
||||||
|
(or your specific board's name) instead of your computer.
|
||||||
|
Name the file main.py and click OK or Save.
|
||||||
|
|
||||||
|
Power cycle the board: Eject or unmount the device safely from your computer's file system, and then unplug and re-plug the USB cable (or press the RST button if available).
|
||||||
|
|
||||||
|
Upon reconnection, the code within main.py will run automatically.
|
||||||
|
|
||||||
|
Advanced Boot Options
|
||||||
|
MicroPython actually uses two special files during the boot process:
|
||||||
|
|
||||||
|
boot.py: This file runs first and is intended for low-level configuration, such as setting up the system path or network connections. You typically do not need to modify this file unless you are customizing the boot process itself.
|
||||||
|
|
||||||
|
main.py: This file runs after boot.py and should contain your primary application logic.
|
||||||
|
|
||||||
|
By correctly naming your script main.py, you ensure it behaves like an embedded system program, running immediately when power is applied, without needing a computer connection or manual command.
|
||||||
BIN
Lab08/MicroPython/MicroPython/RPI_PICO_W-20251209-v1.27.0.uf2
Normal file
BIN
Lab08/MicroPython/MicroPython/RPI_PICO_W-20251209-v1.27.0.uf2
Normal file
Binary file not shown.
10
Lab08/MicroPython/README.md
Normal file
10
Lab08/MicroPython/README.md
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# MicroPython Files
|
||||||
|
|
||||||
|
---
|
||||||
|
Directories & Files
|
||||||
|
---
|
||||||
|
MicroPython: MicroPython firmware for the Pico 2 W
|
||||||
|
|
||||||
|
Code: MicroPython code for the lab.
|
||||||
|
|
||||||
|
Documentation: Any additional documentation files.
|
||||||
16
Lab08/README.md
Normal file
16
Lab08/README.md
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Lab08
|
||||||
|
Introduction to the Pico W.
|
||||||
|
|
||||||
|
Pico W introduction. Using Thonny, connecting to the Pico W, using MicroPython and CircuitPython.
|
||||||
|
---
|
||||||
|
Directories & Files
|
||||||
|
---
|
||||||
|
|
||||||
|
CircuitPython: CircuitPython code and documentation. It includes the CircuitPython Version 9.2.4 Pico W firmware.
|
||||||
|
|
||||||
|
MicroPython: MicroPython code and documentation. It includes the MicroPython Version 1.27.0 Pico W firmware.
|
||||||
|
|
||||||
|
flash_nuke.uf2: Erases all existing firmware on the Pico W.
|
||||||
|
|
||||||
|
Documentation: Pin diagrams, web links, and other information.
|
||||||
|
|
||||||
BIN
Lab08/flash_nuke.uf2
Normal file
BIN
Lab08/flash_nuke.uf2
Normal file
Binary file not shown.
15
README.md
15
README.md
|
|
@ -1,2 +1,15 @@
|
||||||
# 2026IoTPicowWorking
|
# 2026 IoT Pico W Lab Files
|
||||||
|
Lab files for the 2026SP IoT Networking and Security labs.
|
||||||
|
|
||||||
|
Main Directory: 2026IoTPicowLab
|
||||||
|
|
||||||
|
---
|
||||||
|
Lab Directories
|
||||||
|
---
|
||||||
|
Lab08: Pico W introduction. Using Thonny, connecting to the Pico W, using MicroPython and CircuitPython.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue