Disable Storage on a Raspberry Pi Pico

2023-12-03 · christian · embedded, python

When using a Raspberry Pi Pico as a USB Mouse or Keyboard, you may want to disable CircuitPythons flash drive and the REPL serial console.

Just put the following into the boot.py:

import storage
import usb_cdc
import usb_midi

storage.disable_usb_drive()
usb_cdc.disable()
usb_midi.disable()

The actual logic of your program should be put into the code.py and will be launched after boot.py has completed.

It is also possible to add a physical button to skip disabling the Flash Drive. The following example will not disable it, when the button is hold while resetting the Pico:

import board
import storage
import usb_cdc
import usb_midi
from digitalio import DigitalInOut, Direction, Pull

btn = DigitalInOut(board.GP13)
btn.direction = Direction.INPUT
btn.pull = Pull.DOWN

if not btn.value:
    storage.disable_usb_drive()
    usb_cdc.disable()
    usb_midi.disable()

Pico Jiggler


More


serverless.industries BG by Carl Lender (CC BY 2.0) Imprint & Privacy
9d41264a 2023-12-28 19:26
Mastodon via chaos.social Mastodon via einbeck.social