Bosch BME280 driver

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
oscarBravo
Posts: 1
Joined: Wed Jan 20, 2016 11:41 pm

Bosch BME280 driver

Postby oscarBravo » Wed Jan 20, 2016 11:43 pm

I needed to interface a BME280 environmental sensor to my WiPy, so I modified Adafruit's driver (written for Raspberry Pi) to work on MicroPython.

Hopefully someone else will find it useful.

https://bitbucket.org/oscarBravo/wipy_bme280

Turbinenreiter
Posts: 260
Joined: Sun May 04, 2014 8:54 am

Re: Bosch BME280 driver

Postby Turbinenreiter » Thu Jan 21, 2016 11:54 am

Nice! As far as I know the BMP280 should work with the same code, except the humidity.

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: Bosch BME280 driver

Postby JimTal001 » Sun Jan 31, 2016 2:19 pm

Great job! I am interested to use the same sensor with the pyboard. Will the driver require much change to work with the pyboard? If so, would you be willing to suggest the appropriate changes?

Also, The original Adafruit driver sets the I2C address as:
# BME280 default address.
BME280_I2CADDR = 0x77


and your driver for the WiPy uses:
# BME280 default address.
BME280_I2CADDR = 0x76


Can you explain why you changed the address?

Thanks

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: Bosch BME280 driver

Postby JimTal001 » Sun Jan 31, 2016 10:38 pm

I believe I now have the pyboard working with the BME280 sensor. The data seems to be slightly off compared to measurements. If you are interested to review the code and add it to your bitbucket site I will post it.

Turbinenreiter
Posts: 260
Joined: Sun May 04, 2014 8:54 am

Re: Bosch BME280 driver

Postby Turbinenreiter » Mon Feb 01, 2016 11:03 am

The I2C address can be changed by bringing a pin of the sensor high or low. It's done so you have an option to change the address in case you have another device with a conflicting address on the same bus. So the address depends on how the breakout you use chose to handle this pin. Often there is a jumper so you can switch it.

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: Bosch BME280 driver

Postby JimTal001 » Mon Feb 01, 2016 5:34 pm

Thanks Turbinenreiter, I did not see this in the literature.

User avatar
jwissing
Posts: 29
Joined: Thu Jun 19, 2014 12:23 pm
Location: Germany

Re: Bosch BME280 driver

Postby jwissing » Sun May 08, 2016 6:11 pm

oscarBravo wrote:I needed to interface a BME280 environmental sensor to my WiPy, so I modified Adafruit's driver (written for Raspberry Pi) to work on MicroPython.

Hopefully someone else will find it useful.

https://bitbucket.org/oscarBravo/wipy_bme280

Thank you Oscar for your driver.
It helped a lot for my weekend project.
It is also running on the ESP12E port with some slight modifications.

Code: Select all

    def writeRaw8(self, value):
        """Write an 8-bit value on the bus (without register)."""
        buf = bytearray(1)
        buf[0] = value & 0xFF
        self._i2c.writeto(self._address, buf)

    def write8(self, register, value):
        """Write an 8-bit value to the specified register."""
        buf = bytearray(1)
        buf[0] = value & 0xFF
        self._i2c.writeto_mem(self._address, register, buf)

The ESP port needs to have a bytearray as parameter on these methods.

catdog2
Posts: 2
Joined: Sat May 21, 2016 11:17 pm

Re: Bosch BME280 driver

Postby catdog2 » Sat May 21, 2016 11:47 pm

I have modified the driver quite a bit for the ESP8266:

https://github.com/catdog2/mpy_bme280_esp8266

The main goal was to make It less memory hungry, especially during import. Worked I think. I only tested it with a BMP280 as I don't possess a BME280 yet.

warren
Posts: 73
Joined: Tue Jul 12, 2016 5:47 pm

Re: Bosch BME280 driver

Postby warren » Wed Jul 20, 2016 8:02 pm

catdog2 wrote:I have modified the driver quite a bit for the ESP8266:

https://github.com/catdog2/mpy_bme280_esp8266

The main goal was to make It less memory hungry, especially during import. Worked I think. I only tested it with a BMP280 as I don't possess a BME280 yet.

Hi

I am running an ESP8266 with a bmp280 - and have copied your code into bme280.py.

I get this error when I run your suggested code:

Code: Select all

=== import machine
=== import bme280
===
=== i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
=== bme = bme280.BME280(i2c=i2c)
===
=== print(bme.values)
===
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
AttributeError: 'module' object has no attribute 'BME280'

Any ideas?

Thank you...

User avatar
pythoncoder
Posts: 1564
Joined: Fri Jul 18, 2014 8:01 am

Re: Bosch BME280 driver

Postby pythoncoder » Thu Jul 21, 2016 6:47 am

Assuming you've double checked that bme280.py on the ESP8266 is correct, I suspect you have run out of RAM. Are you running it from webrepl? It might be worth not running webrepl and using a direct connection. Executing the following after the error may be informative:

Code: Select all

import micropython
micropython.mem_info()
Peter Hinch


Return to “Drivers for External Components”

Who is online

Users browsing this forum: No registered users and 1 guest