Main Menu

search

You are here

rPi Pico

[last updated: 2026-01-13]
raspberry Pi home page
--------------------------------------------------------------



      On This Page:
  • General description:
  • Programming setup:
      micropython
      thonny
  • i2c
  • alternate import syntax
  • UART
  • reading and writing files to memory
  • resetting Flash memory
  • RTC
  • Links
  • random snippets


---------------------------------------------------------

  • [pinout pix]
  • 4 board options in Pico-1 family:
    Pico
    Pico-H
    Pico-W
    Pico-WH
  • Pico Features:
      RP2040 MCU
      dual-core M0+ up to 133 MHz
      264 KB SRAM
      2 MB flash
      26 × multi-function GPIO pins
      2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM channels
      Temperature sensor
      Accelerated floating-point libraries on-chip
      8 × Programmable I/O (PIO) state machines for custom peripheral support

      GPIO's provide max 0.012A = 12mA current

    • onboard green LED on GPIO25
    • VSYS: board can be powered by 1.8-5.5v into the VSYS pin
    • 3v3_EN: enable pin for 3.3v regulator; normally pulled-high internally,
      connect to ground to disable the regulator (and the whole board)
    • 3v3(OUT): powers external 3.3 peripherals up to max 300ma
    • VBUS:provides 5v out for peripherals, up to 2a,
      ONLY when the Pico is being powered via the USBC input connector.

    --------------------------------------------------------------

  • Programming:
    rPi Pico can be programmed in C++ or MicroPython
      Thonny is an IDE/editor for MicroPython programs
      Install Thonny:
      go to Thonny.org to download, or install from Software Manager if on a Linux PC.

  • install micropython on the Pico:
    With no power applied to the Pico,
    press and hold the BOOTSEL button on the board,
    then apply power with USB from your PC.
      a new removable drive should show up on your PC, "RP1-RP2"

    Release the BOOTSEL button.
    Navigate to this drive and find the file: Index.htm.
    Double-click to open, and follow prompts to "download UF2 file" for your specific board.
    This file will usually be downloaded into the downloads folder of your PC.
    Drag the uf2 file and drop it into the RP1-RP2 folder.
    The removable drive RP1-RP2 will then close automatically.
    MicroPython will now be loaded/installed onto your Pico.

  • Verify Installation:
    This will verify correct installation of micropython onto your Pico,
    as well as installation of the Thonny editor on your PC,
    as well as the basic functioning of the Pico board itself.
    • Set up Thonny:
      With the Pico connected to your PC via USB,
      Open Thonny.
        How you do this will vary by how/where you installed it, and what OS you're using.
        On my Linux PC, I do: Start Menu -> Programming -> Thonny

      In Thonny top menu bar: Run -> configure interpreter -> MicroPython (raspberry pi pico) -> detect port automatically -> OK
      Click "re-start back-end process" button ("stop" sign icon) on toolbar.
      Version and other info should show up at the bottom of the screen.

    • Using Thonny:
      • When you open Thonny, the screen layout will be whatever you had the last time you used it.
        As a minimum, you may only have one area, ie. the whole screen will just be one area (other than the top menu and tool bars).
        It will not be labeled exactly, but it will have a tab at the top to identify it, and initially the tab will just say "<untitled>".
        This is your script or program space.
      • If your "Shell" area is not displayed at the bottom of your screen, you should make it visible.
        This is the area where error messages will be shown, so it's really essential for program development.
        In the top menu bar: View -> Shell
      • The first thing you should notice is the lines printed in the Shell area that report the version of your MicroPython
        and the model and CPU of your MCU (Pico)

      • Thonny is an IDE/editor for python commands.
        If you type python commands in the Shell area at the bottom, and press Enter, they will be immediately executed.
          This can be handy if testing a command syntax and function.

        If you type python commands in the script/program area at the top, and press Enter, no execution happens,
        the cursor just moves to the next line, waiting for you to type in another line of code.
        But if you click "Run current script" (green right-arrow icon at the top, or also on the top menu bar item 'Run')
        then whatever commands you've typed will likewise be immediately executed.

      • If you want to save a script that you've written into the Script/program area, and save it to a program that you can retrieve and run later,
        then click File -> Save As
        then you'll be given a prompt with two options:
          save program to this computer (ie. your PC)
          -or- save program to Pico

        After you make your choice, a folder/directory structure will be opened for you to navigate to your desired location,
        and a text field opens for you to enter your choice of program name.
        If it's a python program, be sure to include the ".py" extension to your filename.

      • If you want to edit or run a program that you've saved,
        in Thonny: File -> Open
        select PC or Pico
        navigate to folder and file desired, and double-click to open.

    • First test programs:
      • Printing to the screen:
      • blinking the onboard LED:

      --------------------------------------------------------------

    • Micro-Python: - misc/random programming instructions...
      • import machine
        eg: LEDpin = machine.Pin(16, Pin.OUT)
        then: LEDpin.value(1)
        or: LEDpin.value(0)
      • import utime
        utime.sleep(1) ... seconds

      --------------------------------------------------------------

    • i2c on the Pico:

      --------------------------------------------------------------

    • Note on alternative ways to import a library, and correct command syntax for each:
      • 2 alternative ways to import a library:
        • if you import this way: import ssd1306
          then you would do:
          i2c = machine.I2C(0, scl=machine.Pin(1), sda=machine.Pin(0), freq=400000)
        • if instead you import with: from ssd1306 import SSD1306_I2C
          then you would do:
          i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=40000)

    --------------------------------------------------------------

  • Using UART:
    • Connect the GND pin on the Pico to the GND pin on the other device.
      Connect the Pico's RX pin to the other device's TX pin.
      Connect the Pico's TX pin to the other device's RX pin for two-way communication.
      Crucial: The voltage levels must match (Pico uses 3.3V logic; do not connect directly to 5V devices without a logic level shifter).
      Default Pins: UART0 uses GPIO 0 (TX) and GPIO 1 (RX) by default.
      UART1 uses GPIO 4 (TX) and GPIO 5 (RX).
    • python code:
        from machine import UART, Pin
        import time
        # Initialize UART0 (default pins: GP0 for TX, GP1 for RX)
        # Set baud rate to match the transmitting device
        uart0 = UART(0, baudrate=115200, bits=8, parity=None, stop=1, tx=Pin(0), rx=Pin(1))
        while True:
              if uart0.any(): # Check if any data is waiting in the buffer
                    received_data = uart0.readline() # Read the line (adjust as needed for your data format)
                    if received_data:
                          try:
                                decoded_data = received_data.decode('utf-8').strip() # Decode bytes to string
                                print("Received via UART:", decoded_data)
                          except ValueError:
                                print("Received non-UTF-8 data")
              time.sleep(0.1)

      Explanation: The code initializes a UART object, then enters a loop to check for incoming data using uart0.any(). If data is present, uart0.readline() reads it (which is a blocking call until a newline character or timeout), and decode() converts the bytes into a readable string.

      Key Considerations

      Baud Rate: Ensure the Pico's baud rate configuration matches the sending device exactly.
      Voltage Levels: The Pico operates on 3.3V logic. Connecting directly to 5V serial devices will damage the Pico.
      Thonny IDE: When using the USB method, ensure Thonny's built-in serial monitor is closed if you want another program (like PuTTY or a custom Python script using pyserial on a different computer) to access the port.
      --------------------------------------------------------------

    • Reading and writing to memory:

      --------------------------------------------------------------

    • Resetting Flash memory:
      For Pico-series devices, BOOTSEL mode lives in read-only memory inside the RP2040 or RP2350 chip, and can’t be overwritten accidentally.
      No matter what, if you hold down the BOOTSEL button when you plug in your Pico, it will appear as a drive onto which you can drag a new UF2 file.
      There is no way to brick the board through software.
      However, there are some circumstances where you might want to make sure your flash memory is empty.
      You can do this by dragging and dropping a special UF2 binary onto your Pico when it is in mass storage mode.
      To download the special uf2 file, see: https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html
      --------------------------------------------------------------

    • The Pico (RP2040 chip) has an internal Real-Time Clock (RTC), but does not have a built-in battery backup,
      so it resets on power loss.
      You can add an external battery with an expansion module (like a DS3231) for persistent timekeeping.
      But AFAIK there is no way to add a backup battery for the internal RTC, because the Pico itself does not have a dedicated backup battery pin.
      --------------------------------------------------------------

    • Links:

      --------------------------------------------------------------

    • Random/Unorganized Snippets...


    .

    .
    eof