TCS Pune

MicroPython Pico Sensor Logger

MicroPython

MicroPython Pico Sensor Logger

Sample an analogue input and print plotter-ready values on RP2040.

IDE: Thonny or mpremote with current Pico MicroPython firmwareBoard/MCU: Raspberry Pi Pico / RP2040

Project files

Download project ZIP
Starter — main.py
from machine import ADC
from time import sleep_ms
sensor = ADC(26)
while True:
    # TODO read and print
    sleep_ms(100)
Completed — main.py
from machine import ADC
from time import sleep_ms, ticks_ms
sensor = ADC(26)
while True:
    raw = sensor.read_u16()
    volts = raw * 3.3 / 65535
    print(f'{ticks_ms()},{volts:.3f}')
    sleep_ms(100)

Toolchain and dependencies

IDE requirements

Thonny or mpremote with current Pico MicroPython firmware

Compatible targets

Raspberry Pi Pico / RP2040

Libraries/dependencies

  • MicroPython machine and time modules (built in)

Serial output examples

Serial Monitor

0,0.412
100,0.825
200,1.237
300,1.650

Serial Plotter

Compiler-error explanations

ImportError: no module named machine

Likely cause: Script is running in desktop Python

Fix: Select the MicroPython interpreter connected to the board

OSError: invalid ADC pin

Likely cause: ADC was created on a non-ADC GPIO

Fix: Use GPIO26–GPIO28 on Pico

Submit your code

Log in to edit the starter files and submit your solution for instructor review.

Log in to submit
Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA