Skip to content

Commit 917deea

Browse files
Merge pull request #31 from jposada202020/improving_docs
improving_docs
2 parents 110242b + 8f9686b commit 917deea

File tree

6 files changed

+129
-29
lines changed

6 files changed

+129
-29
lines changed

README.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ Usage Example
6161
import time
6262
import board
6363
# import digitalio # For use with SPI
64-
import busio
6564
import adafruit_bmp280
6665
67-
# Create library object using our Bus I2C port
68-
i2c = busio.I2C(board.SCL, board.SDA)
66+
# Create sensor object, communicating over the board's default I2C bus
67+
i2c = board.I2C() # uses board.SCL and board.SDA
6968
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
7069
71-
# OR create library object using our Bus SPI port
72-
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
70+
# OR Create sensor object, communicating over the board's default SPI bus
71+
# spi = board.SPI()
7372
# bmp_cs = digitalio.DigitalInOut(board.D10)
7473
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
7574

adafruit_bmp280.py

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
# SPDX-License-Identifier: MIT
44

55
"""
6-
`adafruit_bmp280` - Adafruit BMP280 - Temperature & Barometic Pressure Sensor
6+
`adafruit_bmp280`
77
===============================================================================
88
9-
CircuitPython driver from BMP280 Temperature and Barometic Pressure sensor
9+
CircuitPython driver from BMP280 Temperature and Barometric Pressure sensor
1010
1111
* 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
1226
"""
1327
import math
1428
from time import sleep
@@ -100,9 +114,9 @@
100114

101115

102116
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
106120
107121
.. note::
108122
The operational range of the BMP280 is 300-1100 hPa.
@@ -301,15 +315,15 @@ def measurement_time_max(self):
301315

302316
@property
303317
def temperature(self):
304-
"""The compensated temperature in degrees celsius."""
318+
"""The compensated temperature in degrees Celsius."""
305319
self._read_temperature()
306320
return self._t_fine / 5120.0
307321

308322
@property
309323
def pressure(self):
310324
"""
311325
The compensated pressure in hectoPascals.
312-
returns None if pressure measurement is disabled
326+
returns `None` if pressure measurement is disabled
313327
"""
314328
self._read_temperature()
315329

@@ -338,8 +352,8 @@ def pressure(self):
338352

339353
@property
340354
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)"""
343357
p = self.pressure # in Si units for hPascal
344358
return 44330 * (1.0 - math.pow(p / self.sea_level_pressure, 0.1903))
345359

@@ -382,8 +396,45 @@ def _write_register_byte(self, register, value):
382396

383397

384398
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+
"""
387438

388439
def __init__(self, i2c, address=0x77):
389440
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):
408459

409460

410461
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+
"""
413505

414506
def __init__(self, spi, cs, baudrate=100000):
415507
import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel

docs/examples.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/bmp280_simpletest.py
77
:caption: examples/bmp280_simpletest.py
88
:linenos:
9+
10+
Normal Mode
11+
-----------
12+
13+
Example showing how the BMP280 library can be used to set the various
14+
parameters supported by the sensor.
15+
16+
.. literalinclude:: ../examples/bmp280_normal_mode.py
17+
:caption: examples/bmp280_normal_mode.py
18+
:linenos:

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
Adafruit BMP280 I2C or SPI Barometric Pressure & Altitude Sensor Learning Guide <https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

examples/bmp280_normal_mode.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
Refer to the BMP280 datasheet to understand what these parameters do
88
"""
99
import time
10-
1110
import board
12-
import busio
1311
import adafruit_bmp280
1412

15-
# Create library object using our Bus I2C port
16-
i2c = busio.I2C(board.SCL, board.SDA)
13+
# Create sensor object, communicating over the board's default I2C bus
14+
i2c = board.I2C() # uses board.SCL and board.SDA
1715
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
1816

19-
# OR create library object using our Bus SPI port
20-
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
17+
# OR Create sensor object, communicating over the board's default SPI bus
18+
# spi = busio.SPI()
2119
# bmp_cs = digitalio.DigitalInOut(board.D10)
2220
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
2321

examples/bmp280_simpletest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
import board
88

99
# import digitalio # For use with SPI
10-
import busio
1110
import adafruit_bmp280
1211

13-
# Create library object using our Bus I2C port
14-
i2c = busio.I2C(board.SCL, board.SDA)
12+
# Create sensor object, communicating over the board's default I2C bus
13+
i2c = board.I2C() # uses board.SCL and board.SDA
1514
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
1615

17-
# OR create library object using our Bus SPI port
18-
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
16+
# OR Create sensor object, communicating over the board's default SPI bus
17+
# spi = board.SPI()
1918
# bmp_cs = digitalio.DigitalInOut(board.D10)
2019
# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
2120

0 commit comments

Comments
 (0)