Last active
August 3, 2023 22:13
-
-
Save monkeymademe/8ce6014c00be908e7c0dba9a48e97af6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import shutil | |
import argparse | |
# Create the argument parser | |
parser = argparse.ArgumentParser(description='Pico Firmware Flasher') | |
parser.add_argument('uf2_file_path', metavar='UF2_FILE', type=str, help='Path to the UF2 file') | |
parser.add_argument('-d', '--drive_letter', type=str, default='D:', help='Drive letter of the Pico (default: D:)') | |
# Parse the command-line arguments | |
args = parser.parse_args() | |
# Set the UF2 file path and drive letter | |
uf2_file_path = args.uf2_file_path | |
drive_letter = args.drive_letter | |
# Print the initial message | |
print("Press Ctrl+C to exit - Warning: Exiting while flashing a Pico could damage the Pico.") | |
# Loop indefinitely | |
while True: | |
# Check if the Pico drive is available | |
if os.path.exists(drive_letter): | |
print("Pico detected - Attempting to write firmware") | |
try: | |
# Copy the UF2 file to the Pico drive | |
shutil.copy2(uf2_file_path, drive_letter) | |
# Print a message indicating that the firmware has been installed | |
print("Firmware installed - Rebooting Pico") | |
except PermissionError: | |
print("Permission Error: Unable to copy firmware to the Pico. Please reconnect the Pico and try again.") | |
except FileNotFoundError: | |
print("Error: UF2 file not found. Please check the file location.") | |
# Wait for 5 seconds before checking again | |
time.sleep(5) |
Fixed a typo (time.sleep(5'') line 37 should not have the apostrophes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windows counterpart for the pico autoflash script for mac.
Essentially functions the same way just that the script is much simpler.
The script is run in command line like this 'python pico-autoflash-windows.py pathtofile.u2f -d F:'
Steps to use: