BMP280 / BME280 uPython

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Rissy
Posts: 116
Joined: Sun Aug 14, 2022 8:15 am

BMP280 / BME280 uPython

Post by Rissy » Thu Aug 25, 2022 5:46 pm

Hello all,

I've had a look on Github (Although admittedly i'm not very good at understanding what i'm actually looking at half the time there).

I'm looking for the necessary files I need to get a BMP280 breakout from Pimoroni working with a Pico W, and also I want to do the same thing again but with two BME280 breakouts from Pimoroni linked in series with my other Pico W.

I found this on Github: https://github.com/pimoroni/pimoroni-pi ... on/modules

This seems to be a source of what i need, at least to get me started. But I don't understand what to do with this information. There's no instructions on what to do.

Can anyone assist?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BMP280 / BME280 uPython

Post by jimmo » Fri Aug 26, 2022 12:15 am

Rissy wrote:
Thu Aug 25, 2022 5:46 pm
I found this on Github: https://github.com/pimoroni/pimoroni-pi ... on/modules

This seems to be a source of what i need, at least to get me started. But I don't understand what to do with this information. There's no instructions on what to do.
Pimoroni make a custom build of MicroPython that includes a lot of drivers for their breakouts. This is the code for their custom version.

You can use their .uf2 firmware images in place of the official MicroPython builds. See https://github.com/pimoroni/pimoroni-pico

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BMP280 / BME280 uPython

Post by jimmo » Fri Aug 26, 2022 12:16 am

That said, you might also prefer just to use a Python driver on a regular MicroPython version.

See https://github.com/robert-hh/BME280
and https://github.com/dafvid/micropython-bmp280

Rissy
Posts: 116
Joined: Sun Aug 14, 2022 8:15 am

Re: BMP280 / BME280 uPython

Post by Rissy » Fri Aug 26, 2022 6:14 am

Thanks Jimmo, that’s a great piece of guidance there.

I’ll take a look at the pimoroni link there later today after work.

With regards to roberthh’s official upython version, I saw that too, after I posted last night, but I’ll admit it wasn’t obvious to me what I needed to do. I didn’t recognise any of the snippets of code as being usually upython structure, and I *think* it needs to tap into driver files which I couldn’t see or have any knowledge of. I know you can put folders on to a pico w, so am I needing to collect driver files or something and put them into a particular folder or something? Otherwise how can I “import bme280 from BME280” for instance?

I’m a bit confused, but I’m just new to this. I only have one example of a running and complex looking piece of code on my first pico w, and I can’t even remember where I first found the coding which got me started with a sht30 device. In fact, roberthh himself had to help me quite heavily to get that working in the end.

Rissy
Posts: 116
Joined: Sun Aug 14, 2022 8:15 am

Re: BMP280 / BME280 uPython

Post by Rissy » Fri Aug 26, 2022 8:13 am

Oh, i think i've been a bit stupid. I WAS tired last night, and i was replying earlier on my phone before work an in a bit of a rush, so didn't see the links properly.

Looking at roberthh's page, am i to rename and use either bme280_float.py or bme280_int.py to be just bme280.py depending on the one i want to use, and then put that on the pico w alongside bmetest.py and use that as the top level working example for my editing purposes?

This is seemingly not necessary for dafvid's bmp280 version but instead, you need to copy bmp280.py and leave as, and then use the working example, calling it anything you want, and then this taps into the first bmp280.py file.

Have i got it?


And then for the pimoroni versions, i need:

the pico w version from this page: https://github.com/pimoroni/pimoroni-pi ... ag/v1.19.6
& these
https://github.com/pimoroni/pimoroni-pi ... out_bme280
https://github.com/pimoroni/pimoroni-pi ... out_bmp280

is this correct?

It was this stuff that i saw last night: https://github.com/pimoroni/pimoroni-pi ... out_bme280

This confused me. What is this please?

danjperron
Posts: 51
Joined: Thu Dec 27, 2018 11:38 pm
Location: Québec, Canada

Re: BMP280 / BME280 uPython

Post by danjperron » Fri Aug 26, 2022 12:32 pm

I didn't have any problem with the BME280 sensor but I installed that version


https://github.com/SebastianRoll/mpy_bme280_esp8266


I just copy the bme280.py into the pico lib folder.


This is an example. I didn't test this exact code but it should work since I extracted it from my working solar garden station.
https://github.com/danjperron/PicoWSolar

Be aware that some BME280 aren't at 0x77 address. Check yours using i2c.scan()

Code: Select all

import machine
import bme280    
bme_PinSDA=4
bme_PinSCL=5
bme_i2c_address = 0x77

i2c=machine.I2C(0,sda=machine.Pin(bme_PinSDA), scl=machine.Pin(bme_PinSCL), freq=100000)    #initializing the I2C method 
bme = bme280.BME280(i2c=i2c,address=bme_i2c_address)


def readBme():
    try:
        t, p, h = bme.read_compensated_data()
        t, p, h = bme.read_compensated_data()
        return (t/100.0 , p/25600.0, h/1024.0)
    except OSError as e:
        pass
    return None    

t, p , h = readBme()
print("Temperature :", t)
print("Humidity:", h)
print("Pressure:", p)

Rissy
Posts: 116
Joined: Sun Aug 14, 2022 8:15 am

Re: BMP280 / BME280 uPython

Post by Rissy » Fri Aug 26, 2022 12:56 pm

danjperron wrote:
Fri Aug 26, 2022 12:32 pm
I didn't have any problem with the BME280 sensor but I installed that version


https://github.com/SebastianRoll/mpy_bme280_esp8266


I just copy the bme280.py into the pico lib folder.


This is an example. I didn't test this exact code but it should work since I extracted it from my working solar garden station.
https://github.com/danjperron/PicoWSolar

Be aware that some BME280 aren't at 0x77 address. Check yours using i2c.scan()

Code: Select all

import machine
import bme280    
bme_PinSDA=4
bme_PinSCL=5
bme_i2c_address = 0x77

i2c=machine.I2C(0,sda=machine.Pin(bme_PinSDA), scl=machine.Pin(bme_PinSCL), freq=100000)    #initializing the I2C method 
bme = bme280.BME280(i2c=i2c,address=bme_i2c_address)


def readBme():
    try:
        t, p, h = bme.read_compensated_data()
        t, p, h = bme.read_compensated_data()
        return (t/100.0 , p/25600.0, h/1024.0)
    except OSError as e:
        pass
    return None    

t, p , h = readBme()
print("Temperature :", t)
print("Humidity:", h)
print("Pressure:", p)
Thanks danjperron!

Plenty of choice it seems to choose from!

Looking at people's code scares me, as everyone is much further advanced in their coding techniques compared to me, so a lot of what is written, I struggle to follow. If I showed you my code, which is probably deemed "long winded" and "clunky"; at least it's written in such a way that I understand it (or at least did at the time of writing it!).

I'm still struggling with using functions and understanding them. Then people throw in lots of fancy words to describe ways of doing things when I watch YouTube videos on things like classes and __init__'s and self's etc, my little brain verges on exploding! :lol:

I guess what i'm saying is, I'll take what others have written, and see what it does because i can't fully understand it right now just by looking at it and then once i see what it does, I can see if i can modify it to achieve what I need/want it to do, and if/WHEN i struggle with this, then I'll call on help from you guys to assist or guide me in achieving my goals.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BMP280 / BME280 uPython

Post by jimmo » Fri Aug 26, 2022 2:08 pm

Rissy wrote:
Fri Aug 26, 2022 8:13 am
It was this stuff that i saw last night: https://github.com/pimoroni/pimoroni-pi ... out_bme280

This confused me. What is this please?
This is a different driver, written in C++ that is used by the Pimoroni custom firmware.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: BMP280 / BME280 uPython

Post by Roberthh » Fri Aug 26, 2022 7:18 pm

Looking at roberthh's page, am i to rename and use either bme280_float.py or bme280_int.py to be just bme280.py depending on the one i want to use, and then put that on the pico w alongside bmetest.py and use that as the top level working example for my editing purposes?
Yes, you can do that. The default pins for I2C(0) at the Pico are scl=Pin(9), sda=Pin(8). Please be awarm that the Pin numbers are GPIO numbers. So GPIO(8) is at board pins # 11. The difference between the results of the int and float version is minor and in any case much smaller than the measurement error of the sensor.

Rissy
Posts: 116
Joined: Sun Aug 14, 2022 8:15 am

Re: BMP280 / BME280 uPython

Post by Rissy » Sat Aug 27, 2022 2:25 pm

Roberthh wrote:
Fri Aug 26, 2022 7:18 pm
Looking at roberthh's page, am i to rename and use either bme280_float.py or bme280_int.py to be just bme280.py depending on the one i want to use, and then put that on the pico w alongside bmetest.py and use that as the top level working example for my editing purposes?
Yes, you can do that. The default pins for I2C(0) at the Pico are scl=Pin(9), sda=Pin(8). Please be awarm that the Pin numbers are GPIO numbers. So GPIO(8) is at board pins # 11. The difference between the results of the int and float version is minor and in any case much smaller than the measurement error of the sensor.
Thanks Roberthh. :)

Post Reply