Code Monkey home page Code Monkey logo

micropython-bmp280's Introduction

micropython-bmp280

Inspired by
https://github.com/vitally/BMP280
https://github.com/micropython-IMU/micropython-bmp180

Constructor

BMP280(i2c_bus, addr=0x76, use_case=BMP280_CASE_HANDHELD_DYN)

  • i2c_bus - the I2C bus to use
  • addr - I2C address of the BMP280 (always the same)
  • use_case - Use case to start the BMP280 with. Set to None to disable measuring on boot.

Enums

Values for different settings are defined in the following constants. Reference to manual section in parenthesis.

Use cases (See 3.4, 3.8.2)

  • BMP280_CASE_HANDHELD_LOW
  • BMP280_CASE_HANDHELD_DYN (default)
  • BMP280_CASE_WEATHER
  • BMP280_CASE_FLOOR
  • BMP280_CASE_DROP
  • BMP280_CASE_INDOOR

Oversampling setting (See 3.3.1, 3.8.2)

  • BMP280_OS_ULTRALOW
  • BMP280_OS_LOW
  • BMP280_OS_STANDARD
  • BMP280_OS_HIGH
  • BMP280_OS_ULTRAHIGH

Pressure oversampling (See 3.3.1)

  • BMP280_PRES_OS_SKIP
  • BMP280_PRES_OS_1
  • BMP280_PRES_OS_2
  • BMP280_PRES_OS_4
  • BMP280_PRES_OS_8
  • BMP280_PRES_OS_16

Temperature oversampling (See 3.3.2)

  • BMP280_TEMP_OS_SKIP
  • BMP280_TEMP_OS_1
  • BMP280_TEMP_OS_2
  • BMP280_TEMP_OS_4
  • BMP280_TEMP_OS_8
  • BMP280_TEMP_OS_16

IIR filter (See 3.3.3)

  • BMP280_IIR_FILTER_OFF
  • BMP280_IIR_FILTER_2
  • BMP280_IIR_FILTER_4
  • BMP280_IIR_FILTER_8
  • BMP280_IIR_FILTER_16

Standby settings for Normal measure (See 3.6.3)

  • BMP280_STANDBY_0_5
  • BMP280_STANDBY_62_5
  • BMP280_STANDBY_125
  • BMP280_STANDBY_250
  • BMP280_STANDBY_500
  • BMP280_STANDBY_1000
  • BMP280_STANDBY_2000
  • BMP280_STANDBY_4000

Power modes

  • BMP280_POWER_SLEEP
  • BMP280_POWER_FORCED
  • BMP280_POWER_NORMAL

SPI 3-wire select

  • BMP280_SPI3W_ON
  • BMP280_SPI3W_OFF

Example

from machine import I2C
from bmp280 import *

bus = I2C()
bmp = BMP280(bus)

bmp.use_case(BMP280_CASE_WEATHER)
bmp.oversample(BMP280_OS_HIGH)

bmp.temp_os = BMP280_TEMP_OS_8
bmp.press_os = BMP280_PRES_OS_4

bmp.standby = BMP280_STANDBY_250
bmp.iir = BMP280_IIR_FILTER_2

bmp.spi3w = BMP280_SPI3W_ON

bmp.power_mode = BMP280_POWER_FORCED
# or 
bmp.force_measure()

bmp.power_mode = BMP280_POWER_NORMAL
# or 
bmp.normal_measure()
# also
bmp.in_normal_mode()

bmp.power_mode = BMP280_POWER_SLEEP
# or 
bmp.sleep()

print(bmp.temperature)
print(bmp.pressure)

#True while measuring
bmp.is_measuring

#True while copying data to registers
bmp.is_updating

TODO

  • SPI support
  • Filters
  • Oversampling settings (half done)
  • Power modes
  • Standby setting for Normal mode

micropython-bmp280's People

Contributors

dafvid avatar mobley-m 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  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

micropython-bmp280's Issues

Typo in use_case argument to constructor?

if use_case is None:

Looking through the code base as I'm looking for a package that does what I expect I saw this line and wondered if it should read:

        if use_case is not None:
            self.use_case(use_case)

I haven't tested either way yet, that is on the plan for tomorrow...

EDIT:
Apologies I didn't see #3 conversation. Will move to conversation on the PR.

Some chips may be at address 0x77 vs 0x76

I have BMP280 that is actually one of the hybrids with an AHT20 Temp/Hum and a BMP280 Temp/Pressure sensor combined. https://universal-solder.ca/aht20-bmp280-sensor-replaces-bme280/. There is note "The I2C address for AHT20 is 0x38, for BMP280 it can be 0x76 or 0x77." and my board turned out to be 0x77. Changing the address in line def __init__(self, i2c_bus, addr=0x77, use_case=BMP280_CASE_HANDHELD_DYN): got it working. Thank you for your useful library.

Raspberry Pico

Hi, I get the following error when using the example code in RPi Pico:

Traceback (most recent call last): File "<stdin>", line 10, in <module> File "bmp280.py", line 97, in __init__ File "bmp280.py", line 126, in _read OSError: 5

The bmp280 is visible with i2c.scan()

Also the example code should have
import bmp280

otherwise the variables are not loaded, only the class.

Fehlermeldeung bei bus = I2C()

Hallo,
vorab bin Anfänger!, also nehmt mir mir meine Unwissenheit nicht allzu übel.
Erfasse mit einem ESP32 und einem BMP280 die Temperatur. Bin aber nicht zufrieden mit den Meßergebnissen. Nun bich ich auf dieses Programm gestossen.
habe bisher I2C wie folgt aufgerufen:

i2c0_sda = Pin(26)
i2c0_scl = Pin(27)
i2c0 = I2C(0, sda = i2c0_sda, scl = i2c0_scl, freq = 10000)

und den Sensor:
bmp280_i2c = BMP280I2C(0x77, i2c0)

Wenn ich diesen Code aufrufe, erscheint schon bei:
bus = I2C()
eine Fehlermeldung:
TypeError: 'scl' argument required
Wie gesagt Anfänger!!!
Sicherlich muß ich noch Werte für das Argument eingeben, blos welche?

Gruß Klaus

swap t_os and p_os

Line 54-55 in bmp280.py is :

_BMP280_OS_MATRIX = [
    [BMP280_PRES_OS_1, BMP280_TEMP_OS_1, 7],

But line 315 is:

        t_os, p_os, self.read_wait_ms = _BMP280_OS_MATRIX[oss]

t_os and p_os should be swapped. Line 316 and 317 are correct. Bits 7-5 are osrs_t and bits 4-2 are osrs_p according to the datasheet of bmp280.
The following patch should be able to fix this issue:

--- bmp280.py.orig	2022-04-26 06:07:08.000000000 +0800
+++ bmp280.py	2022-05-02 06:43:07.000000000 +0800
@@ -312,11 +312,11 @@
     def use_case(self, uc):
         assert 0 <= uc <= 5
         pm, oss, iir, sb = _BMP280_CASE_MATRIX[uc]
-        t_os, p_os, self.read_wait_ms = _BMP280_OS_MATRIX[oss]
+        p_os, t_os, self.read_wait_ms = _BMP280_OS_MATRIX[oss]
         self._write(_BMP280_REGISTER_CONFIG, (iir << 2) + (sb << 5))
         self._write(_BMP280_REGISTER_CONTROL, pm + (p_os << 2) + (t_os << 5))
 
     def oversample(self, oss):
         assert 0 <= oss <= 4
-        t_os, p_os, self.read_wait_ms = _BMP280_OS_MATRIX[oss]
+        p_os, t_os, self.read_wait_ms = _BMP280_OS_MATRIX[oss]
         self._write_bits(_BMP280_REGISTER_CONTROL, p_os + (t_os << 3), 2)

Move constants to constants.py

When I added all the constants from the spec the file grew quite a bit. I'm considering seperating them into a separate file you can use if you need them. This would reduce the file so that it can be more easily used on SoC with restricted storage.

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.