---
title: Using CircuitPython with Swan
description: Learn about using Swan with CircuitPython.
source_url: https://dev.blues.io/feather-mcus/swan/using-circuitpython-with-swan/
canonical_url: https://dev.blues.io/feather-mcus/swan/using-circuitpython-with-swan/
markdown_url: https://dev.blues.io/feather-mcus/swan/using-circuitpython-with-swan.md
---

# Using CircuitPython with Swan

[CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython) is an open-source derivative of the MicroPython programming language and is primarily supported by [Adafruit](https://www.adafruit.com/).

## Prerequisites

1. Download the latest version of the Swan's UF2 bootloader from the [adafruit/tinyuf2 repository releases page](https://github.com/adafruit/tinyuf2/releases). Expand the full list of assets under the current release and search for `"swan"` to find the appropriate file.

   ![Swan bootloader location](https://dev.blues.io/images/quickstart/swan/swan-bootloader.png?v=9fdb3838)

2. Download the latest version of CircuitPython from [Adafruit's CircuitPython page for Swan](https://circuitpython.org/board/swan_r5/). (You only need the `.uf2` file.)

   ![Swan CircuitPython location](https://dev.blues.io/images/quickstart/swan/swan-circuitpython.png?v=4640d5f9)

3. If you haven't already, install the device firmware upgrade utility: [dfu-util](http://dfu-util.sourceforge.net/).

## Installation

1. Connect the Swan's Micro USB port to your computer with a USB cable.

2. Put your Swan into "boot" mode by holding down the `BOOT` button, pressing and releasing the `RESET` button, then releasing the `BOOT` button.

   ![boot and reset buttons on swan](https://dev.blues.io/images/quickstart/swan/cp-buttons.png?v=3a023601)

3. Unzip your `tiny-uf2-swan_r5-[version].zip` file. You'll need the extracted `.bin` file for the next step.

4. In a terminal window, run the following command to flash the bootloader files to your Swan. Note that you may to need to navigate directories first, and you will likely need to change the file name at the end of the command to include the appropriate version number.

   ```bash
   dfu-util -s 0x8000000:leave -a 0 -D tinyuf2-swan_r5.bin
   ```

5. In a few seconds, a new drive called `SWANBOOT` will appear.

   > **Note:**
   >
   > If you have previously installed the bootloader but don't see the `SWANBOOT` drive appear, press the `RESET` button twice (fairly quickly) to mount the drive.

6. Drag-and-drop the previously downloaded `adafruit-circuitpython-swan_r5.uf2` file onto the `SWANBOOT` drive. Your Swan will quickly reset and the `CIRCUITPY` drive will appear.

## Choosing an IDE

The beauty of working with CircuitPython on the Swan is that you interact directly with the source Python files on the `CIRCUITPY` drive. Virtually any IDE or text editor can be used to add, edit, and delete these files.

However, if you want to interact with the on-device REPL or view terminal output, you'll want to use a tool specific to CircuitPython development. Traditional Python editors such as [Mu](https://codewith.mu/) and [Thonny](https://thonny.org/) are great for programming CircuitPython on the Swan. Likewise, VS Code with the [CircuitPython extension](https://marketplace.visualstudio.com/items?itemName=joedevivo.vscode-circuitpython) is another popular option.

## Blink the Onboard LED

1. Open the `code.py` file in the `CIRCUITPY` drive using your preferred editor.

2. Paste in the following code and save the updated `code.py` file.

   ```python
   import board
   import digitalio
   import time

   led = digitalio.DigitalInOut(board.LED)
   led.direction = digitalio.Direction.OUTPUT

   while True:
       led.value = True
       time.sleep(0.5)
       led.value = False
       time.sleep(0.5)
   ```

3. Depending on your IDE or editor, you may have to reset the device to see the changes. Enjoy your blinking LED!
