Skip to content

Instantly share code, notes, and snippets.

@PaulskPt
Created March 25, 2024 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulskPt/de21ddeee901a88745a71ddae9ff0e76 to your computer and use it in GitHub Desktop.
Save PaulskPt/de21ddeee901a88745a71ddae9ff0e76 to your computer and use it in GitHub Desktop.
CircuitPython test if board connected to USB
# SPDX-FileCopyrightText: 2024 Paulus Schulinck
#
# SPDX-License-Identifier: Unlicense
# Tested on board: Adafruit MAGTAG (ID: 4800)
def is_usb():
# Test if we're connected to USB
# If an error occurs we are on USB
ret = False
try:
from storage import remount
remount("/", False)
except RuntimeError as e:
ret = True
return ret
def main():
print(f"Are we connected to USB? {"Yes" if is_usb() else "No"}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment