3
3
# SPDX-License-Identifier: MIT
4
4
5
5
"""
6
- `adafruit_bmp280` - Adafruit BMP280 - Temperature & Barometic Pressure Sensor
6
+ `adafruit_bmp280`
7
7
===============================================================================
8
8
9
- CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor
9
+ CircuitPython driver from BMP280 Temperature and Barometric Pressure sensor
10
10
11
11
* Author(s): ladyada
12
+
13
+ Implementation Notes
14
+ --------------------
15
+
16
+ **Hardware:**
17
+
18
+ * `Adafruit from BMP280 Temperature and Barometric
19
+ Pressure sensor <https://www.adafruit.com/product/2651>`_
20
+
21
+ **Software and Dependencies:**
22
+
23
+ * Adafruit CircuitPython firmware for the supported boards:
24
+ https://github.com/adafruit/circuitpython/releases
25
+ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
12
26
"""
13
27
import math
14
28
from time import sleep
100
114
101
115
102
116
class Adafruit_BMP280 : # pylint: disable=invalid-name
103
- """Base BMP280 object. Use `Adafruit_BMP280_I2C` or `Adafruit_BMP280_SPI` instead of this. This
104
- checks the BMP280 was found, reads the coefficients and enables the sensor for continuous
105
- reads
117
+ """Base BMP280 object. Use :class: `Adafruit_BMP280_I2C` or :class: `Adafruit_BMP280_SPI`
118
+ instead of this. This checks the BMP280 was found, reads the coefficients and
119
+ enables the sensor for continuous reads
106
120
107
121
.. note::
108
122
The operational range of the BMP280 is 300-1100 hPa.
@@ -301,15 +315,15 @@ def measurement_time_max(self):
301
315
302
316
@property
303
317
def temperature (self ):
304
- """The compensated temperature in degrees celsius ."""
318
+ """The compensated temperature in degrees Celsius ."""
305
319
self ._read_temperature ()
306
320
return self ._t_fine / 5120.0
307
321
308
322
@property
309
323
def pressure (self ):
310
324
"""
311
325
The compensated pressure in hectoPascals.
312
- returns None if pressure measurement is disabled
326
+ returns ` None` if pressure measurement is disabled
313
327
"""
314
328
self ._read_temperature ()
315
329
@@ -338,8 +352,8 @@ def pressure(self):
338
352
339
353
@property
340
354
def altitude (self ):
341
- """The altitude based on the sea level pressure (`sea_level_pressure`) - which you must
342
- enter ahead of time)"""
355
+ """The altitude based on the sea level pressure (:attr: `sea_level_pressure`)
356
+ - which you must enter ahead of time)"""
343
357
p = self .pressure # in Si units for hPascal
344
358
return 44330 * (1.0 - math .pow (p / self .sea_level_pressure , 0.1903 ))
345
359
@@ -382,8 +396,45 @@ def _write_register_byte(self, register, value):
382
396
383
397
384
398
class Adafruit_BMP280_I2C (Adafruit_BMP280 ): # pylint: disable=invalid-name
385
- """Driver for I2C connected BMP280. Default address is 0x77 but another address can be passed
386
- in as an argument"""
399
+ """Driver for I2C connected BMP280.
400
+
401
+ :param ~busio.I2C i2c: The I2C bus the BMP280 is connected to.
402
+ :param int address: I2C device address. Defaults to :const:`0x77`.
403
+ but another address can be passed in as an argument
404
+
405
+ **Quickstart: Importing and using the BMP280**
406
+
407
+ Here is an example of using the :class:`BMP280_I2C` class.
408
+ First you will need to import the libraries to use the sensor
409
+
410
+ .. code-block:: python
411
+
412
+ import board
413
+ import adafruit_bmp280
414
+
415
+ Once this is done you can define your `board.I2C` object and define your sensor object
416
+
417
+ .. code-block:: python
418
+
419
+ i2c = board.I2C() # uses board.SCL and board.SDA
420
+ bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
421
+
422
+ You need to setup the pressure at sea level
423
+
424
+ .. code-block:: python
425
+
426
+ bmp280.sea_level_pressure = 1013.25
427
+
428
+ Now you have access to the :attr:`temperature`,
429
+ :attr:`pressure` and :attr:`altitude` attributes
430
+
431
+ .. code-block:: python
432
+
433
+ temperature = bmp280.temperature
434
+ pressure = bmp280.pressure
435
+ altitude = bmp280.altitude
436
+
437
+ """
387
438
388
439
def __init__ (self , i2c , address = 0x77 ):
389
440
import adafruit_bus_device .i2c_device as i2c_device # pylint: disable=import-outside-toplevel
@@ -408,8 +459,49 @@ def _write_register_byte(self, register, value):
408
459
409
460
410
461
class Adafruit_BMP280_SPI (Adafruit_BMP280 ):
411
- """Driver for SPI connected BMP280. Default clock rate is 100000 but can be changed with
412
- 'baudrate'"""
462
+ """Driver for SPI connected BMP280.
463
+
464
+ :param ~busio.SPI spi: SPI device
465
+ :param ~digitalio.DigitalInOut cs: Chip Select
466
+ :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate`
467
+
468
+
469
+ **Quickstart: Importing and using the BMP280**
470
+
471
+ Here is an example of using the :class:`BMP280_SPI` class.
472
+ First you will need to import the libraries to use the sensor
473
+
474
+ .. code-block:: python
475
+
476
+ import board
477
+ from digitalio import DigitalInOut, Direction
478
+ import adafruit_bmp280
479
+
480
+
481
+ Once this is done you can define your `board.SPI` object and define your sensor object
482
+
483
+ .. code-block:: python
484
+
485
+ cs = digitalio.DigitalInOut(board.D10)
486
+ spi = board.SPI()
487
+ bme280 = adafruit_bmp280.Adafruit_bmp280_SPI(spi, cs)
488
+
489
+ You need to setup the pressure at sea level
490
+
491
+ .. code-block:: python
492
+
493
+ bmp280.sea_level_pressure = 1013.25
494
+
495
+ Now you have access to the :attr:`temperature`, :attr:`pressure` and
496
+ :attr:`altitude` attributes
497
+
498
+ .. code-block:: python
499
+
500
+ temperature = bmp280.temperature
501
+ pressure = bmp280.pressure
502
+ altitude = bmp280.altitude
503
+
504
+ """
413
505
414
506
def __init__ (self , spi , cs , baudrate = 100000 ):
415
507
import adafruit_bus_device .spi_device as spi_device # pylint: disable=import-outside-toplevel
0 commit comments