[last updated: 2026-01-13]
raspberry Pi home page
--------------------------------------------------------------
On This Page:
- General description:
- Programming setup:
- 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:
--------------------------------------------------------------
- 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:
- Available i2c channels:
- The Pico has two i2c channels available:
I2C0 and I2C1
Each channel has several pairs of sda/scl pin combinations available
- I2C0 can be defined using any ONE of these sda/scl pair options:
GP0/GP1, GP4/GP5, GP8/GP9, GP12/GP13, GP16/GP17, GP20/GP21
Note these are "GP" numbers, NOT physical board pin numbers.
and note that the "pin" numbers given are GP numbers, not board numbers.
that is, for SCL0, GP# is 1, but board# is pin 2
so you would use: ... scl=machine.Pin(1)
See the pinout diagram.
- But I2C0 can only use ONE of the available sda/scl pairs. Same goes for I2C1.
So in net, you only have TWO i2c channels available, even though glancing at the pinout might confuse you into thinking there were many more.
In fact there are 6 sda/scl pin-pair options that you could use to define a given i2c channel, but you can only use one of the 6 for each channel,
and in total you can only have two i2c channels defined.
- i2c Libraries:
https://awesome-micropython.com/
i2c is a communication protocol for communication between your Pico and a peripheral, that being, in this initial case, an OLED display.
- which library to use:
The library/driver must be specific to your peripheral. There are several drivers available for different models/mfrs of OLEDs,
the common ones being: sh1106.py, ssd1306.py, and ssd1309.py.
So the process is, research data sheets and other info, and decide which driver you need to use for your chosen peripheral.
- getting the library:
- uploading to the pico:
- connect USB cable between PC and Pico
- Open Thonny
top menu bar: View -> Files
A bar will open on the left. The top section is your host PC directory structure, the lower section is the rPi pico
- Navigate to the file on your PC that you want to upload to the pico,
(be sure the lower section, the directory of your Pico, is showing the root directory)
left-click to select it, right-click it to bring up the context menu, select "upload to/" and it will be copied to the pico.
You should see it show up as a listing in the lower section.
- python code to initialize and run i2c to your OLED:
- tutorial links:
https://www.youtube.com/watch?v=Ts9JXbMvfTQ
https://www.youtube.com/watch?v=vVS4gFI5gjM
https://www.youtube.com/watch?v=c1eVrc-K1HE
https://www.youtube.com/watch?v=BUYWBV2b7S0
https://www.youtube.com/watch?v=c64WG4iJuEo
https://www.youtube.com/watch?v=RXxqMGz03-U
https://www.youtube.com/watch?v=fH23Kvl_o_o
https://www.tomshardware.com/how-to/oled-display-raspberry-pi-pico
https://www.phippselectronics.com/use-an-oled-screen-with-raspberry-pi-p...
https://randomnerdtutorials.com/raspberry-pi-pico-ssd1306-oled-micropython/
https://thepihut.com/blogs/raspberry-pi-tutorials/using-ssd1315-oleds-wi...
https://github.com/mcauser/deshipu-micropython-oled
https://luma-oled.readthedocs.io/en/latest/
https://github.com/raspberrypi/pico-examples/blob/develop/i2c/ssd1306_i2...
https://madflex.de/using-oled-displays-with-micropython-and-the-pico/
https://docs.micropython.org/en/latest/esp8266/tutorial/ssd1306.html
--------------------------------------------------------------
- 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