Skip to content

Pi 4 / 5 · Build guide

Raspberry Pi Pico Oscilloscope with MicroPython

Build a Raspberry Pi Pico MicroPython waveform viewer with ADC sampling, an SSD1306 OLED, and optional USB serial plotting on a computer.

Raspberry Pi Pico Oscilloscope with MicroPython
Difficulty
Intermediate
Read time
6 min
Board
Pi 4 / 5
Author
Shantanu Kumar Mohanty
Published
Oct 26, 2026
Views
7

Pico ADC Capabilities and Limitations

The RP2040 has a 12-bit successive-approximation ADC running from a 48 MHz clock. The maximum sample rate is approximately 500 kSPS (500,000 samples per second), giving a Nyquist bandwidth of 250 kHz. In practice, MicroPython overhead limits free-running sampling to around 100 kSPS — enough for audio frequencies, power supply ripple, and slow sensor signals.

For higher speeds, the RP2040's DMA controller can be driven from C/C++ to hit the full 500 kSPS, but for most educational and hobbyist uses MicroPython is sufficient and far easier to modify.

🚨 Danger

The Pico's ADC inputs accept 0–3.3V maximum. Signals above 3.3V will permanently damage the RP2040. Always use a voltage divider or clamping diodes when probing unknown signals. Never connect directly to mains voltage.

Components

6 items
NameQtyLink
Raspberry Pi Pico (RP2040)×1Buy ↗
0.96" I2C OLED (SSD1306, 128×64)×1Buy ↗
1 MΩ Resistor (probe input protection)×1—
10 nF Capacitor (anti-aliasing filter)×1—
Mini breadboard + Jumper Wires×1—
Micro-USB Cable (data, not charge-only)×1—

Need these parts? Get this build sheet by email

Parts list with buy links, plus new builds as they're published. By subscribing you agree to our Privacy Policy. Unsubscribe anytime.

main.py
# ── Raspberry Pi Pico — MicroPython Oscilloscope ─────────────────────────────
# Samples ADC on GP26 and displays waveform on SSD1306 OLED (128×64)
# Secondary mode: streams samples as CSV over USB serial for PC plotting
#
# Install MicroPython on Pico first: https://micropython.org/download/RPI_PICO/
# Copy this file as main.py using Thonny IDE or mpremote
# ─────────────────────────────────────────────────────────────────────────────
import machine
import utime
import ssd1306
import math
# ── Hardware setup ────────────────────────────────────────────────────────────
ADC_PIN
= 26
# GP26 = ADC0 (0–3.3V)
BTN_MODE  = 15
# Button to toggle OLED ↔ USB serial mode
BTN_SCALE = 16
# Button to cycle voltage scale
adc = machine.ADC(ADC_PIN)
btn_mode  = machine.Pin(BTN_MODE,  machine.Pin.IN, machine.Pin.PULL_UP)
btn_scale = machine.Pin(BTN_SCALE, machine.Pin.IN, machine.Pin.PULL_UP)
i2c  = machine.I2C(0, scl=machine.Pin(1), sda=machine.Pin(0), freq=400_000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
# ── Config ────────────────────────────────────────────────────────────────────
SAMPLES
= 128
# One sample per OLED column
SAMPLE_US
= 100
# µs between samples → 10 kSPS base rate
SCALES
= [3.3, 1.65, 0.825, 0.4125]
# V full-scale
scale_idx
= 0
usb_mode
= False
def sample_waveform():
    buf = []
    for _ in range(SAMPLES):
        buf.append(adc.read_u16())
        utime.sleep_us(SAMPLE_US)
        return buf
        def draw_waveform(buf):
            oled.fill(0)
            v_max = SCALES[scale_idx]
            # Draw graticule
            for gx in range(0, 128, 32):
                for gy in range(0, 64, 16):
                    oled.pixel(gx, gy, 1)
                    # Trigger: find first rising zero-crossing near 50% rail
                    trigger_level = 32768
                    start = 0
                    for i in range(1, SAMPLES - 1):
                        if buf[i-1] < trigger_level <= buf[i]:
                            start = i
                            break
                            for x in range(min(128, SAMPLES - start)):
                                raw = buf[start + x]
                                volts = raw / 65535 * 3.3
                                y = int((1.0 - volts / v_max) * 56) + 4  # 4px top margin, 56px plot area
                                y = max(4, min(60, y))
                                oled.pixel(x, y, 1)
                                if x > 0:
                                    prev_raw = buf[start + x - 1]
                                    prev_volts = prev_raw / 65535 * 3.3
                                    py = int((1.0 - prev_volts / v_max) * 56) + 4
                                    py = max(4, min(60, py))
                                    # Simple line interpolation
                                    if abs(y - py) > 1:
                                        step = 1 if y > py else -1
                                        for iy in range(py, y, step):
                                            oled.pixel(x - 1, iy, 1)
                                            # Annotations
                                            oled.text(f"{v_max:.2f}V", 0, 0, 1)
                                            peak_v = max(buf) / 65535 * 3.3
                                            oled.text(f"pk:{peak_v:.2f}", 64, 0, 1)
                                            oled.show()
                                            # ── Main loop ─────────────────────────────────────────────────────────────────
                                            print("Pico Oscilloscope ready | USB serial for CSV stream")
                                            while True:
                                                # Button handling
                                                if not btn_mode.value():
                                                    usb_mode = not usb_mode
                                                    utime.sleep_ms(300)
                                                    if not btn_scale.value():
                                                        scale_idx = (scale_idx + 1) % len(SCALES)
                                                        utime.sleep_ms(300)
                                                        buf = sample_waveform()
                                                        if usb_mode:
                                                            # Stream raw 16-bit samples as CSV — plot with PC script
                                                            print(",".join(str(v) for v in buf))
                                                        else:
                                                            draw_waveform(buf)
main.py
# ── pc_plotter.py — Run on your PC to plot Pico USB serial stream ────────────
# pip install pyserial matplotlib
import serial
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np

PORT   = "/dev/ttyUSB0"   # Windows: "COM3"
BAUD   = 115200

ser = serial.Serial(PORT, BAUD, timeout=1)
fig, ax = plt.subplots()
line,  = ax.plot([], [], lw=1, color="#00ff88")
ax.set_xlim(0, 128)
ax.set_ylim(0, 65535)
ax.set_facecolor("#0d1117")
fig.patch.set_facecolor("#0d1117")
ax.set_ylabel("ADC counts (0–65535)", color="white")
ax.tick_params(colors="white")

def update(_frame):
    raw = ser.readline().decode("utf-8", errors="ignore").strip()
    if not raw: return line,
    try:
        vals = [int(v) for v in raw.split(",") if v]
        if len(vals) == 128:
            line.set_data(range(128), vals)
    except ValueError:
        pass
    return line,

ani = animation.FuncAnimation(fig, update, interval=50, blit=True)
plt.tight_layout()
plt.show()

Wiring and First Test

Use the Pico ADC input GP26 (ADC0) for the signal and connect the signal source ground to Pico GND. For the SSD1306 I²C display in this example, connect SDA to GP0, SCL to GP1, VCC to the display module’s supported supply, and GND to GND. The two optional push buttons connect GP15 and GP16 to GND; the code enables internal pull-ups, so a pressed button reads LOW. Confirm the pin labels on your own Pico and display before powering the circuit.

ConnectionRaspberry Pi PicoNotes
Signal inputGP26 / ADC0Keep the input between 0 and 3.3 V
Signal groundGNDCommon ground is required
OLED SDAGP0I²C0 data in this example
OLED SCLGP1I²C0 clock in this example
Mode buttonGP15 to GNDOptional; internal pull-up enabled
Scale buttonGP16 to GNDOptional; internal pull-up enabled

Understand the Sample Rate and Display Limits

This is an educational, low-speed waveform viewer—not a calibrated bench oscilloscope. The MicroPython loop, list allocation, OLED drawing, and Python interpreter overhead all affect the real sample interval. A configured 100 microsecond delay does not guarantee a precise 10 kS/s rate. Measure the actual capture interval or treat the display as qualitative unless you have validated the timing. The RP2040 ADC is 12-bit hardware, but MicroPython's read_u16() scales readings to a 16-bit range; it does not create 16 bits of effective resolution.

A simple sequential capture also has limited trigger stability and can miss fast transients. Use a known low-voltage test waveform first, such as a slow square wave from a signal generator, and compare the result with a multimeter or a trusted instrument. Do not use this build to certify frequency, amplitude, or safety-critical signals.

Calibration and Troubleshooting

  1. Run a short test that prints ADC readings with the input tied to GND; values should remain near zero, with small noise possible.
  2. Apply a known voltage below 3.3 V through a suitable source and compare the reading with the expected ADC scale.
  3. If the OLED stays blank, check its I²C address, supply voltage, SDA/SCL wiring, and that the ssd1306.py driver is copied to the Pico.
  4. If the waveform is clipped, reduce the input amplitude or choose a suitable voltage divider. The scale buttons do not protect the input electrically.
  5. If the PC plotter shows no data, select the correct serial port, close Thonny's serial console, and match the baud rate.

Input Protection and Safe Use

The Pico GPIO and ADC pins are not 5 V tolerant. Never connect a 5 V logic output, an unknown circuit, or mains-referenced equipment directly to GP26. A resistor divider can reduce a known low-voltage signal, but it is not sufficient isolation for mains or other hazardous sources. For unknown signals, use a properly rated isolated probe or a commercial oscilloscope. Keep grounds common only when the source is known to be safe to connect.

What This Project Is Best For

Use this build to learn ADC sampling, basic triggering, I²C display control, and serial data transfer. For faster or more repeatable acquisition, move the sampling routine to C/C++ and use the RP2040's ADC FIFO and DMA, then validate timing independently. That is a separate upgrade from the MicroPython example shown here.

What This MicroPython Oscilloscope Can Measure

This project is an educational waveform viewer, not a replacement for a calibrated bench oscilloscope. The Raspberry Pi Pico reads an analogue voltage through ADC0 on GP26, draws a compact trace on an SSD1306 128×64 OLED, and can stream samples to a computer for plotting. The ADC input must stay within approximately 0–3.3 V. A negative input, a 5 V logic signal, or a large transient can damage the board. Measure an unknown signal first and add suitable attenuation, buffering, or protection before connecting it.

The RP2040 ADC is nominally 12-bit, but useful resolution and noise depend on the board, reference stability, source impedance, and sampling code. MicroPython adds interpreter and scheduling overhead, so the achieved rate is lower and less consistent than a dedicated instrument. Use this project to observe slow sensor outputs, modest ripple, and low-frequency signals—not as a promise of a fixed bandwidth or calibrated accuracy.

A waveform's horizontal scale depends on the actual sample interval, while its vertical scale depends on the ADC conversion and any external divider. If the firmware does not measure or guarantee those values, label the plot as relative amplitude or ADC counts instead of claiming calibrated volts per division. This matters when comparing results from different boards or code versions.

Wiring and Signal Conditioning

Connect the signal source to GP26/ADC0 and its ground to a Pico GND pin. For the display example, connect SSD1306 SDA to GP0 and SCL to GP1, with display power selected according to the module documentation. Optional buttons on GP15 and GP16 can connect to GND when the firmware enables internal pull-ups; a pressed button then reads LOW. Confirm pin labels and code assignments before powering the circuit.

Never connect mains voltage, a mains-referenced circuit, a motor-driver output, or an unknown high-energy source directly to the Pico. A resistor divider alone may not provide isolation or transient protection. For signals outside the ADC range, use a properly designed attenuator and protection network. For mains-related measurements, use a suitably rated isolated instrument or differential probe and follow electrical safety practices; do not attach Pico ground to an unsafe potential.

For a divider with top resistor R1 and bottom resistor R2, the approximate output is Vin × R2 / (R1 + R2). Choose resistor values and ratings for the maximum possible input, not just the expected value. The divider ratio in the firmware must match the physical circuit. A divider also changes source impedance and can affect ADC settling; a buffer may be needed for high-impedance sources. Until the divider is built and validated, display raw ADC counts instead of a claimed input voltage.

Never let the voltage on GP26 go below 0 V or above 3.3 V, or the Pico's ADC input can be damaged.

Reading the Trace and Plotting on a Computer

The OLED has only 64 vertical pixels, so it compresses the waveform into a small number of amplitude levels. It can show whether a signal is flat, periodic, noisy, clipping, or changing over time, but it cannot reveal fine detail like a full-size display. If the trace is jumpy, check the physical input first: use a short ground lead, keep it away from switching power wires, and ensure the source shares ground with the Pico. Compare raw ADC samples against a stable, known voltage.

A moving average reduces random noise but also smooths fast changes and can distort narrow pulses. A median filter can reject occasional spikes; a low-pass filter may help with slow sensor trends. Keep filtering optional and explain its effect. A trace clipped at the top or bottom may indicate an input outside the ADC range, a display scale that is too narrow, or software clamping. A flat line can also mean the input is disconnected or the code is not updating.

The PC plotting script uses USB serial and Matplotlib. Install the serial and plotting dependencies in the computer's Python environment, select the serial port that appears when the Pico is connected, and close other applications that might have opened it. Match the firmware's baud rate and line format. One integer sample per line is easy to parse; CSV rows are useful when sending multiple channels or timestamps. Avoid mixing debug messages into the sample stream unless the parser can ignore them.

For meaningful comparisons, record the sample interval, ADC range, divider ratio, and filtering settings. If the firmware does not provide a calibrated time base, label the horizontal axis “sample index” rather than seconds. If the vertical conversion is not calibrated, use ADC counts or relative amplitude rather than volts.

Troubleshooting and Validation

  • OLED stays blank: check power, ground, SDA/SCL, I²C address, and display compatibility. An I²C scanner can help isolate the problem.
  • Trace stays near zero: check common ground, the GP26/ADC0 connection, and raw ADC values in the serial console.
  • Trace is pinned high: verify input voltage and divider ratio; never raise the input voltage to “fix” saturation.
  • Waveform is noisy: shorten leads, improve grounding, inspect source impedance, and add filtering only after viewing raw samples.
  • PC script shows no points: confirm serial port, baud rate, newline format, and that the firmware is streaming samples.
  • PC and OLED traces differ: check for different sampling intervals, scaling, and filtering.
  • USB disconnects: inspect the cable, host port, power stability, and serial output rate.

Repeatable Test Procedure

Connect GP26 to GND and confirm readings stay near zero. Next apply a known low DC voltage from a safe, current-limited source and compare the raw ADC reading with the expected value. Never exceed 3.3 V. Then use a low-frequency, low-voltage signal from a function generator or safe sensor output. Compare the OLED and PC plots and note any aliasing or dropped samples. Remove the test signal and confirm the reading returns to baseline.

Graph and Evidence to Add

A measured waveform screenshot is useful, but it should come from captured samples rather than invented data. Add a PC plot with axes labelled in sample index or measured time and ADC counts or calibrated volts. Its caption should state the signal source, sample interval, divider ratio, and filter settings. An animated SVG trace can make a good educational illustration if the site supports inline SVG, but label it illustrative unless it is driven by live Pico data. Do not present a decorative animation as a measurement.

Sampling Rate, Aliasing, and Interpreting Frequency

A sampled waveform can only represent changes that the sampling process captures. If a periodic signal changes too quickly relative to the sample rate, the displayed pattern may appear slower, unstable, or misleading; this is aliasing. The theoretical Nyquist limit is half the sampling frequency, but a useful waveform display generally needs multiple samples per cycle and a stable sample interval. The MicroPython loop, display refreshes, serial output, and other work can make the sample interval vary, so do not infer a precise frequency from the shape alone unless the code measures timing and accounts for dropped samples.

For a first experiment, use a low-frequency signal and increase its frequency gradually while watching both the OLED and PC plot. Note when the waveform begins to lose detail or its apparent frequency changes. Repeat the test with the display update temporarily reduced or disabled, if the firmware supports that, to see how rendering affects acquisition. If accurate timing is important, use hardware-timed sampling and buffering in a lower-level implementation rather than assuming a Python loop provides a fixed-rate sampler.

Capture Notes for Reproducible Results

For each screenshot, record the source waveform, approximate amplitude, sample interval or configured delay, number of samples displayed, and any filtering. Include whether the horizontal axis is sample index or time. If converting ADC counts to voltage, state the ADC reference assumption and any divider ratio; do not claim calibration unless you checked the result against a known source. These notes help readers distinguish a real measurement from a decorative illustration and explain why two builds may show different traces.

Extensions That Add Real Value

Useful next steps include a selectable time window, adjustable vertical scaling, trigger level for repetitive signals, min/max readout, and CSV capture for later analysis. Add one feature at a time and check that it does not silently reduce the sample rate. A trigger can make repetitive signals easier to inspect, but it should be documented as a software trigger if it operates on a buffer after acquisition. The most useful improvement is not a more elaborate animation; it is a transparent acquisition path with known limits and a graph that accurately labels the data it displays.

Illustrative oscilloscope waveform and sampled points
ADC sampling workflow for Pico oscilloscope
Topicsraspberry-piraspberry-pi-picomicropythonoscilloscopeadcoledssd1306

Questions & Answers