PiicoDev BME280 /ESP32 using MicroPython?

Hi All.
Just wondering if anyone has developed any projects here using PiicoDev BME280 / ESP32 and MicroPython?

Cheers in advance


Welcome Phil!

I’ve completed a couple with the ESP32-C3 and standard modules.

The only quirk I’ve run into is having to manually initialise the I2C bus before the modules (though I am running a different branch of Micropython)
An example using the OLED module:

from PiicoDev_SSD1306 import *

i2c = I2C(0,sda=Pin(8),scl=Pin(9))

display = create_PiicoDev_SSD1306(addr=0x03D)

I’ve just finished working on a 3d printing filament dry box monitor using an ESP8266 running Micropython.

I used the PiicoDev BME280 for humidity and temperature logging, and a PiicoDev Oled for showing the current sensor data. I also run a web server on the ESP8266 which is then queried by my home automation server to log the data over time (and so I can make pretty graphs!)

Since the ESP8266 is quite memory constrained I did have to slim down the PiicoDev_SSD1306.py and PiicoDev_Unified.py files to only the Machine Micropython stuff (and ditch the Linux and Microbit code).

The overall process and code should be much the same between the ESP8266 that I have used and the ESP32.

My code is here:
Github - Filament Monitor


Hi Shane,

Neat write-up!! What home automation service are you running?

PS: I’d also check out the minified versions of the PiicoDev libraries!:

I’d be keen to see some pics :smiley:


Sweet, I’ll have to check out those minified versions!

Could be very useful on my retic controller when I migrate it over to a Piico temp sensor rather than the current raw LMT86LP sensors I’m currently using. Either that or I’ll just have to throw a ESP32 at it instead and be lazy with memory management!

I would use a PicoW since they’re cheaper than an ESP32 but since it doesn’t natively have WebRePL it’s a no go for now. (Way easier to manage it remotely than lug my laptop around outside, unbolt everything, plug it all in to the laptop just to push an update!)

Currently I’m running a homebrew webserver hosted on a Raspberry Pi 4B 4GB. It runs a homemade flask webserver for all my interactions and graphing etc.

Automations are built in python to do a whole bunch of things (get and save down temps from 5 stations around the home, manage my aircon, retic, save down my solar power data, etc) and are managed through a ‘master scheduler’ python script that is run as a cron job.

I’m sure there are pre-built solutions that work way better and more robustly but doing it myself has taught me so much more!

I’ve jerry rigged the OLED and Atmos sensor in my filament dry box until I can 3D print a proper housing for it. (Pics 1 & 2 in the album below).

I’m also working on some new temperature sensor boxes to replace my current ones around the house that are janky project boxes with a usb plug hot glued to them! These will use the PiicoDev TMP117 sensors, and a 5v mini 30mm Rasperry Pi cooling fan running at 30% through PWM to ensure accurate air temps! (Pics 3,4, and 5 in the album)

Imgur Album



Hey ShaneC and thanks for responding. With regards to the PicoW are already flashed with MicroPython ?? This could be a simpler solution than re-inventing the wheel with the ESP32 ?



You could definetly go with a PicoW, The main reason I’m sticking with ESP32 / 8266 at the moment is due to the micropython port for the PicoW is still pretty early days and is missing WebREPL support out of the box.

Since I deploy all my microcontrollers all around the house (and in the roof, and outside and everywhere!) WebREPL is an absolute game changer for me. Being able to deploy updates remotely from my PC to all of my devices still seems like absolute magic.

Flashing Micropython onto an ESP32 / 8266 is really quite simple;
Micropython have great guides for both the ESP 8266 and the ESP 32

Personally I’ve got way more experience with the 8266 since I use the Wemos D1 Mini mostly since it’s tiny, cheap and cheerful!


Hi Shane,

That filament drybox is looking really neat, no doubt it will look even better once you’ve finished the display housings.
This is good motivation to get my half-finished drybox moving :laughing:


I have flashed a few esp32’s with micropython and still yet to get the bme280 to work.
some code issues. do you have some code for i can study for the ESP32 / 8266 using the PiicoDev bme 280?



I’ve gotten the PiicoDev BME280 working on a ESP8266 flashed with micropython in this repo

Specifically I’ve modifed the Piico Unified for memory, but you won’t need to on the ESP32. So just grab the latest PiicoDev_Unified.py from CE-PiicoDev-Unified and the PiicoDev_BME280.py from CE-PiicoDev-BME280

If you upload both of those along with a main.py like:

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function

sensor = PiicoDev_BME280() # initialise the sensor

while True:
    tempC, presPa, humRH = sensor.values() # read all data
    pres_hPa = presPa / 100 # convert Pascals to hPa (mbar)
    print(str(tempC)+" °C  " + str(pres_hPa)+" hPa  " + str(humRH)+" %RH")

You should then see the values being printed to the console.

Or you can have a look in my AtmosMonitor.py in the repo mentioned above which logs the temp and Humidity to lists every 5 seconds (overwritting as they fill up). FYI this is managed from the main.py which calls checkSensorReads in its main loop function.

you can then call the calculateAverageTemp() or calculateAverageHumidity() and it returns the average value recorded. Since the arrays hold 60 entries and they’re updated every 5 seconds it effectly returns the average value over the last 5min based on readings made every 5 seconds.


let me try what you have posted… looks familiar, but it didn’t work. kept complaining that the bme wasn’t connected.

Thanks in advance


Other things to check would be that the switch on the BME280 is in the off position (I think it’s actually labelled ‘1’)

Also I think the ESP32 has multiple I2C sets of pins so you might need to go through them to see which one is the default on your particular board.


Hi Phil,

To cover all of the bases I’d try the following:

  1. First confirm that your ESP32 recognises the BME is on the bus
    Run in the REPL or main script (you might have to change the pin numbers, I’m running a custom board):
from machine import Pin,I2C
i2c = I2C(0,sda=Pin(9),scl=Pin(8))
  1. Then you should be able to initalise the BME
    (I’m not sure if the extra i2c setup will be required for you but since using 1.19 on the ESP32-C3 it’s no longer required)
    My main.py is:
from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function

sensor = PiicoDev_BME280() # initialise the sensor


After running steps 1 and 2 the REPL looks like this:

If the above doesn’t work would it be possible to send through a link to:

  • the ESP32 board you are using?
  • A screenshot of the REPL after you reset the board? (Just looking for the micropython version)

Hi Liam,

I am running VROOM ESP32’s…
Let me use your snipette of code and will let you know.

I was running the BMP280’s prior without any weather reporting issues.

I did notice that you are using sda 9 and scl 8. where I am using sda 21 and scl 22

will let you know how it goes.

thanks in advance


thanks checked and tested both options to no avail.


Hi Liam
Just browsing this thread and noticed something peculiar.
Earlier (4 days ago) you quoted

And recently you quote

And I am sitting here at the moment with a little Pico pin out card (supplied by Core) that suggest the default I2C pins to be SDA = GP8 and SCL = GP9.
Could this be the cause of some confusion. I know I am just starting to have a look at these Pico units and I am a little confused.
Cheers Bob


Hi Liam,
can you confirm i2c = I2C(0,sda=Pin(9),scl=Pin(8))


1 Like


Hi Phil
I am looking at the “ordinary” Pico which is nothing like the “W” version you portray. That doesn’t seem to have any GPIO between 5 and 13.
This is the first time I have looked at this detail. I would have imagined the “W” version would have been much the same except for the addition of the “W” feature. This is a completely different beast, even down to the number of pins, This one has 30 and the plain Pico has 40.

Might be the reason I have stayed clear of RPi for so long.
Cheers Bob
EDIT: Just had a look. Apologies to RPi. The board depicted above is NOT a Pico W. The Pico W does indeed resemble the “ordinary” Pico and has the default I2C on GPIO 8 and 9. So I got a bit mixed up by not being familiar with all the flavours out there.