Coder Social home page Coder Social logo

pimoroni / bme280-python Goto Github PK

View Code? Open in Web Editor NEW
63.0 63.0 25.0 65 KB

Python library for the BME280 temperature, pressure and humidity sensor

Home Page: https://shop.pimoroni.com/products/bme280-breakout

License: MIT License

Makefile 5.14% Shell 42.53% Python 52.33%
pypi-package

bme280-python's People

Contributors

gadgetoid avatar iohe avatar lionsphil avatar ptorru avatar sandyjmacdonald avatar tanyafish 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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bme280-python's Issues

Breakout board BME280

Hi Team,

I have a basic question.
Do we need to externally connect pull up resistors to establish a I2C communication ?
I see the break out board already having some SMD along with sensor and Diodes..
Are the terminals output points already having the pullup resistors ?
I am using a NXPk66F dev board.

Raspberry Pi hangs in forced mode

I'm finding that when I'm using the library in forced mode after a number of sensor reads, the Raspberry Pi hangs.

Is there a known issue with repeatedly reading the sensor in forced mode? I'm reading the sensor every minute, but after a while something is locking up the Raspberry Pi.

install.sh error

On Rasbian: 2019-09-26-raspbian-buster-lite

As per install instructions

sudo pip install pimoroni-bme280
git clone https://github.com/pimoroni/bme280-python
cd bme280-python
sudo ./install.sh

Error received:

...
Installing for Python 3..
Traceback (most recent call last):
  File "setup.py", line 26, in <module>
    from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 28, in <module>
    from distutils.core import setup
ModuleNotFoundError: No module named 'distutils.core'
Done!

Should setup() be called on each update?

Hi,

When updating the sensor values the setup method is called before triggering a measurement when in forced mode, and reading the latest values.

def update_sensor(self):
self.setup()
if self._mode == "forced":
self._bme280.set('CTRL_MEAS', mode="forced")
while self._bme280.get('STATUS').measuring:
time.sleep(0.001)

Calling the method with no arguments will overwrite any arguments you may have set previous with the defaults (including setting normal mode, so it looks like the force mode logic in the if block in update_sensor may never be called) and forces a 0.1s sleep. Is it necessary to call setup this way every time?

test.py example is broken

from bme280 import _bme280, CHIP_ID fails to import _bme280. The fix is to instantiate the BME280 class and then access _bme280 through that.

ImportError

Trying to run some examples, but not working real well
pi@Grow4:~/bme280-python/examples $ ls all-values.py dump-calibration.py relative-altitude.py temperature-forced-mode.py compensated-temperature.py local_altitude.py temperature-compare.py pi@Grow4:~/bme280-python/examples $ python compensated-temperature.py Traceback (most recent call last): File "/home/pi/bme280-python/examples/compensated-temperature.py", line 6, in <module> from bme280 import BME280 ImportError: cannot import name 'BME280' from 'bme280' (/usr/local/lib/python3.9/dist-packages/bme280/__init__.py) pi@Grow4:~/bme280-python/examples $ python dump-calibration.py Traceback (most recent call last): File "/home/pi/bme280-python/examples/dump-calibration.py", line 7, in <module> from bme280 import BME280 ImportError: cannot import name 'BME280' from 'bme280' (/usr/local/lib/python3.9/dist-packages/bme280/__init__.py) pi@Grow4:~/bme280-python/examples $ python relative-altitude.py Traceback (most recent call last): File "/home/pi/bme280-python/examples/relative-altitude.py", line 9, in <module> from bme280 import BME280 ImportError: cannot import name 'BME280' from 'bme280' (/usr/local/lib/python3.9/dist-packages/bme280/__init__.py) pi@Grow4:~/bme280-python/examples $
Jeff

ValueError: Invalid format specifier when running allvalues.py

installed the PIMORONI BME280 breakout on pins 1, 3, 5, 7, 9, on my RaspberryPI-4 however - when I run the allvalues.py example i get the following error:

Ctrl+C to exit
Traceback (most recent call last):
File "/home/pi/BME280 test.py", line 19, in
print('{:05.2f}*C {:05.2f}hPa {:05:2f}%'.format(temperature, pressure, humidity))
ValueError: Invalid format specifier

ROCK 4 C+

Would I be able to use this on a different SBC, I have a ROCK 4 C+ and looking to use this in a waveguide dehydrator monitoring project

Binho Nova adapter instructions

Not submitting this as a PR to the documentation as I'm not confident in it at all, but wanted to capture this atrocity I've just cooked up, to read a BME280 via the Binho Nova host adapter's Python library:

class BinhoSmbusShim:
    def __init__(self, host_adapter):
        self.binho = host_adapter
    def read_i2c_block_data(self, i2c_address, register, length):
        return self.binho.i2c.transfer(i2c_address, [register], length)

    def write_i2c_block_data(self, i2c_address, register, values):
        self.binho.i2c.transfer(i2c_address, [register] + values, 0)

Usage instructions:

    binho = binhoHostAdapter()
    binho.operationMode = "I2C"

    bme280 = BME280(i2c_dev=BinhoSmbusShim(binho))
    bme280.setup()
    # you can now follow examples/

Fairly confident this glosses over a lot of details (like register width?), but this was enough to get temperature/humidity/pressure out of the sensor so I can carry on with software.

I'm also aware you're no longer stocking Binho Nova, so no worries if you don't want to add in support/documentation for use โ€” this note is just to capture this info in the public domain for next time I need it ๐Ÿ™ˆ

ImportError: No module named bme280 when running all-values.py

Fresh install of the latest PiOS on a Pi Zero W.
pHat Stack with Breakout Garden Mini i2c SPI and Mini i2c
BME280, RV3028, LTR-599 in the mini i2c BG
0.96 SPI Color LCD in the mini i2c SPI BG

My BME280 breakout is giving me the following error when I run the all-values.py file.
Either from thoony or via command line.

from bme280 import BME280
ImportError: No module named bme280

i2c is enabled and it is detected.
I have run the following.
sudo pip install pimoroni-bme280 smbus
sudo pip3 install pimoroni-bme280 smbus
and also did the following
git clone https://github.com/pimoroni/bme280-python
cd bme280-python
sudo ./install.sh
and rebooted several times.
Tried two different BME280โ€™s, one that was working before I reimaged my SD card, and one new one I just received today.
Both give the above error.

bme280

please could somone guide me though the procedure on running the python programm all-values.py from the sample programs
bit new to the pi and what sudo etc amd what program i use to run to work the bme280

help gladly taken

Unable to find bme280 on 0x76, CHIP_ID returned 58

Hi there,

Started playing with bme280 - I can't initialise it correctly on my RPI + Breakout Garden + BME280 (and a few others breakout)

#!/usr/bin/env python3

# std lib imports
import os
import logging
import argparse
import sys
import time

# extra imports
try:
    from smbus2 import SMBus
except ImportError:
    from smbus import SMBus

from bme280 import BME280

# Set logs
logger = logging.getLogger('bme280')
logger.setLevel(logging.INFO)
# Log format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Console Handler
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch.setFormatter(formatter)
logger.addHandler(ch)


def temperature():
    # Initialise the BME280
    bus = SMBus(1)
    bme280 = BME280(i2c_dev=bus)

    temperature = bme280.get_temperature()
    pressure = bme280.get_pressure()
    humidity = bme280.get_humidity()
    print('{:05.2f}*C {:05.2f}hPa {:05.2f}%'.format(temperature, pressure, humidity))
    time.sleep(1)

def main():
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--url', default="http://localhost", help="url")
    args = parser.parse_args()
    """

    temperature()

if __name__ == "__main__":
    main()

Leads to:

Traceback (most recent call last):
  File "/home/pi/airborne/airborne/environment.py", line 52, in <module>
    main()
  File "/home/pi/airborne/airborne/environment.py", line 49, in main
    temperature()
  File "/home/pi/airborne/airborne/environment.py", line 36, in temperature
    temperature = bme280.get_temperature()
  File "/home/pi/.local/lib/python3.9/site-packages/bme280/__init__.py", line 264, in get_temperature
    self.update_sensor()
  File "/home/pi/.local/lib/python3.9/site-packages/bme280/__init__.py", line 250, in update_sensor
    self.setup()
  File "/home/pi/.local/lib/python3.9/site-packages/bme280/__init__.py", line 228, in setup
    raise RuntimeError("Unable to find bme280 on 0x{:02x}, CHIP_ID returned {:02x}".format(self._i2c_addr, chip.id))
RuntimeError: Unable to find bme280 on 0x76, CHIP_ID returned 58

whereas it's on 0X76:

i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: 10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --                         

Any changes on the chip that should be updated in the lib ?

Thanks

Double call of update_sensor() when getting altitude

Hi,

I noticed that update_sensor() appears to be called twice in a row when calling get_altitude. First self.update_sensor() is called followed by self.get_pressure(),

def get_altitude(self, qnh=1013.25):
self.update_sensor()
pressure = self.get_pressure()
altitude = 44330.0 * (1.0 - pow(pressure / qnh, (1.0 / 5.255)))
return altitude

However, the first line of get_pressure is also self.update_sensor(),

def get_pressure(self):
self.update_sensor()
return self.pressure

So, if we unrolled this we would get something like

self.update_sensor()
self.update_sensor()
pressure = self.pressure

I'm happy to open a PR changing this if it isn't intended.

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.