|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (c) 2018 Kattni Rembor for Adafruit Industries LLC |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | +""" |
| 23 | +`adafruit_featherwing.ina219_featherwing` |
| 24 | +==================================================== |
| 25 | +
|
| 26 | +Helper for using the `INA219 FeatherWing <https://www.adafruit.com/product/3650>`_. |
| 27 | +
|
| 28 | +* Author(s): Kattni Rembor |
| 29 | +""" |
| 30 | + |
| 31 | +__version__ = "0.0.0-auto.0" |
| 32 | +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" |
| 33 | + |
| 34 | +import adafruit_ina219 |
| 35 | +from adafruit_featherwing import shared |
| 36 | + |
| 37 | + |
| 38 | +class INA219FeatherWing: |
| 39 | + """Class representing an `Adafruit INA219 FeatherWing |
| 40 | + <https://www.adafruit.com/product/3650>`_. |
| 41 | +
|
| 42 | + Automatically uses the feather's I2C bus.""" |
| 43 | + def __init__(self): |
| 44 | + self._ina219 = adafruit_ina219.INA219(shared.I2C_BUS) |
| 45 | + |
| 46 | + @property |
| 47 | + def bus_voltage(self): |
| 48 | + """Bus voltage returns volts. |
| 49 | +
|
| 50 | + .. image :: /_static/ina219_featherwing/ina219_featherwing.jpg |
| 51 | + :alt: INA219 Featherwing |
| 52 | +
|
| 53 | + This example prints the bus voltage with the appropriate units. |
| 54 | +
|
| 55 | + .. code-block:: python |
| 56 | +
|
| 57 | + from adafruit_featherwing import ina219_featherwing |
| 58 | + import time |
| 59 | +
|
| 60 | + ina219 = ina219_featherwing.INA219FeatherWing() |
| 61 | +
|
| 62 | + while True: |
| 63 | + print("Bus Voltage: {} V".format(ina219.bus_voltage)) |
| 64 | + time.sleep(0.5) |
| 65 | +
|
| 66 | + """ |
| 67 | + return self._ina219.bus_voltage |
| 68 | + |
| 69 | + @property |
| 70 | + def shunt_voltage(self): |
| 71 | + """Shunt voltage returns volts. |
| 72 | +
|
| 73 | + .. image :: /_static/ina219_featherwing/ina219_featherwing.jpg |
| 74 | + :alt: INA219 Featherwing |
| 75 | +
|
| 76 | + This example prints the shunt voltage with the appropriate units. |
| 77 | +
|
| 78 | + .. code-block:: python |
| 79 | +
|
| 80 | + from adafruit_featherwing import ina219_featherwing |
| 81 | + import time |
| 82 | +
|
| 83 | + ina219 = ina219_featherwing.INA219FeatherWing() |
| 84 | +
|
| 85 | + while True: |
| 86 | + print("Shunt Voltage: {} V".format(ina219.shunt_voltage)) |
| 87 | + time.sleep(0.5) |
| 88 | +
|
| 89 | + """ |
| 90 | + return self._ina219.shunt_voltage |
| 91 | + |
| 92 | + @property |
| 93 | + def voltage(self): |
| 94 | + """Voltage, known as load voltage, is bus voltage plus shunt voltage. Returns volts. |
| 95 | +
|
| 96 | + .. image :: /_static/ina219_featherwing/ina219_featherwing.jpg |
| 97 | + :alt: INA219 Featherwing |
| 98 | +
|
| 99 | + This example prints the voltage with the appropriate units. |
| 100 | +
|
| 101 | + .. code-block:: python |
| 102 | +
|
| 103 | + from adafruit_featherwing import ina219_featherwing |
| 104 | + import time |
| 105 | +
|
| 106 | + ina219 = ina219_featherwing.INA219FeatherWing() |
| 107 | +
|
| 108 | + while True: |
| 109 | + print("Voltage: {} V".format(ina219.voltage)) |
| 110 | + time.sleep(0.5) |
| 111 | +
|
| 112 | + """ |
| 113 | + voltage = self._ina219.bus_voltage + self._ina219.shunt_voltage |
| 114 | + return voltage |
| 115 | + |
| 116 | + @property |
| 117 | + def current(self): |
| 118 | + """Current returns mA. |
| 119 | +
|
| 120 | + .. image :: /_static/ina219_featherwing/ina219_featherwing.jpg |
| 121 | + :alt: INA219 Featherwing |
| 122 | +
|
| 123 | + This example prints the current with the appropriate units. |
| 124 | +
|
| 125 | + .. code-block:: python |
| 126 | +
|
| 127 | + from adafruit_featherwing import ina219_featherwing |
| 128 | + import time |
| 129 | +
|
| 130 | + ina219 = ina219_featherwing.INA219FeatherWing() |
| 131 | +
|
| 132 | + while True: |
| 133 | + print("Current: {} mA".format(ina219.current)) |
| 134 | + time.sleep(0.5) |
| 135 | +
|
| 136 | + """ |
| 137 | + return self._ina219.current |
0 commit comments