Hi All.
Just wondering if anyone has developed any projects here using PiicoDev BME280 / ESP32 and MicroPython?
Cheers in advance
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
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)
Cheers!
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 ?
Cheers!
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
coolā¦
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?
Cheers!
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")
sleep_ms(100)
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:
from machine import Pin,I2C
i2c = I2C(0,sda=Pin(9),scl=Pin(8))
i2c.scan()
from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function
sensor = PiicoDev_BME280() # initialise the sensor
print(sensor.values())
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:
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))
Pins?
Phil
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.