Skip to content

Commit bd7705b

Browse files
kattnitannewt
authored andcommitted
INA219 featherwing (#2)
INA219 FeatherWing library, example, docs, image
1 parent fe1fd3c commit bd7705b

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed
Loading
+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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

api.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.. If you created a package, create one automodule per module in the package.
33
44
.. automodule:: adafruit_featherwing.motor_featherwing
5+
.. automodule:: adafruit_featherwing.ina219_featherwing
56
:members:

conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Uncomment the below if you use native CircuitPython modules such as
1919
# digitalio, micropython and busio. List the modules you use. Without it, the
2020
# autodoc module docs will fail to generate with a warning.
21-
autodoc_mock_imports = ["adafruit_motor", "adafruit_pca9685", "board", "busio"]
21+
autodoc_mock_imports = ["adafruit_motor", "adafruit_pca9685", "board", "busio", "adafruit_ina219"]
2222

2323
intersphinx_mapping = {
2424
'python': ('https://docs.python.org/3.4', None),

examples/ina219_featherwing/ina219.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
""" Example to print out the voltage and current using the INA219 """
2+
import time
3+
from adafruit_featherwing import ina219_featherwing
4+
5+
INA219 = ina219_featherwing.INA219FeatherWing()
6+
7+
while True:
8+
print("Bus Voltage: {} V".format(INA219.bus_voltage))
9+
print("Shunt Voltage: {} V".format(INA219.shunt_voltage))
10+
print("Voltage: {} V".format(INA219.voltage))
11+
print("Current: {} mA".format(INA219.current))
12+
print("")
13+
time.sleep(0.5)

0 commit comments

Comments
 (0)