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.
upymar
Posts: 18
Joined: Sat Feb 04, 2017 7:47 am

Re: Bosch BME280 driver

Post by upymar » Sat Jun 03, 2017 6:45 am

I just noticed that there is 1.9 release for esp8266.
Will I have more success with it getting the BME280 to work?

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

Re: Bosch BME280 driver

Post by Roberthh » Sat Jun 03, 2017 1:39 pm

V1.9 should not behave differently. Are you sure that you loaded bme280.py completely to your file system?
Execute:

Code: Select all

import uos
uos.stat("bme280.py)"
The 7th element of the tuple is the file size. That should match the file size on your PC.

joli
Posts: 2
Joined: Tue Jul 04, 2017 10:12 am

Re: Bosch BME280 driver

Post by joli » Tue Jul 04, 2017 10:56 am

I did upload the bme280.py file via webrepl. Initially I had the same error on an esp8266 board when calling:

bme = bme280.BME280(i2c=i2c)
attributeerror: 'module' object has no attribute 'bme280'

I had to reset the board. After the reset it did work.
When I changed something in the bme280.py file I always had to reset the board after uploading it to the esp8266 board.
Does anyone know why it only works after a reboot/reset?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Bosch BME280 driver

Post by pythoncoder » Thu Jul 06, 2017 8:00 am

That's how Python works. Try the following under Python 3 on a PC. Create this file:
rats29.py:

Code: Select all

def foo():
    print('foo 1')
At the REPL issue

Code: Select all

import rats29
rats29.foo()
It will print "foo 1".
Now edit rats29.py to print something else. You'll find it still prints "foo 1" until you start a new Python session or reload the module. See https://stackoverflow.com/questions/437 ... ule#437591 for more information on reloading and its pitfalls. There is no equivalent in MicroPython and, as the link indicates, a reset is the best way.
Peter Hinch
Index to my micropython libraries.

upymar
Posts: 18
Joined: Sat Feb 04, 2017 7:47 am

Re: Bosch BME280 driver

Post by upymar » Mon Sep 04, 2017 11:55 am

I tried it again with micropython release 1.9.2 on my esp8266

What has changed is that

Code: Select all

>>> import machine
>>> import bme280
seems to work correctly now.

But I am very unsure about the correct I2C wiring.
I have a BME280 for I2C and SPI from adafruit that has the following pinout:
VIN, 3Vo, GND, SCK, SDO, SDI, CS

Besides VIN and GND I connected SCK to D1 (GPIO5) and SDI to D2 (GPIO4).

After

Code: Select all

>>> i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
>>> bme = bme280.BME280(i2c=i2c)
I get:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bme280.py", line 74, in __init__
OSError: [Errno 19] ENODEV
I think that the pins in

Code: Select all

>>> i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
aren't correct but I don't know better.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Bosch BME280 driver

Post by deshipu » Mon Sep 04, 2017 12:59 pm

Does i2c.scan() return anything? The wiring seems correct, comparing with https://learn.adafruit.com/adafruit-bme ... g-and-test

upymar
Posts: 18
Joined: Sat Feb 04, 2017 7:47 am

Re: Bosch BME280 driver

Post by upymar » Tue Sep 05, 2017 6:30 am

Thanks for your reply.
deshipu wrote:Does i2c.scan() return anything?

Code: Select all

>>> import machine
>>> import bme280
>>> i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
>>> i2c.scan()
[119]
Does this help?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Bosch BME280 driver

Post by deshipu » Tue Sep 05, 2017 2:58 pm

Well, your driver defaults to address 118 (0x76), so maybe try this:

Code: Select all

bme = bme280.BME280(i2c, address=119)

upymar
Posts: 18
Joined: Sat Feb 04, 2017 7:47 am

Re: Bosch BME280 driver

Post by upymar » Wed Sep 06, 2017 6:42 am

deshipu wrote:Well, your driver defaults to address 118 (0x76), so maybe try this:

Code: Select all

bme = bme280.BME280(i2c, address=119)
Thank you so much, this did help me a lot.

I changed your suggestion (that didn't work)

Code: Select all

bme = bme280.BME280(i2c, address=119)
to

Code: Select all

bme = bme280.BME280(i2c=i2c, address=119)
and it works.

Thanks and have a nice day

vahithosan
Posts: 19
Joined: Wed Jul 26, 2017 5:15 pm

Re: Bosch BME280 driver

Post by vahithosan » Mon Sep 18, 2017 1:57 pm

Hi. I am using the BME280 sensor with ESP-12.

i measure indoor. (unused room) and the place of the esp board does not change

Im running script one per hour an goes deepsleep.

I use 2 lipo battery and HT7333 ldo.

My questions is why the pressure values are unstable.

Code: Select all

DATE						TEMP		HUM	PRESSURE
2017-09-18 12:30:05	22.37	48.56	905.53
2017-09-18 11:30:03	22.34	48.54	905.51
2017-09-18 10:30:03	22.33	47.78	906.03
2017-09-18 09:30:04	21.95	47.27	906.07
2017-09-18 08:30:03	21.91	47.25	906.13
2017-09-18 07:30:05	21.92	46.88	905.95
2017-09-18 06:30:03	21.99	46.88	905.57
2017-09-18 05:30:04	22.18	47.53	905.47
2017-09-18 04:30:17	22.15	47.52	905.46
2017-09-18 03:30:03	22.23	47.88	904.46
2017-09-18 02:30:02	22.32	48.18	905.47
2017-09-18 01:30:02	22.44	48.24	905.72
2017-09-18 00:30:02	22.59	48.34	905.79
2017-09-17 22:30:07	22.68	49.32	905.85
2017-09-17 21:30:03	22.70	49.51	906.45
2017-09-17 20:30:02	22.83	49.25	905.34
2017-09-17 19:30:02	22.94	49.23	904.63
2017-09-17 18:30:02	23.68	46.66	903.78
2017-09-17 17:30:02	23.64	46.65	903.80
2017-09-17 16:30:02	23.53	46.66	903.86
2017-09-17 15:30:04	22.37	48.57	904.82
2017-09-17 14:30:02	22.33	48.56	904.84
2017-09-17 13:30:02	22.19	48.55	905.46
2017-09-17 12:30:02	22.11	48.43	906.13
2017-09-17 11:30:02	22.05	48.07	906.80
2017-09-17 10:30:03	21.87	46.71	907.55
2017-09-17 09:30:02	21.84	46.71	907.52
2017-09-17 08:30:02	21.60	45.73	907.23
2017-09-17 07:30:02	21.62	45.75	907.16
2017-09-17 06:30:02	21.73	46.05	906.85
2017-09-17 05:30:02	21.80	46.46	905.99
2017-09-17 04:30:02	21.90	47.28	906.91
2017-09-17 03:30:02	22.14	48.44	906.70
2017-09-17 02:30:02	22.11	48.44	906.72
2017-09-17 01:30:04	22.37	49.31	906.85
2017-09-17 00:30:02	22.34	49.31	906.43
2017-09-16 23:30:02	22.43	50.92	905.60
2017-09-16 22:30:02	22.59	52.17	906.71
2017-09-16 21:30:02	22.95	52.58	906.48
Thanks

Post Reply