Examples

  1. Create a new folder for your source code, e.g. in ~/Documents/test and change into that directory:

    mkdir ~/Documents/test
    cd ~/Documents/test
    
  2. In an editor, create a new file named code.py in the above folder with the following contents:

    from time import sleep
    
    i = 0
    while True:
        print(f"hello world: {i}")
        sleep(1)
        i += 1
    
  3. Enable shell completion to make the subsequent commands easier:

    eval $(circuitpython-tool completion)
    
  4. List connected CircuitPython devices to figure out the device naming:

    circuitpython-tool devices
    

    The connected device has a model value of Pico_W. To refer to this device in subsequent commands, we can use the device syntax of :Pico:. Alternatively, if you only have one device connected to your computer, you can just use the wildcard :: value.

  5. Use circuitpython-tool to upload code:

    circuitpython-tool upload :Pico: --mode=watch
    

    The :Pico: argument refers to the Raspberry Pi Pico W we found using. the circuitpython devices command. The --mode=watch option keeps the program continuously running and waiting for file changes. You can exit it at any time using Control-C

  6. Open a new terminal window and connect to your device’s serial terminal:

    circuitpython-tool connect :Pico: