Skip to content

Instantly share code, notes, and snippets.

Last active August 3, 2023 22:13
Show Gist options
  • Save monkeymademe/8ce6014c00be908e7c0dba9a48e97af6 to your computer and use it in GitHub Desktop.
Save monkeymademe/8ce6014c00be908e7c0dba9a48e97af6 to your computer and use it in GitHub Desktop.
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")
# 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
Copy link

monkeymademe commented Jul 4, 2023

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 pathtofile.u2f -d F:'

  • Path to file is the location of the u2f file and -d is an optional argument for the drive letter (default is D:)

Steps to use:

  1. Run the command in command line and it will say its waiting for the pico
  2. Take the pico and press and hold the 'BOOTSEL' button
  3. Plug in the pico to the computer with your USB cable
  4. Wait for the message 'Firmware installed - Rebooting Pico'
  5. Remove the pico
  6. Select the next pico and go back to step 2
  7. To exit the script press 'Ctrl+C'

Copy link

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