Get Started with the Notecard and Cellular IoT on June 8th !

Blues Developers
Search
Documentation Results
End of results
Community Results
End of results
What’s New
Blues.io
Notehub.io
Shop
Sign In
What’s New
Blues.io
Notehub.io
Shop
×
HomeSwan
Introduction to Swan
Swan QuickstartSwan Datasheet
Using STM32CubeIDE with Swan
Using Arduino IDE with Swan
Using CircuitPython with Swan
Recovering the STM32L4R5

Using CircuitPython with Swan

CircuitPython is an open-source derivative of the MicroPython programming language and is primarily supported by Adafruit .

Prerequisites

  1. Download the latest version of the Swan's UF2 bootloader from the adafruit/tinyuf2 repository releases page . Expand the full list of assets under the current release and search for "swan" to find the appropriate file.

    Swan bootloader location

  2. Download the latest version of CircuitPython from Adafruit's CircuitPython page for Swan . (You only need the .uf2 file.)

    Swan CircuitPython location

  3. If you haven't already, install the device firmware upgrade utility: dfu-util .

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

  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.

    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 and Thonny are great for programming CircuitPython on the Swan. Likewise, VS Code with the CircuitPython extension 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.

    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!

Can we improve this page? Send us feedback
© 2023 Blues Inc.Terms & ConditionsPrivacy
blues.ioTwitterLinkedInGitHubHackster.io
Disconnected
Notecard Disconnected
Having trouble connecting?

Try changing your Micro USB cable as some cables do not support transferring data. If that does not solve your problem, contact us at support@blues.com and we will get you set up with another tool to communicate with the Notecard.

Advanced Usage

The help command gives more info.

Connect a Notecard
Use USB to connect and start issuing requests from the browser.
Try Notecard Simulator
Experiment with Notecard's latest firmware on a Simulator assigned to your free Notehub account.

Don't have an account? Sign up