Raspberry Pi Pico environmental logger — Thu 06 July 2023

I've started a little environmental logger project, just for temperature, pressure and relative humidity. Using the Raspberry Pi Pico controller, a simple BME280 sensor and to provide a clock which won't lose time if the main power is disrupted, a STEMMA QT / Qwiic I2C interface to the Pico and an SD card for data the Adafruit PiCowbell.


Logger should eventually be able to run on battery for an extended time. This will mean exploring ways of reducing power consumption. Not an immediate goal.

The data can be accessed from a built-in web interface for quick checks on values - there won't be a local display.

Start off development by using the Pimoroni MicroPython library and runtime; this will allow used of the wifi capabilities.

Provide a git repository for any useful code which might come out of this.

To access the SD card and the clock will require using CircuitPython libraries - these can be used via the Adafruit Blinka compatibility layer (hopefully).

For data presentation, there'll be a library for Snap!


I've got most of the components, and was just waiting for some headers which arrived today.

Logger components

First task to solder headers onto the PiCowbell; so that it can be attached to the headers on the Pico, there's a procedure for this (on the Adafruit site) which involves soldering the four corner pins first to get the mechanical alignment right, then soldering the remainder. With the stacking, unfortunately the reset button is inaccessible, so a Pimoroni Captain Resetti switch designed for the original Pico works well. Not an essential mod but handy for the first dev. Stages.

Add reset switch

Here's the final development package with the sensor connected - it ends up being quite compact.

Development package

First code

Just to see that there was communication over I2C from the sensor, tried the below code. Some references for this are (PDF)

Raspberry Pi MicroPython SDK

… and the Pimoroni sensor libraries (we need the BME280 one)

First thing is to import the required libraries, then (blinking an LED is Hello world) set up the relevant pin (which changes for the PicoW from the standard Pico). An i2c port is setup and the reference to the device initialised. Finally a 1 second period timer is kicked off to grab and print out a reading and toggle the LED.

from machine import Pin, Timer
from breakout_bme280 import BreakoutBME280
from pimoroni_i2c import PimoroniI2C

led = Pin("LED", Pin.OUT)
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}

bme = BreakoutBME280(i2c)

tim = Timer()
def tick(timer):
    global led, bme
    reading = bme.read()
    print(reading[0], "C", reading[1], "Pa", reading[2], "%")

tim.init(freq=1, mode=Timer.PERIODIC, callback=tick)

First readings

Values are degrees C for temp, Pascals for pressure and a % for relative humidity. Looks like these are sensible.

Enough for today!