Lab 8-Pico W Introduction

This commit is contained in:
Edward Bigos 2026-03-22 23:06:48 -04:00
commit c7ac62b6b3
26 changed files with 8387 additions and 5 deletions

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View file

@ -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.

View 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.