Giter VIP home page Giter VIP logo

adafruit_circuitpython_bme280's People

Contributors

anecdata avatar barbudor avatar brennen avatar dhalbert avatar evaherrada avatar foamyguy avatar gbaman avatar janhbade avatar jerryneedell avatar jposada202020 avatar jraber avatar kattni avatar keiththeee avatar kmatch98 avatar ladyada avatar makermelissa avatar mrmcwethy avatar robert-hh avatar rsbohn avatar sommersoft avatar tannewt avatar tdicola avatar tekktrik avatar thekitty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_bme280's Issues

Did something with this project recently change? The examples no longer work.

I used the examples here as a starting point for a project on a raspberry pi over a year ago, it has worked without issue.

https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/main/examples/bme280_simpletest.py

I recently tried to recreate the project on another raspberry pi but this library seems to have changed?

I installed it like this:

pip3 install smbus2 adafruit-circuitpython-bme280

before I had these lines:

import adafruit_bme280
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76)

now I have:

import Adafruit_BME280
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = Adafruit_BME280.Adafruit_BME280_I2C(i2c, 0x76)

Notice I had to capitalize the library, which is fine however I am now seeing:

AttributeError: module 'Adafruit_BME280' has no attribute 'Adafruit_BME280_I2C'

additionally the guide on the main page for this project appears to be out of date as well: https://github.com/adafruit/Adafruit_CircuitPython_BME280#usage-example

Really appreciate any help on this, Thanks a Ton!

Minor reduction in memory footprint to make library more viable with adafruit_rfm9x on M0 processors

This library is used in the guide article, Adafruit Learn: Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN. It is being discussed in Adafruit Forums: Memory Error Lora_Device with BME280 as the CircuitPython code in the guide hits a MemoryError.

File "code.py", line 15, in <module>
File "adafruit_bme280.py", line 499, in <module>
File "adafruit_bme280.py", line 517, in Adafruit_BME280_SPI
MemoryError:

If everything is working as expected here then shrinking adafruit_rfm9x or adafruit_bme280 are the only options to get this working.

Some ideas:

  • The raise ValueError in all the setters currently have a specific message per property. This could be made generic and then six strings get condensed into one.
  • You could try putting the i2c/spi classes in separate files but I've got a vague feeling this would make it worse.
  • For the private methods with underscore prefixes (i.e. ones not part of the interface which is already in use by applications) you could abbreviate them more as these end repeatedly in the mpy. If desperation reaches this stage I'd verify this has some effect with a gc.collect() ; print(mem_free()).

@brentru and @jerryneedell might have some other or better ideas on this.

Documentation

Hey πŸ‘‹

I note that this is missing Pydoc.

I'm happy to go through and add some if that would be useful? :)

[Errno 121] Reoccur

Dear all,

I use the Adafruit CircuitPython Ecosystem now with a whole strip of sensors:
1x BME280, 1x LSM9DS1, 2x INA219 (one as 0x40, one as 0x41) and a DS3231 - which is currently not actively pulled. I actively try to get data from all sensors as fast as possible and save this info in a dict.
All is run on a Raspberry Pi Zero W, with current drivers and dependencies.

Adafruit-Blinka==3.3.4
adafruit-circuitpython-bme280==2.3.2
adafruit-circuitpython-busdevice==4.1.1
adafruit-circuitpython-ds3231==2.1.3
adafruit-circuitpython-ina219==3.3.0
adafruit-circuitpython-lsm9ds1==2.0.5
adafruit-circuitpython-register==1.7.1
Adafruit-PlatformDetect==1.3.8
Adafruit-PureIO==1.0.4
pyftdi==0.42.2
pyusb==1.0.2
rpi-ws281x==4.2.2
spidev==3.4
sysv-ipc==1.0.1

After some time, the whole script "dies", always pointing to the BME280 lib, which seems to be similiar to #15

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "sensorTest.py", line 41, in gpioThreadFunc
    tlm["bt"], tlm["bp"], tlm["ba"], tlm["bh"]  = bme280.temperature, bme280.humidity, bme280.pressure, bme280.altitude
  File "/usr/lib/python3.7/site-packages/adafruit_bme280.py", line 335, in pressure
    self._read_temperature()
  File "/usr/lib/python3.7/site-packages/adafruit_bme280.py", line 143, in _read_temperature
    while self._get_status() & 0x08:
  File "/usr/lib/python3.7/site-packages/adafruit_bme280.py", line 172, in _get_status
    return self._read_byte(_BME280_REGISTER_STATUS)
  File "/usr/lib/python3.7/site-packages/adafruit_bme280.py", line 426, in _read_byte
    return self._read_register(register, 1)[0]
  File "/usr/lib/python3.7/site-packages/adafruit_bme280.py", line 451, in _read_register
    i2c.write(bytes([register & 0xFF]))
  File "/usr/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py", line 98, in write
    self.i2c.writeto(self.device_address, buf, **kwargs)
  File "/usr/lib/python3.7/site-packages/busio.py", line 84, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/usr/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 38, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 256, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

Test Code:

from time import sleep, time
import threading
import board
import busio
import adafruit_bme280
import adafruit_lsm9ds1
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
#import adafruit_ds3231
import json
tlm = {}

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA, frequency=400000)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
lsm9ds1 = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
ina219 = INA219(i2c)
ina219b = INA219(i2c, 0x41)

def i2c_writeNumber(value):
	value = chr(value)
	i2c.writeto(0x26,value)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
# optional : change voltage range to 16V
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V

# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
ina219b.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina219b.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
# optional : change voltage range to 16V
ina219b.bus_voltage_range = BusVoltageRange.RANGE_16V

def gpioThreadFunc():
	while True:
		#print("BME280")
		tlm["bt"], tlm["bp"], tlm["ba"], tlm["bh"]  = bme280.temperature, bme280.humidity, bme280.pressure, bme280.altitude
		
		sleep(0.01)
		#print("LSM9DS1")
		# Read acceleration, magnetometer, gyroscope, temperature.
		tlm["ax"], tlm["ay"], tlm["az"] = lsm9ds1.acceleration
		tlm["mx"], tlm["my"], tlm["mz"] = lsm9ds1.magnetic
		tlm["gx"], tlm["gy"], tlm["gz"] = lsm9ds1.gyro

		sleep(0.01)
		tlm["5b"], tlm["5s"], tlm["5c"] = ina219.bus_voltage, ina219.shunt_voltage, ina219.current

		sleep(0.01)
		tlm["3b"], tlm["3s"], tlm["3c"] = ina219b.bus_voltage, ina219b.shunt_voltage, ina219b.current

		sleep(0.01)		
		print(tlm)
		i2c_writeNumber(1)
		#sleep(0.05)
		#sleep(0.75)


def mainThreadFunc():
	sleep(5)


gpioThread = threading.Thread(target = gpioThreadFunc)
mainThread = threading.Thread(target = mainThreadFunc)
gpioThread.start()
mainThread.start()

The main thread is so work with the data and transform it, but I have not yet gotten so far.
Do you see anything that I am doing wrong - and if so, how can I fix it / are there besides this problems ways to enhance speed / more readings per second :)?

The only special thing I added, was to sent one byte to the i2c Device on 0x26. But other than that, it is all fairly standard.

Thanks a lot for your help and awesome work over at Adafruit!

Nico

Library uses short argument names

pylint suggests using argument names with at least 3 letters. This library uses argument names of shorter length, and while these warnings have been disabled for now, they should be considered for renaming. This may require the rework of Learn Guides and other references to code snippets.

Instructions for GY-BMP280

The GY-BMP280 (GY-BM P/E 280) and a few other similar (non-Adafruit) BMP/BME 280 boards, use the 0x76 I2C address instead of 0x77. Some tutorials I found on the web instruct changing the address in library source code. But it is trivial to make this Adafruit driver work out-of-the-box.

For example, in the 'Usage Example' code, just change this line:

bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

to this:

bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)

Perhaps it would be useful to add these instructions?

Potential sign problem with the calibration values for humidity

In line 197 of the driver, the calibration constants are unpacked with

        coeff = list(struct.unpack('<hBBBBb', bytes(coeff)))

This goes into humidity_calib[3] and humidity_calib[4], which in the Bosch data sheet are told as signed quantities. Unpacking like above results in decoding them as unsigned quantities. So this line should be:

        coeff = list(struct.unpack('<hBbBbb', bytes(coeff)))

From the data sheet:

0xE4 / 0xE5[3:0] dig_H4 [11:4] / [3:0] signed short
0xE5[7:4] / 0xE6 dig_H5 [3:0] / [11:4] signed short

I have no device where the sign bit is set, so I can only simulate the behavior.

Note: I came along these lines when considering to carry over the very elegant conversion of similar data from the BME680 driver. There, the sign is considered.

Memory error

Using a Sparkfun RedBoard T.

on import adafruit_bme280 get a Memory error.

in the REPL I get slightly more information but not much:

import adafruit_bme280
Traceback (most recent call last):
File "", line 1, in
MemoryError: memory allocation failed, allocating 512 bytes

I've stripped back to just the sample code for the BME280 so nothing else is in RAM. RAM is 256K on this board.

[Errno 121] Remote I/O error when reading temperature

I'm getting a remote I/O error when _read_temperature() is called.

The initialization (which checks the chipid) works, and I'm able to do a few other things (like read the coefficients). Also, similar code has worked from the same environment with your Si7021 breakout.

root@monitoring_server:/# python
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux


>>> import board
>>> import busio
>>> import adafruit_bme280
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
>>> bme280.humidity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bme280.py", line 161, in humidity
    self._read_temperature()
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bme280.py", line 93, in _read_temperature
    while self._read_byte(_BME280_REGISTER_STATUS) & 0x08:
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bme280.py", line 218, in _read_byte
    return self._read_register(register, 1)[0]
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bme280.py", line 243, in _read_register
    i2c.write(bytes([register & 0xFF]))
  File "/usr/local/lib/python3.5/dist-packages/adafruit_bus_device/i2c_device.py", line 102, in write
    self.i2c.writeto(self.device_address, buf, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/busio.py", line 63, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_blinka/microcontroller/raspi_23/i2c.py", line 38, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_PureIO/smbus.py", line 244, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_bme280/basic.py:173
  • adafruit_bme280/basic.py:299
  • adafruit_bme280/basic.py:303
  • adafruit_bme280/basic.py:311
  • adafruit_bme280/basic.py:314
  • adafruit_bme280/basic.py:365
  • adafruit_bme280/basic.py:371
  • adafruit_bme280/basic.py:378
  • adafruit_bme280/basic.py:433
  • adafruit_bme280/basic.py:439
  • adafruit_bme280/basic.py:447
  • adafruit_bme280/advanced.py:155
  • adafruit_bme280/advanced.py:172
  • adafruit_bme280/advanced.py:187
  • adafruit_bme280/advanced.py:202
  • adafruit_bme280/advanced.py:217
  • adafruit_bme280/advanced.py:312
  • adafruit_bme280/advanced.py:318
  • adafruit_bme280/advanced.py:326
  • adafruit_bme280/advanced.py:380
  • adafruit_bme280/advanced.py:386
  • adafruit_bme280/advanced.py:395

Wrong decoding of humitiy calibration constants

The decoding of the calubration constant dig_H5 seems wrong. The adafruit driver is:

	self._humidity_calib[4] = float(((coeff[3] & 0xF0) << 4) | coeff[4])

while the Bosch driver is:

	dig_H5_msb = (int16_t)(int8_t)reg_data[5] * 16;
	dig_H5_lsb = (int16_t)(reg_data[4] >> 4);
	calib_data->dig_H5 = dig_H5_msb | dig_H5_lsb;

Along that, the adafruit code should be:

	self._humidity_calib[4] = float((coeff[4] << 4) | (coeff[3] >> 4))

Align code in this library to Adafruit code for ESP32, ESP8266, etc.

The current Adafruit code for ESP32, ESP8266 BME280 libraries/APIs support correct calculation for sea level pressure by accepting an elevation value and pressure value. And that calculated pressure at sea level is then used for altitude result.

This library only supports a crude static value for pressure at sea level. This is functionally incorrect, and should be address. For example ESP32 and ESP8266 library by Adafruit correctly reports sea level pressure at an elevation of 41 meters for my location. But this library reports the altitude for my location as 68 meters.

needs oversampling + IIR Filter options

If I use this library and keep a log of the measurements, the temperature and humidity data are super noisy.
I tried different measurements intervals in the range [2;120] seconds, but all of it is noisy. The pressure data on the other hand is smooth.

The BME280 has support for supersampling and has a built in IIR filter, both of which help smoothing out the data. Currently the library only has supersampling enabled for humidity (hardcoded), it would be useful if the value can be set, and also for temperature and pressure. The IIR filter currently does not seem to be used?

screenshot 2019-02-12 at 10 11 12

FTDI on Linux PC

I have a genuine FTDI dongle and Ubuntu PC. Whenever the "import board" command is run I get the following error:

>>> import board
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/board.py", line 294, in <module>
raise NotImplementedError("Board not supported {}".format(board_id))
NotImplementedError: Board not supported GENERIC_LINUX_PC

Based on the online tutorial I was not expecting a problem with support for generic linux PC's. Please advise. thanks.

Support for multiple device I2C addresses

Per the library,

#    I2C ADDRESS/BITS/SETTINGS
#    -----------------------------------------------------------------------
_BME280_ADDRESS = const(0x77)
# ...

As it happens, the BME280 supports address 0x76 OR 0x77 depending on the state of the SDO pin (tied high or low). The circuit I was testing with defaulted to 0x76. For now, I solved my own problem by switching the jumper physically, but I can imagine others might have an address conflict or want two sensors or what have you.

If init-time support for non-default address sounds like a good idea to you, I can put together a PR. How is this kind of situation handled in other CircuitPython libraries?

EDIT: In fact, I guess the circuitpython BMP280 code already does exactly this. I'll put together a PR and test it physically when I get a chance. https://github.com/adafruit/Adafruit_CircuitPython_BMP280/blob/master/adafruit_bmp280.py

issue

Hello,

I am having this issue, any idea please ?

Traceback (most recent call last):
  File "/home/pi/n.py", line 16, in <module>
    bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/advanced.py", line 321, in __init__
    super().__init__(I2C_Impl(i2c, address))
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/advanced.py", line 152, in __init__
    super().__init__(proxy)
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/basic.py", line 107, in __init__
    self._read_coefficients()
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/basic.py", line 292, in _read_coefficients
    self._humidity_calib[0] = self._read_byte(0xA1)  # BME280_REGISTER_DIG_H1
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/basic.py", line 303, in _read_byte
    return self._read_register(register, 1)[0]
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/basic.py", line 314, in _read_register
    return self._bus_implementation.read_register(register, length)
  File "/home/pi/.local/lib/python3.9/site-packages/adafruit_bme280/protocol.py", line 23, in read_register
    i2c.write(bytes([register & 0xFF]))
  File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 101, in write
    self.i2c.writeto(self.device_address, buf, start=start, end=end)
  File "/usr/local/lib/python3.9/dist-packages/busio.py", line 174, in writeto
    return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
  File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 52, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 314, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

bme280.sea_level_pressure

In example "bme280_simpletest.py" I see bme280.sea_level_pressure being set in the example but I don't see it being used. This is an important feature for air pressure and elevation. I can set this variable to any number and it makes no difference in the results.

Frank

Support out of full accuracy pressure

In the datasheet for the BME280, it states the pressure range of the sensor is full accuracy 300hPa to 1100hPa, which no doubt is perfectly fine for just about everyone.
Not noticing this on the datasheet, we launched 2 BME280s on a high altitude weather balloon. The first used this library and the second used a different library.
The sensor itself quite happily returned results right down to 50hPa on the second sensor (after which the balloon burst), but the first sensor that used this library simply returned 300 at that point.

If the sensor is capable of returning values (even if outside the "full accuracy" range), would it not make sense to simply return these values instead of artificially capping it?

Temperature is simply returned no matter the value, even if it is only rated down to -40c. Funny enough, we reported down to -46c on this flight without issues!

pressure

Error in humidity calculation?

I think that the formula to calculate the calibrated humidity does not match with the c code in data-sheet of the BME280, chapter 8.1, page 49. If I am correct, var5 is multiplied one time too often into var6.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.