|
1 | 1 | ''' |
2 | | -PyPi Package: bmx280_spi |
3 | | -Homepage: |
4 | | -Git: |
| 2 | +# BMP280 / BME280 over SPI |
5 | 3 |
|
6 | | -TODO: Test with traditional SPI CS pins |
| 4 | +Homepage: https://www.learningtopi.com/python-modules-applications/bmx280_spi/ |
7 | 5 |
|
8 | | -Description: |
9 | | -Library to configure and collect data from BMP280 / BME280 via SPI. After |
10 | | -testing several python libraries that either didn't support BMP280 device |
11 | | -or simply failed to function, I put together yet another BMP/BME280 library. |
| 6 | +BMP280/BME280 python3 driver using the SPI bus to control and read data. |
12 | 7 |
|
| 8 | +General GPIO Pin (NOT an SPI CS) used to pull the signal pin low. The SPI CS pins do not operate properly with the SPI kernel driver. |
13 | 9 |
|
14 | | -BMP280/BME280 SPI controller library |
15 | | -BMP280 Pinout: |
| 10 | +BMP280 datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf |
| 11 | +
|
| 12 | +BME280 datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf |
| 13 | +
|
| 14 | +BMP280/BME280 Pinout: |
16 | 15 | SCL = SCK (SPI Clock) |
17 | 16 | SDO = MISO (sensor out to board in) |
18 | 17 | SDA = MOSI (sensir in to board out) |
19 | 18 | CSB = CS (select) |
20 | 19 |
|
| 20 | +Parts: |
| 21 | +- BMP280 (Temp and pressure) - https://amzn.to/3YVwblE |
| 22 | +- BME280 (Temp, pressure and humidity) - https://amzn.to/3JIxtMr |
| 23 | +
|
| 24 | +## Usage: |
| 25 | +
|
| 26 | +
|
| 27 | + # Import bmx280 SPI class |
| 28 | + from bmx280_spi import Bmx280Spi, MODE_NORMAL |
| 29 | +
|
| 30 | + # initialize device |
| 31 | + # cs_chip and cs_pin from "gpioinfo". gpiod used for platform compatibility. |
| 32 | + bmx = Bmx280Spi(spiBus=0, cs_chip=0, cs_pin=26) |
| 33 | + bmx.set_power_mode(MODE_NORMAL) |
| 34 | + bmx.set_sleep_duration_value(3) |
| 35 | + bmx.set_temp_oversample(1) |
| 36 | + bmx.set_pressure_oversample(1) |
| 37 | + bmx.set_filter(0) |
| 38 | + reading = bmx.update_reading() # returns instance of Bmx280Readings |
| 39 | + print(reading) |
| 40 | + # --or-- |
| 41 | + print(reading.temp_c, reading.temp_f, reading.pressure_psi) |
| 42 | +
|
| 43 | +## Testing |
| 44 | +Included in the module is a basic test script that can be executed with the following: |
| 45 | +
|
| 46 | + python3 -m dht11_spi [gpio] |
| 47 | +
|
| 48 | +Additional test options are available for interval, run time, dht22. Documentation is available using the "--help" option. |
| 49 | +
|
| 50 | +### Example Output |
| 51 | +
|
| 52 | + DHT11: 105/105 (100.0%): Temps (min/avg/max): 73.54/75.2/75.34 deg FHumidity (min/avg/max): 17.0/17.0/17.0 % |
| 53 | + DHT22: 112/112 (100.0%): Temps (min/avg/max): 74.48/74.51/74.66 deg FHumidity (min/avg/max): 14.1/14.21/16.0 % |
| 54 | +
|
| 55 | +MIT License |
| 56 | +
|
| 57 | +Copyright (c) 2023 LearningToPi |
| 58 | +
|
| 59 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 60 | +of this software and associated documentation files (the "Software"), to deal |
| 61 | +in the Software without restriction, including without limitation the rights |
| 62 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 63 | +copies of the Software, and to permit persons to whom the Software is |
| 64 | +furnished to do so, subject to the following conditions: |
| 65 | +
|
| 66 | +The above copyright notice and this permission notice shall be included in all |
| 67 | +copies or substantial portions of the Software. |
| 68 | +
|
| 69 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 70 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 71 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 72 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 73 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 74 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 75 | +SOFTWARE. |
| 76 | +
|
21 | 77 | ''' |
22 | 78 | import spidev |
23 | 79 | import logging_handler |
|
0 commit comments