The objective of this module is to set up your microcontroller and computer so you can write, run, and view the output of CircuitPython code using Visual Studio Code.
For the following tutorials, we will be using the Metro M0 Express board with CircuitPython. You will also need a micro USB cable (with data transfer) to connect the board to a computer.
Connect the Metro M0 Express board to your computer with the micro-USB data cable.
Look at your computer's file explorer. If a USB drive called CIRCUITPY appears, CircuitPython is already installed. You can skip directly to Step 3 below.
If a drive called METROBOOT appears, OR if nothing happens at all (your computer does not recognize any device), do not worry. This is completely normal for a fresh board. Proceed to Step 2.
If your board is unrecognized or running older firmware, you must install CircuitPython to proceed. Continue with the steps below.
Download the Firmware: Download the latest CircuitPython .uf2 file for the Metro M0 Express here: https://learn.adafruit.com/adafruit-metro-m0-express-designed-for-circuitpython/circuitpython
Important: Note the major version number you are downloading (e.g., CircuitPython 9.x.x). You will need this exact number in Step 3 to download the matching library bundle.
Enter Bootloader Mode: If your computer did not recognize the board in Step 1, find the small reset button on the board and double-tap it. The board's indicator light will flash red, then turn green. This action forces the computer to recognize the hardware.
Mount the Boot Drive: A new drive called METROBOOT should now appear on your computer.
Flash the Board: Drag and drop the downloaded .uf2 file onto the METROBOOT drive.
Verify: The METROBOOT drive will disappear, and a new drive named CIRCUITPY will mount in its place. Your installation is complete.
Troubleshooting: If you are having trouble getting the drive to appear, review the Adafruit Troubleshooting Guide.
Note: For a detailed guide see Adafruit Installing CircuitPython
Download the latest CircuitPython Library Bundle that matches your version of CircuitPython.
Download: https://circuitpython.org/libraries
Note: The library bundle includes all the current libraries available for CircuitPython and some example files. Since we will not being using all of the libraries, we do not need to copy all of them onto the board (see the next step).
Find and copy only the simpleio and adafruit_motor libraries to your board:
If you don't already have a lib folder on your board, create a new folder called lib on the CIRCUITPY Drive.
Unzip the CircuitPython Library Bundle and find the simpleio and adafruit_motor libraries. Copy these files to the lib folder on the CIRCUITPY Drive.
Learn more about using libraries here.
Note: The only libraries we will be using in these tutorials are simpleio and adafruit_motor. If you need more libraries in future projects, you can find the libraries you need from the library bundle and copy them to your board.
Navigate to this link to download the latest version of Visual Studio Code compatible with your machine.
The specifics of Visual Studio Code: check this out, as well as this.
Open Visual Studio Code and navigate to the "Extensions" tab (the squares icon on the left sidebar). Search for and install the "CircuitPython" extension.
Link to it: https://marketplace.visualstudio.com/items?itemName=joedevivo.vscode-circuitpython
Important Note: Due to a bug in the latest release of this extension, you must manually install a specific older version for it to function correctly. Once installed, click the caret on the Uninstall button to open the dropdown menu, select Install Specific Version... from the dropdown, choose version 0.1.20 from the list, and Restart Extension in VS Code when prompted, see images below.
Plug your CircuitPython board with your assembled circuit in to your machine.
From the main page of VS Code, open up the CircuitPython Drive. The image below shows where to find this.
Important: Make sure to open the entire CIRCUITPY (D:) drive.
There are usually a few other extensions or dependencies that might be required depending on your existing VS Code profile. These should automatically download once you open the main.py or code.py file.
Ensure that VS Code is configured for your specific board.
Open the Command Palette by navigating to View > Command Palette (or pressing Ctrl+Shift+P / Cmd+Shift+P).
Type CircuitPython: Choose CircuitPython Board and select it.
Scroll and choose your specific board (e.g., Metro M0 Express) from the list of available boards.
You can access serial output and several other CircuitPython commands through the Command Palette. To access this, press View > Command Palette. A text bar should drop down from the top of the screen. Type in CircuitPython to see the full list of commands you can use. Select CircuitPython: Open Serial Monitor to view the output from your board.