|
16 | 16 |
|
17 | 17 | **Hardware:**
|
18 | 18 |
|
19 |
| -* `Adafruit BH1750 Breakout <https://www.adafruit.com/products/46XX>`_ |
| 19 | +* Adafruit `BH1750 Light Sensor |
| 20 | + <https://www.adafruit.com/product/4681>`_ (Product ID: 4681) |
20 | 21 |
|
21 | 22 | **Software and Dependencies:**
|
22 | 23 |
|
23 | 24 | * Adafruit CircuitPython firmware for the supported boards:
|
24 |
| - https://github.com/adafruit/circuitpython/releases |
| 25 | + https://circuitpython.org/downloads |
25 | 26 |
|
26 |
| - * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice |
| 27 | +* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice |
27 | 28 | """
|
28 | 29 |
|
29 | 30 | # imports
|
@@ -89,7 +90,7 @@ class RWBitfields:
|
89 | 90 | gets and sets the full byte value from the ``_settings`` attribute of the calling
|
90 | 91 | object.
|
91 | 92 |
|
92 |
| - Values are `int` between 0 and ``2**num_bits - 1`` |
| 93 | + Values are `int` between 0 and :math:`2^num_bits - 1` |
93 | 94 |
|
94 | 95 | :param int num_bits: The number of bits in the field.
|
95 | 96 | :param type lowest_bit: The lowest bits index within the byte at ``register_address``
|
@@ -148,10 +149,33 @@ class Resolution(CV):
|
148 | 149 | class BH1750: # pylint:disable=too-many-instance-attributes
|
149 | 150 | """Library for the BH1750 Sensor
|
150 | 151 |
|
| 152 | + :param ~busio.I2C i2c_bus: The I2C bus the BH1750 is connected to. |
| 153 | + :param int address: The I2C device address. Defaults to :const:`0x23`.Can be |
| 154 | + set to :const:`0x5C` by pulling the address pin high. |
151 | 155 |
|
152 |
| - :param ~busio.I2C i2c_bus: The I2C bus the BH1750 is connected to. |
153 |
| - :param address: The I2C slave address of the sensor. Defaults to ``0x23``. \ |
154 |
| - Can be set to ``0x5C`` by pulling the address pin high. |
| 156 | +
|
| 157 | + **Quickstart: Importing and using the BH1750** |
| 158 | +
|
| 159 | + Here is an example of using the :class:`BH1750` class. |
| 160 | + First you will need to import the libraries to use the sensor |
| 161 | +
|
| 162 | + .. code-block:: python |
| 163 | +
|
| 164 | + import board |
| 165 | + import adafruit_bh1750 |
| 166 | +
|
| 167 | + Once this is done you can define your `board.I2C` object and define your sensor object |
| 168 | +
|
| 169 | + .. code-block:: python |
| 170 | +
|
| 171 | + i2c = board.I2C() # uses board.SCL and board.SDA |
| 172 | + sensor = adafruit_bh1750.BH1750(i2c) |
| 173 | +
|
| 174 | + Now you have access to the :attr:`lux` value in lux |
| 175 | +
|
| 176 | + .. code-block:: python |
| 177 | +
|
| 178 | + lux = sensor.lux |
155 | 179 |
|
156 | 180 | """
|
157 | 181 |
|
@@ -194,25 +218,7 @@ def _raw_reading(self):
|
194 | 218 |
|
195 | 219 | @property
|
196 | 220 | def lux(self):
|
197 |
| - """Light value in lux. |
198 |
| -
|
199 |
| - This example prints the light data in lux. Cover the sensor to see the values change. |
200 |
| -
|
201 |
| - .. code-block:: python |
202 |
| -
|
203 |
| - import time |
204 |
| - import board |
205 |
| - import busio |
206 |
| - import adafruit_bh1750 |
207 |
| -
|
208 |
| - i2c = busio.I2C(board.SCL, board.SDA) |
209 |
| - sensor = adafruit_bh1750.BH1750(i2c) |
210 |
| -
|
211 |
| - while True: |
212 |
| - print("Lux:", sensor.lux) |
213 |
| - time.sleep(0.1) |
214 |
| -
|
215 |
| - """ |
| 221 | + """Light value in lux.""" |
216 | 222 | raw_lux = self._raw_reading
|
217 | 223 |
|
218 | 224 | return self._convert_to_lux(raw_lux)
|
|
0 commit comments