PiicoDev Atmospheric Sensor BME280 - Raspberry Pi Guide

I’ve just shared a new tutorial: “PiicoDev Atmospheric Sensor BME280 - Raspberry Pi Guide”

This guide will help you read weather data from your PiicoDev® Atmospheric Sensor and a Raspberry Pi single-board computer

Read more


Very impressive. I tried the BME280 on a headless Rasperry Pi Zero W and it was going in no time.

I then tried the advanced example to get more accurate valuesfrom:

Python crashed in the lines:
NameError: name ‘machine’ is not defined

From the notes the SDA & SCL Pin are only implemented on the Raspberry Pi Pico.

I tried commenting the lines out, inserting dummy values but nothing seemed to work.

Has anyone managed to get this code to work on the Pi as distinct from the Pi Pico?


Thanks for raising this!
Yes it appears this demo was written with Raspberry Pi Pico in mind because it is relying on calls to machine, and changes the default I2C pins - something we can’t yet do on a raspberry pi.

However, you can still play with the ‘advanced features’ like the IIR filter. Here’s something to get you started - I’ve just stripped out the code that is doesn’t play well on a Pi.

The really useful parameters in this example are the pressure_sea_level argument which allows you to null-out your local mean-sea-level-pressure, and iir which filters pressure samples.

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms

sensor = PiicoDev_BME280(t_mode=2, p_mode=5, h_mode=1,iir=2)
zeroAlt = sensor.altitude(pressure_sea_level=1013.25)

while True:
    tempC, presPa, humRH = sensor.values()
    pres_hPa = presPa / 100
    print(str(tempC)+" °C  " + str(pres_hPa)+" hPa  " + str(humRH)+" %RH")
    print(sensor.altitude() - zeroAlt)

This updated code will likely become an exact replacement for the advanced demo.

We’ll update the documentation to be more platform-agnostic - I’ve opened an issue in the repo on your behalf.


Hi Michael
Once again thanks for your prompt reply. I was interested in the advanced features to improve accuracy, especially for temperature. The pressure_sea_level argument could be useful for calibrating to official BOM readings.


I have used the BME280 sensor before and have noticed a couple of things wih readings which are also on the PiicoDev board.
The first is it seems to need about 30 minutes to “burn in”. For example when first used you can see the temperature measurement gradually go lower even in a stable environment.
The other is that the first few readings are often wild.
The first issue takes care of itself. With the second issue I get around this in the code. After power up I take five fairly rapid throw away readings before starting actual recording.
I cannot find any mention of this in the data sheets. Pimoroni noticed the same thing “In our testing, we’ve found that the sensor requires some burn-in time (at least 20 minutes) and that readings may take a couple of minutes to stabilise after beginning measurements”.

Note this is a comment on the BME280 sensor and not on the PiicoDev board which is absolutely superb!


I’ve ordered a PiicoDev BME280 board that I plan to use with a Raspberry pi. I didn’t order the connecting cable instead I plan to solder header pins to the board. I have downloaded the sample software and the problem is that I don’t know which board pin connects the which Raspberry pi pin. Can anyone help?


Hey @Phil196453 - these are the pins you’re after. There are four connections (GND, 3v3, SDA and SCL) to make with the raspberry pi.


Thank you Michael and sorry to have bothered you. Being a long-time
Raspberry pi owner I should have known the answer. At the time I was
thinking that there are two pairs of I2C pins.


No problem @Phil196453 - the PiicoDev examples leave out pin numbering on purpose to remove as much ‘noise’ as possible for beginners since they’ll be using the default pins broken out by the PiicoDev adapters.


Which, Michael, brings up another question. Does the PiicoDev board use
the Pi Pico’s I2C 0 or 1. I’m guessing it’s I2C 0 which is pin 1 and 2.
I know it would be just a matter of trial and error to find out.


The machine package uses I2C0, GPIO8 and 9 by default, so PiicoDev also uses these by default too. See the readme for changing the i2c bus or pins.


Thank you Michael and I’m looking forward to having the PiicoDev board
in my hand.


19 posts were split to a new topic: Using PiicoDev BME280 on the Pi 5