PyCharm is a Python editor. With the MicroPython Tools plugin it connects to the Phyduino Pico over USB, runs your script on the board and shows what it prints. Before you start, load the firmware onto the board (Setting up the Phyduino Pico) and install Python 3.10 or later.

1. Install PyCharm

  • Download PyCharm from the JetBrains download page and install it.
  • The free version is all you need. The plugin needs PyCharm 2024.3 or newer.

2. Install the MicroPython Tools plugin

  • Open the settings: File → Settings (on macOS, PyCharm → Settings).
  • Go to Plugins → Marketplace, search for MicroPython Tools and click Install.
  • Restart PyCharm if it asks you to.
PyCharm Settings, Plugins page, with MicroPython Tools by Lukas Kremla selected in the plugin list and its details on the right
MicroPython Tools by Lukas Kremla in Settings → Plugins, shown here on the Installed tab once it is installed. It is marked Freemium: everything in this tutorial uses the free features.

3. Make a project for the board

  • Create a new project, or open the folder that holds your scripts.
  • Open the settings again and go to Languages & Frameworks → MicroPython Tools.
  • Tick Enable MicroPython support.
  • Under Connection, set Type to Serial. Set Port to Auto-Detect Port, or pick the board's port from the list (on Windows a COM port).
  • Under MicroPython Type Hints, tick Enable MicroPython type hints, then install and select micropython-rp2-stubs version 1.29.0, which matches the firmware. Type hints let PyCharm complete MicroPython names such as machine.Pin as you type. Installing them needs an internet connection.
  • Click Apply.
PyCharm Settings, Languages and Frameworks, MicroPython Tools page: Enable MicroPython support ticked, connection type Serial on port COM24, and micropython-rp2-stubs 1.29.0 selected under MicroPython Type Hints
Languages & Frameworks → MicroPython Tools with MicroPython support enabled, a Serial connection on the board's port, and micropython-rp2-stubs 1.29.0 selected (green) under MicroPython Type Hints.

4. Connect to the board

  • Plug the board in with a USB cable.
  • Open the MicroPython Tools tool window from its icon on the left-hand tool bar. It has a File System tab and a REPL tab.
  • Click the connect button (the plug icon) at the top left of the tool window. The board's port is shown next to it.
    The MicroPython Tools tool window at the bottom of PyCharm, File System tab open, with a red arrow pointing to the connect button next to the COM24 port list
    The MicroPython Tools tool window. The arrow points to the connect button; once connected, the File System tab shows the board's files and free space.
  • Only one program can use the board's port at a time. If PyCharm can't connect, close any mpremote repl left open in a terminal.
  • Auto-Detect needs exactly one MicroPython board plugged in. With more than one, pick the board's port from the list instead.

Linux: if the board isn't found, your account may need permission to use serial ports. See the Linux note in Setting up the Phyduino Pico.

5. Run a script

  • Create a file called main.py in the project and paste in this script, which blinks the on-board green LED:
    # Blinks the on-board green LED once a second.
    
    import time  # sleep() for pauses
    
    import phyduino as mcu  # the Phyduino Pico library, used as mcu.<name>
    
    mcu.led.off()  # start with the LED off
    
    while True:  # repeats until stopped: Interrupt in PyCharm, or mpremote soft-reset
        mcu.led.toggle()  # on if it was off, off if it was on
        time.sleep(0.5)  # wait half a second, so one on-off cycle takes a second
  • Right-click main.py in the project tree and choose Execute File in REPL. The green LED starts blinking.
    PyCharm with main.py selected in the project tree and its right-click menu open, Execute File in REPL highlighted near the bottom, just above Upload to MicroPython Device
    Execute File in REPL near the bottom of the right-click menu for main.py. Upload to MicroPython Device, just below it, is used in step 6.
  • Press Interrupt in the REPL tab to stop it.
    The REPL tab of the MicroPython Tools tool window, with the mouse on the square Interrupt button in its toolbar and KeyboardInterrupt shown below
    The Interrupt button (the square) in the REPL tab's toolbar. The REPL then shows KeyboardInterrupt and the script has stopped.

PyCharm's Stop button and disconnecting both leave the script running on the board. Connecting again stops it.

6. Run it every time the board starts

Execute File in REPL runs the script without saving it on the board. To have it run on its own:

  • Right-click main.py in the project tree and choose Upload to MicroPython Device, or drag it onto the File System tab of the tool window.
    PyCharm with main.py selected in the project tree and its right-click menu open, Upload to MicroPython Device highlighted at the bottom
    Upload to MicroPython Device in the right-click menu for main.py. Once uploaded, main.py appears in the File System tab.
  • Press the reset button (SW2). The board runs main.py each time it starts, even when it isn't connected to a computer.
  • To stop that, delete main.py from the File System tab (right-click it).

If something doesn't work

  • If the board won't run a file, press Hard reset in the REPL tab, or the reset button (SW2) on the board.
  • If the board has an old phyduino.py in its File System tab, delete it. It takes priority over the one built into the firmware.