BME280 driver that works with ESP32?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
Blechi
Posts: 8
Joined: Mon Apr 23, 2018 5:55 pm

BME280 driver that works with ESP32?

Post by Blechi » Mon Apr 23, 2018 6:50 pm

Hi,
i'm trying to interface an ESP32 board (TT GO, latest loboris port) with a bme280 sensor (I2C, temperature, humidity, barometric pressure).
I couldn't find a driver for ESP32 so i tried the next best thing, which was catdo2's driver for the esp8266
(https://github.com/catdog2/mpy_bme280_esp8266).
Unfortunately it refuses to work.
When using bme280.py like this:

[code]
import machine
import micropython
import bme280
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
print(i2c.scan())
micropython.mem_info()
bme = bme280.BME280(i2c=i2c, address=118)
print(bme.values)
[/code]

I get this:

[code]
[80, 104, 118]

stack: 784 out of 19456
GC: total: 80000, used: 19872, free: 60128
No. of 1-blocks: 50, 2-blocks: 11, max blk sz: 530, max free sz: 2593

Traceback (most recent call last):
File "<stdin>", line 7, in <module>
AttributeError: 'module' object has no attribute 'BME280'
[/code]

My understanding is, that ESP8266 and ESP32 are slightly different animals, so that the ESP8266 code might not work as expected on ESP32.
Because my Python knowledge is basic at best, i have no idea what to do next.
Could someone more knowledgeable than me try to nudge me in the right direction?

Thank you very much in advance

Blechi

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: BME280 driver that works with ESP32?

Post by loboris » Fri Apr 27, 2018 7:58 am

BME280 driver, tested and working well, is included in the repository: bme280.py.
There is also an example of how to run it in thread.
You can also copy it to the modules directory and build it as frozen module.

Blechi
Posts: 8
Joined: Mon Apr 23, 2018 5:55 pm

Re: BME280 driver that works with ESP32?

Post by Blechi » Fri Apr 27, 2018 12:38 pm

Thank you very much for your reply.
Copying the BME280.py into the modules directory and building it as a frozen module did the trick.
Now it works fine.
Thank you again.

Post Reply