Page 1 of 5

Bosch BME280 driver

Posted: Wed Jan 20, 2016 11:43 pm
by oscarBravo
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

Re: Bosch BME280 driver

Posted: Thu Jan 21, 2016 11:54 am
by Turbinenreiter
Nice! As far as I know the BMP280 should work with the same code, except the humidity.

Re: Bosch BME280 driver

Posted: Sun Jan 31, 2016 2:19 pm
by JimTal001
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

Re: Bosch BME280 driver

Posted: Sun Jan 31, 2016 10:38 pm
by JimTal001
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.

Re: Bosch BME280 driver

Posted: Mon Feb 01, 2016 11:03 am
by Turbinenreiter
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.

Re: Bosch BME280 driver

Posted: Mon Feb 01, 2016 5:34 pm
by JimTal001
Thanks Turbinenreiter, I did not see this in the literature.

Re: Bosch BME280 driver

Posted: Sun May 08, 2016 6:11 pm
by jwissing
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.

Re: Bosch BME280 driver

Posted: Sat May 21, 2016 11:47 pm
by catdog2
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.

Re: Bosch BME280 driver

Posted: Wed Jul 20, 2016 8:02 pm
by warren
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...

Re: Bosch BME280 driver

Posted: Thu Jul 21, 2016 6:47 am
by pythoncoder
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()