Bosch BME280 driver
-
- Posts: 1
- Joined: Wed Jan 20, 2016 11:41 pm
Bosch BME280 driver
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
Hopefully someone else will find it useful.
https://bitbucket.org/oscarBravo/wipy_bme280
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: Bosch BME280 driver
Nice! As far as I know the BMP280 should work with the same code, except the humidity.
Re: Bosch BME280 driver
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:
Thanks
Also, The original Adafruit driver sets the I2C address as:
and your driver for the WiPy uses:# BME280 default address.
BME280_I2CADDR = 0x77
Can you explain why you changed the address?# BME280 default address.
BME280_I2CADDR = 0x76
Thanks
Re: Bosch BME280 driver
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.
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: Bosch BME280 driver
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
Thanks Turbinenreiter, I did not see this in the literature.
Re: Bosch BME280 driver
Thank you Oscar for your driver.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
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)
Re: Bosch BME280 driver
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.
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
Hicatdog2 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.
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'
Thank you...
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Bosch BME280 driver
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
Index to my micropython libraries.
Index to my micropython libraries.