MicroPython

Thonny IDE Setup

Thonny is the recommended IDE for MicroPython development. It's beginner-friendly, cross-platform, and includes everything you need: a code editor, REPL shell, and file manager for your microcontroller.


Install Thonny

Windows

  1. Download the installer from thonny.org
  2. Run the .exe installer — accept defaults and install for all users
  3. Launch Thonny from the Start Menu

Ubuntu / Linux

shell
# Option 1: From the official Ubuntu/Debian package
sudo apt install -y thonny

# Option 2: Latest version via pip
pip install thonny
thonny &

macOS

shell
# Via Homebrew (recommended)
brew install --cask thonny

# Or download the .dmg from thonny.org

Step 1 — Connect Your Board

Plug your ESP32 or Raspberry Pi Pico via USB.


Step 2 — Configure the Interpreter

This is the most important step — Thonny needs to know which board you're using.

  1. Go to Tools → Options → Interpreter (or Run → Configure interpreter)
  2. In the "Which kind of interpreter should Thonny use..." dropdown, select:
BoardSelect
Raspberry Pi PicoMicroPython (Raspberry Pi Pico)
ESP32MicroPython (ESP32)
Generic boardMicroPython (generic)
  1. For Port, select:

    • Windows: COMx (e.g., COM3)
    • Ubuntu: /dev/ttyUSB0 or /dev/ttyACM0
    • macOS: /dev/cu.usbserial-* or /dev/cu.SLAB_USBtoUART
  2. Leave baudrate at 115200

  3. Click OK


Step 3 — Connect and Verify

Click the Stop/Restart button (red stop icon) in the toolbar. The Shell panel at the bottom should show:

For Pico:

text
MicroPython v1.xx.x on 2025-xx-xx; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>>

For ESP32:

text
MicroPython v1.xx.x on 2025-xx-xx; ESP32 module
Type "help()" for more information.
>>>

If you see this prompt, you're connected. 🎉


Step 4 — Test with REPL

Click in the Shell panel and type:

python
1>>> print("Hello from Analog Data!")
2Hello from Analog Data!
3
4>>> 2 + 2
54
6
7>>> from machine import Pin
8>>> led = Pin(2, Pin.OUT) # GPIO 2 (adjust for your board)
9>>> led.on()
10>>> led.off()

The LED on your board should turn on and off in response.


Step 5 — Write and Run a Script

In the top editor area, write:

python
1from machine import Pin
2import time
3
4led = Pin(2, Pin.OUT) # Adjust GPIO number for your board
5
6for i in range(10):
7 print(f"Blink {i+1}")
8 led.toggle()
9 time.sleep(0.5)
10
11print("Done blinking!")
12led.off()

Press F5 (Run) or click the green Run button.

The code runs immediately on your board, and output appears in the Shell.


Step 6 — Save Code to the Board

To make your code run automatically when the board powers on:

  1. Go to File → Save As
  2. A popup asks: "Where to save to?"
    • Click "Raspberry Pi Pico" or "MicroPython device"
  3. Save as main.py

Now unplug and replug the board — your code runs automatically!


Step 7 — Manage Files on the Board

Go to View → Files to open the file panel.

The panel is split:

  • Left side: Your computer's files
  • Right side: Files on the microcontroller

You can:

  • Drag files from computer to board (upload)
  • Drag files from board to computer (download)
  • Right-click → Delete files from the board
  • Create folders on the board

Step 8 — Install MicroPython Packages

Thonny has a built-in package manager for MicroPython (similar to pip):

  1. Go to Tools → Manage packages...
  2. Search for a package (e.g., ssd1306 for OLED displays)
  3. Click Install

Alternatively, use mip from the REPL:

python
1>>> import mip
2>>> mip.install("urequests") # Install HTTP requests library

Thonny Tips and Shortcuts

ActionShortcut
Run current scriptF5
Stop runningCtrl+C (in shell) or Stop button
Save to boardCtrl+Shift+S
Open file from boardCtrl+O
Clear shellCtrl+L
Interrupt running codeClick Stop/Restart (red button)

Troubleshooting

"Could not connect to the device" or no REPL prompt

  • Make sure the board is plugged in and you selected the correct port
  • Try pressing the Stop/Restart button
  • Check that no other program (Arduino Serial Monitor, etc.) has the port open
  • On Ubuntu: verify you're in the dialout group: groups | grep dialout

Thonny shows wrong Python version (not MicroPython)

Go to Tools → Options → Interpreter and re-select the MicroPython interpreter for your board.

"Permission denied" on port (Ubuntu)

shell
sudo chmod 666 /dev/ttyUSB0
# Or permanently:
sudo usermod -aG dialout $USER
# Log out and back in

Next Steps

Previous
Introduction