Skip to content

INA219 featherwing #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions adafruit_featherwing/ina219_featherwing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Kattni Rembor for Adafruit Industries LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_featherwing.ina219_featherwing`
====================================================

Helper for using the `INA219 FeatherWing <https://www.adafruit.com/product/3650>`_.

* Author(s): Kattni Rembor
"""

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

import adafruit_ina219
from adafruit_featherwing import shared


class INA219FeatherWing:
"""Class representing an `Adafruit INA219 FeatherWing
<https://www.adafruit.com/product/3650>`_.

Automatically uses the feather's I2C bus."""
def __init__(self):
self._ina219 = adafruit_ina219.INA219(shared.I2C_BUS)

@property
def bus_voltage(self):
"""Bus voltage returns volts.

.. image :: /_static/ina219_featherwing/ina219_featherwing.jpg
:alt: INA219 Featherwing

This example prints the bus voltage with the appropriate units.

.. code-block:: python

from adafruit_featherwing import ina219_featherwing
import time

ina219 = ina219_featherwing.INA219FeatherWing()

while True:
print("Bus Voltage: {} V".format(ina219.bus_voltage))
time.sleep(0.5)

"""
return self._ina219.bus_voltage

@property
def shunt_voltage(self):
"""Shunt voltage returns volts.

.. image :: /_static/ina219_featherwing/ina219_featherwing.jpg
:alt: INA219 Featherwing

This example prints the shunt voltage with the appropriate units.

.. code-block:: python

from adafruit_featherwing import ina219_featherwing
import time

ina219 = ina219_featherwing.INA219FeatherWing()

while True:
print("Shunt Voltage: {} V".format(ina219.shunt_voltage))
time.sleep(0.5)

"""
return self._ina219.shunt_voltage

@property
def voltage(self):
"""Voltage, known as load voltage, is bus voltage plus shunt voltage. Returns volts.

.. image :: /_static/ina219_featherwing/ina219_featherwing.jpg
:alt: INA219 Featherwing

This example prints the voltage with the appropriate units.

.. code-block:: python

from adafruit_featherwing import ina219_featherwing
import time

ina219 = ina219_featherwing.INA219FeatherWing()

while True:
print("Voltage: {} V".format(ina219.voltage))
time.sleep(0.5)

"""
voltage = self._ina219.bus_voltage + self._ina219.shunt_voltage
return voltage

@property
def current(self):
"""Current returns mA.

.. image :: /_static/ina219_featherwing/ina219_featherwing.jpg
:alt: INA219 Featherwing

This example prints the current with the appropriate units.

.. code-block:: python

from adafruit_featherwing import ina219_featherwing
import time

ina219 = ina219_featherwing.INA219FeatherWing()

while True:
print("Current: {} mA".format(ina219.current))
time.sleep(0.5)

"""
return self._ina219.current
1 change: 1 addition & 0 deletions api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.. If you created a package, create one automodule per module in the package.

.. automodule:: adafruit_featherwing.motor_featherwing
.. automodule:: adafruit_featherwing.ina219_featherwing
:members:
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["adafruit_motor", "adafruit_pca9685", "board", "busio"]
autodoc_mock_imports = ["adafruit_motor", "adafruit_pca9685", "board", "busio", "adafruit_ina219"]

intersphinx_mapping = {
'python': ('https://docs.python.org/3.4', None),
Expand Down
13 changes: 13 additions & 0 deletions examples/ina219_featherwing/ina219.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
""" Example to print out the voltage and current using the INA219 """
import time
from adafruit_featherwing import ina219_featherwing

INA219 = ina219_featherwing.INA219FeatherWing()

while True:
print("Bus Voltage: {} V".format(INA219.bus_voltage))
print("Shunt Voltage: {} V".format(INA219.shunt_voltage))
print("Voltage: {} V".format(INA219.voltage))
print("Current: {} mA".format(INA219.current))
print("")
time.sleep(0.5)