Skip to content

Commit 690805c

Browse files
Merge pull request #41 from jposada202020/improving_docs
improving_docs
2 parents d8bb323 + b0b6e7d commit 690805c

File tree

7 files changed

+118
-34
lines changed

7 files changed

+118
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
__pycache__
66
_build
77
*.pyc
8+
.idea

README.rst

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,27 @@ To install in a virtual environment in your current project:
5454
Usage Example
5555
=============
5656

57-
.. code-block:: python
57+
.. code-block:: python3
5858
59-
from busio import I2C
60-
import adafruit_bme680
61-
import time
62-
import board
59+
import adafruit_bme680
60+
import time
61+
import board
6362
64-
# Create library object using our Bus I2C port
65-
i2c = I2C(board.SCL, board.SDA)
66-
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
63+
# Create sensor object, communicating over the board's default I2C bus
64+
i2c = board.I2C() # uses board.SCL and board.SDA
65+
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
6766
68-
# change this to match the location's pressure (hPa) at sea level
69-
bme680.sea_level_pressure = 1013.25
67+
# change this to match the location's pressure (hPa) at sea level
68+
bme680.sea_level_pressure = 1013.25
7069
71-
while True:
72-
print("\nTemperature: %0.1f C" % bme680.temperature)
73-
print("Gas: %d ohm" % bme680.gas)
74-
print("Humidity: %0.1f %%" % bme680.relative_humidity)
75-
print("Pressure: %0.3f hPa" % bme680.pressure)
76-
print("Altitude = %0.2f meters" % bme680.altitude)
70+
while True:
71+
print("\nTemperature: %0.1f C" % bme680.temperature)
72+
print("Gas: %d ohm" % bme680.gas)
73+
print("Humidity: %0.1f %%" % bme680.relative_humidity)
74+
print("Pressure: %0.3f hPa" % bme680.pressure)
75+
print("Altitude = %0.2f meters" % bme680.altitude)
7776
78-
time.sleep(2)
77+
time.sleep(2)
7978
8079
8180
Contributing

adafruit_bme680.py

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(self, *, refresh_rate=10):
142142
self._write(_BME680_BME680_GAS_WAIT_0, [0x65])
143143

144144
self.sea_level_pressure = 1013.25
145-
"""Pressure in hectoPascals at sea level. Used to calibrate ``altitude``."""
145+
"""Pressure in hectoPascals at sea level. Used to calibrate :attr:`altitude`."""
146146

147147
# Default oversampling and filter register values.
148148
self._pressure_oversample = 0b011
@@ -210,7 +210,7 @@ def filter_size(self, size):
210210

211211
@property
212212
def temperature(self):
213-
"""The compensated temperature in degrees celsius."""
213+
"""The compensated temperature in degrees Celsius."""
214214
self._perform_reading()
215215
calc_temp = ((self._t_fine * 5) + 128) / 256
216216
return calc_temp / 100
@@ -288,8 +288,8 @@ def humidity(self):
288288

289289
@property
290290
def altitude(self):
291-
"""The altitude based on current ``pressure`` vs the sea level pressure
292-
(``sea_level_pressure``) - which you must enter ahead of time)"""
291+
"""The altitude based on current :attr:`pressure` vs the sea level pressure
292+
(:attr:`sea_level_pressure`) - which you must enter ahead of time)"""
293293
pressure = self.pressure # in Si units for hPascal
294294
return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903))
295295

@@ -383,10 +383,47 @@ def _write(self, register, values):
383383
class Adafruit_BME680_I2C(Adafruit_BME680):
384384
"""Driver for I2C connected BME680.
385385
386-
:param int address: I2C device address
387-
:param bool debug: Print debug statements when True.
386+
:param ~busio.I2C i2c: The I2C bus the BME680 is connected to.
387+
:param int address: I2C device address. Defaults to :const:`0x77`
388+
:param bool debug: Print debug statements when `True`. Defaults to `False`
388389
:param int refresh_rate: Maximum number of readings per second. Faster property reads
389-
will be from the previous reading."""
390+
will be from the previous reading.
391+
392+
**Quickstart: Importing and using the BME680**
393+
394+
Here is an example of using the :class:`BMP680_I2C` class.
395+
First you will need to import the libraries to use the sensor
396+
397+
.. code-block:: python
398+
399+
import board
400+
import adafruit_bme680
401+
402+
Once this is done you can define your `board.I2C` object and define your sensor object
403+
404+
.. code-block:: python
405+
406+
i2c = board.I2C() # uses board.SCL and board.SDA
407+
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
408+
409+
You need to setup the pressure at sea level
410+
411+
.. code-block:: python
412+
413+
bme680.sea_level_pressure = 1013.25
414+
415+
Now you have access to the :attr:`temperature`, :attr:`gas`, :attr:`relative_humidity`,
416+
:attr:`pressure` and :attr:`altitude` attributes
417+
418+
.. code-block:: python
419+
420+
temperature = bme680.temperature
421+
gas = bme680.gas
422+
relative_humidity = bme680.relative_humidity
423+
pressure = bme680.pressure
424+
altitude = bme680.altitude
425+
426+
"""
390427

391428
def __init__(self, i2c, address=0x77, debug=False, *, refresh_rate=10):
392429
"""Initialize the I2C device at the 'address' given"""
@@ -423,12 +460,50 @@ def _write(self, register, values):
423460
class Adafruit_BME680_SPI(Adafruit_BME680):
424461
"""Driver for SPI connected BME680.
425462
426-
:param busio.SPI spi: SPI device
427-
:param digitalio.DigitalInOut cs: Chip Select
428-
:param bool debug: Print debug statements when True.
429-
:param int baudrate: Clock rate, default is 100000
463+
:param ~busio.SPI spi: SPI device
464+
:param ~digitalio.DigitalInOut cs: Chip Select
465+
:param bool debug: Print debug statements when `True`. Defaults to `False`
466+
:param int baudrate: Clock rate, default is :const:`100000`
430467
:param int refresh_rate: Maximum number of readings per second. Faster property reads
431468
will be from the previous reading.
469+
470+
471+
**Quickstart: Importing and using the BME680**
472+
473+
Here is an example of using the :class:`BMP680_SPI` class.
474+
First you will need to import the libraries to use the sensor
475+
476+
.. code-block:: python
477+
478+
import board
479+
from digitalio import DigitalInOut, Direction
480+
import adafruit_bme680
481+
482+
Once this is done you can define your `board.SPI` object and define your sensor object
483+
484+
.. code-block:: python
485+
486+
cs = digitalio.DigitalInOut(board.D10)
487+
spi = board.SPI()
488+
bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)
489+
490+
You need to setup the pressure at sea level
491+
492+
.. code-block:: python
493+
494+
bme680.sea_level_pressure = 1013.25
495+
496+
Now you have access to the :attr:`temperature`, :attr:`gas`, :attr:`relative_humidity`,
497+
:attr:`pressure` and :attr:`altitude` attributes
498+
499+
.. code-block:: python
500+
501+
temperature = bme680.temperature
502+
gas = bme680.gas
503+
relative_humidity = bme680.relative_humidity
504+
pressure = bme680.pressure
505+
altitude = bme680.altitude
506+
432507
"""
433508

434509
def __init__(self, spi, cs, baudrate=100000, debug=False, *, refresh_rate=10):

docs/examples.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/bme680_simpletest.py
77
:caption: examples/bme680_simpletest.py
88
:linenos:
9+
10+
SPI Example
11+
-----------
12+
13+
Showcase the use of the SPI bus to read the sensor data.
14+
15+
.. literalinclude:: ../examples/bme680_spi.py
16+
:caption: examples/bme680_spi.py
17+
: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 BME680 - Temperature, Humidity, Pressure and Gas Sensor Learning Guide <https://learn.adafruit.com/adafruit-bme680-humidity-temperature-barometic-pressure-voc-gas>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

examples/bme680_simpletest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
import time
55
import board
6-
from busio import I2C
76
import adafruit_bme680
87

9-
# Create library object using our Bus I2C port
10-
i2c = I2C(board.SCL, board.SDA)
8+
# Create sensor object, communicating over the board's default I2C bus
9+
i2c = board.I2C() # uses board.SCL and board.SDA
1110
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
1211

1312
# change this to match the location's pressure (hPa) at sea level

examples/bme680_spi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import time
55
import board
66
import digitalio
7-
from busio import SPI
87
import adafruit_bme680
98

10-
# Create library object using our Bus SPI port
9+
# Create sensor object, communicating over the board's default SPI bus
1110
cs = digitalio.DigitalInOut(board.D10)
12-
spi = SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
11+
spi = board.SPI()
1312
bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)
1413

1514
# change this to match the location's pressure (hPa) at sea level

0 commit comments

Comments
 (0)