Created
March 25, 2024 23:05
-
-
Save PaulskPt/de21ddeee901a88745a71ddae9ff0e76 to your computer and use it in GitHub Desktop.
CircuitPython test if board connected to USB
This file contains hidden or 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
# 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