{ "info": { "author": "Chris Borrill", "author_email": "chris.borrill@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Topic :: System :: Hardware :: Hardware Drivers" ], "description": "Raspberry Pi Python Library for Voltage and Current Sensors Using the INA219\n============================================================================\n\n|Build Status| |codecov| |PyPI version|\n\nThis Python library supports the\n`INA219 `__ voltage,\ncurrent and power monitor sensor from Texas Instruments. The intent of\nthe library is to make it easy to use the quite complex functionality of\nthis sensor.\n\nThe library currently only supports *continuous* reads of voltage and\npower, but not *triggered* reads.\n\nThe library supports the detection of *overflow* in the current/power\ncalculations which results in meaningless values for these readings.\n\nThe low power mode of the INA219 is supported, so if only occasional\nreads are being made in a battery based system, current consumption can\nbe minimised.\n\nThe library has been tested with the `Adafruit INA219\nBreakout `__.\n\nInstallation and Upgrade\n------------------------\n\nThis library and its dependency (`Adafruit GPIO\nlibrary `__) can be\ninstalled from PyPI by executing:\n\n.. code:: shell\n\n sudo pip install pi-ina219\n\nTo upgrade from a previous version installed direct from Github execute:\n\n.. code:: shell\n\n sudo pip uninstall pi-ina219\n sudo pip install pi-ina219\n\nThe Adafruit library supports the I2C protocol on all versions of the\nRaspberry Pi. Remember to enable the I2C bus under the *Advanced\nOptions* of *raspi-config*.\n\nUsage\n-----\n\nThe address of the sensor unless otherwise specified is the default of\n*0x40*.\n\nNote that the bus voltage is that on the load side of the shunt\nresister, if you want the voltage on the supply side then you should add\nthe bus voltage and shunt voltage together, or use the\n*supply\\_voltage()* function.\n\nSimple - Auto Gain\n~~~~~~~~~~~~~~~~~~\n\nThis mode is great for getting started, as it will provide valid\nreadings until the device current capability is exceeded for the value\nof the shunt resistor connected (3.2A for 0.1\u03a9 shunt resistor). It does\nthis by automatically adjusting the gain as required until the maximum\nis reached, when a *DeviceRangeError* exception is thrown to avoid\ninvalid readings being taken.\n\nThe downside of this approach is reduced current and power resolution.\n\n.. code:: python\n\n #!/usr/bin/env python\n from ina219 import INA219\n from ina219 import DeviceRangeError\n\n SHUNT_OHMS = 0.1\n\n\n def read():\n ina = INA219(SHUNT_OHMS)\n ina.configure()\n\n print(\"Bus Voltage: %.3f V\" % ina.voltage())\n try:\n print(\"Bus Current: %.3f mA\" % ina.current())\n print(\"Power: %.3f mW\" % ina.power())\n print(\"Shunt voltage: %.3f mV\" % ina.shunt_voltage())\n except DeviceRangeError as e:\n # Current out of device range with specified shunt resister\n print(e)\n\n\n if __name__ == \"__main__\":\n read()\n\nAdvanced - Auto Gain, High Resolution\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn this mode by understanding the maximum current expected in your\nsystem and specifying this in the script you can achieve the best\npossible current and power resolution. The library will calculate the\nbest gain to achieve the highest resolution based on the maximum\nexpected current.\n\nIn this mode if the current exceeds the maximum specified, the gain will\nbe automatically increased, so a valid reading will still result, but at\na lower resolution.\n\nAs above when the maximum gain is reached, an exception is thrown to\navoid invalid readings being taken.\n\n.. code:: python\n\n #!/usr/bin/env python\n from ina219 import INA219\n from ina219 import DeviceRangeError\n\n SHUNT_OHMS = 0.1\n MAX_EXPECTED_AMPS = 0.2\n\n\n def read():\n ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS)\n ina.configure(ina.RANGE_16V)\n\n print(\"Bus Voltage: %.3f V\" % ina.voltage())\n try:\n print(\"Bus Current: %.3f mA\" % ina.current())\n print(\"Power: %.3f mW\" % ina.power())\n print(\"Shunt voltage: %.3f mV\" % ina.shunt_voltage())\n except DeviceRangeError as e:\n # Current out of device range with specified shunt resister\n print(e)\n\n\n if __name__ == \"__main__\":\n read()\n\nAdvanced - Manual Gain, High Resolution\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn this mode by understanding the maximum current expected in your\nsystem and specifying this and the gain in the script you can always\nachieve the best possible current and power resolution, at the price of\nmissing current and power values if a current overflow occurs.\n\n.. code:: python\n\n #!/usr/bin/env python\n from ina219 import INA219\n from ina219 import DeviceRangeError\n\n SHUNT_OHMS = 0.1\n MAX_EXPECTED_AMPS = 0.2\n\n\n def read():\n ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS)\n ina.configure(ina.RANGE_16V, ina.GAIN_1_40MV)\n\n print(\"Bus Voltage: %.3f V\" % ina.voltage())\n try:\n print(\"Bus Current: %.3f mA\" % ina.current())\n print(\"Power: %.3f mW\" % ina.power())\n print(\"Shunt voltage: %.3f mV\" % ina.shunt_voltage())\n except DeviceRangeError as e:\n print(\"Current overflow\")\n\n\n if __name__ == \"__main__\":\n read()\n\nSensor Address\n~~~~~~~~~~~~~~\n\nThe sensor address may be altered as follows:\n\n.. code:: python\n\n ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS, address=0x41)\n\nLow Power Mode\n~~~~~~~~~~~~~~\n\nThe sensor may be put in low power mode between reads as follows:\n\n.. code:: python\n\n ina.configure(ina.RANGE_16V)\n while True:\n print(\"Voltage : %.3f V\" % ina.voltage())\n ina.sleep()\n time.sleep(60)\n ina.wake()\n\nNote that if you do not wake the device after sleeping, the value\nreturned from a read will be the previous value taken before sleeping.\n\nFunctions\n---------\n\n- ``INA219()`` constructs the class. The arguments, are:\n\n - shunt\\_ohms: The value of the shunt resistor in Ohms (mandatory).\n - max\\_expected\\_amps: The maximum expected current in Amps\n (optional).\n - busnum: The I2C bus number for the device platform, defaults to\n *auto detects 0 or 1 for Raspberry Pi or Beaglebone Black*\n (optional).\n - address: The I2C address of the INA219, defaults to *0x40*\n (optional).\n - log\\_level: Set to *logging.INFO* to see the detailed calibration\n calculations and *logging.DEBUG* to see register operations\n (optional).\n\n- ``configure()`` configures and calibrates how the INA219 will take\n measurements. The arguments, which are all optional, are:\n\n - voltage\\_range: The full scale voltage range, this is either 16V\n or 32V, represented by one of the following constants (optional).\n\n - RANGE\\_16V: Range zero to 16 volts\n - RANGE\\_32V: Range zero to 32 volts (**default**). **Device only\n supports upto 26V.**\n\n - gain: The gain, which controls the maximum range of the shunt\n voltage, represented by one of the following constants (optional).\n\n - GAIN\\_1\\_40MV: Maximum shunt voltage 40mV\n - GAIN\\_2\\_80MV: Maximum shunt voltage 80mV\n - GAIN\\_4\\_160MV: Maximum shunt voltage 160mV\n - GAIN\\_8\\_320MV: Maximum shunt voltage 320mV\n - GAIN\\_AUTO: Automatically calculate the gain (**default**)\n\n - bus\\_adc: The bus ADC resolution (9, 10, 11, or 12-bit), or set\n the number of samples used when averaging results, represented by\n one of the following constants (optional).\n\n - ADC\\_9BIT: 9 bit, conversion time 84us.\n - ADC\\_10BIT: 10 bit, conversion time 148us.\n - ADC\\_11BIT: 11 bit, conversion time 276us.\n - ADC\\_12BIT: 12 bit, conversion time 532us (**default**).\n - ADC\\_2SAMP: 2 samples at 12 bit, conversion time 1.06ms.\n - ADC\\_4SAMP: 4 samples at 12 bit, conversion time 2.13ms.\n - ADC\\_8SAMP: 8 samples at 12 bit, conversion time 4.26ms.\n - ADC\\_16SAMP: 16 samples at 12 bit, conversion time 8.51ms\n - ADC\\_32SAMP: 32 samples at 12 bit, conversion time 17.02ms.\n - ADC\\_64SAMP: 64 samples at 12 bit, conversion time 34.05ms.\n - ADC\\_128SAMP: 128 samples at 12 bit, conversion time 68.10ms.\n\n - shunt\\_adc: The shunt ADC resolution (9, 10, 11, or 12-bit), or\n set the number of samples used when averaging results, represented\n by one of the following constants (optional).\n\n - ADC\\_9BIT: 9 bit, conversion time 84us.\n - ADC\\_10BIT: 10 bit, conversion time 148us.\n - ADC\\_11BIT: 11 bit, conversion time 276us.\n - ADC\\_12BIT: 12 bit, conversion time 532us (**default**).\n - ADC\\_2SAMP: 2 samples at 12 bit, conversion time 1.06ms.\n - ADC\\_4SAMP: 4 samples at 12 bit, conversion time 2.13ms.\n - ADC\\_8SAMP: 8 samples at 12 bit, conversion time 4.26ms.\n - ADC\\_16SAMP: 16 samples at 12 bit, conversion time 8.51ms\n - ADC\\_32SAMP: 32 samples at 12 bit, conversion time 17.02ms.\n - ADC\\_64SAMP: 64 samples at 12 bit, conversion time 34.05ms.\n - ADC\\_128SAMP: 128 samples at 12 bit, conversion time 68.10ms.\n\n- ``voltage()`` Returns the bus voltage in volts (V).\n- ``supply_voltage()`` Returns the bus supply voltage in volts (V).\n This is the sum of the bus voltage and shunt voltage. A\n *DeviceRangeError* exception is thrown if current overflow occurs.\n- ``current()`` Returns the bus current in milliamps (mA). A\n *DeviceRangeError* exception is thrown if current overflow occurs.\n- ``power()`` Returns the bus power consumption in milliwatts (mW). A\n *DeviceRangeError* exception is thrown if current overflow occurs.\n- ``shunt_voltage()`` Returns the shunt voltage in millivolts (mV). A\n *DeviceRangeError* exception is thrown if current overflow occurs.\n- ``current_overflow()`` Returns 'True' if an overflow has occured.\n Alternatively handle the *DeviceRangeError* exception as shown in the\n examples above.\n- ``sleep()`` Put the INA219 into power down mode.\n- ``wake()`` Wake the INA219 from power down mode.\n- ``reset()`` Reset the INA219 to its default configuration.\n\nPerformance\n-----------\n\nOn a Raspberry Pi 2 Model B running Raspbian Jesse and reading a 12-bit\nvoltage in a loop, a read occurred approximately every 10 milliSeconds.\n\nDebugging\n---------\n\nTo understand the calibration calculation results and automatic gain\nincreases, informational output can be enabled with:\n\n.. code:: python\n\n ina = INA219(SHUNT_OHMS, log_level=logging.INFO)\n\nDetailed logging of device register operations can be enabled with:\n\n.. code:: python\n\n ina = INA219(SHUNT_OHMS, log_level=logging.DEBUG)\n\nTesting\n-------\n\nInstall the library as described above, this will install all the\ndependencies required for the unit tests, as well as the library itself.\nClone the library source from Github then execute the test suite from\nthe top level directory with:\n\n.. code:: shell\n\n python -m unittest discover -s tests -p 'test_*.py'\n\nA single unit test class may be run as follows:\n\n.. code:: shell\n\n python -m unittest tests.test_configuration.TestConfiguration\n\nCode coverage metrics may be generated and viewed with:\n\n.. code:: shell\n\n coverage run --branch --source=ina219 -m unittest discover -s tests -p 'test_*.py'\n coverage report -m\n\nCoding Standard\n---------------\n\nThis library adheres to the *PEP8* standard and follows the *idiomatic*\nstyle described in the book *Writing Idiomatic Python* by *Jeff Knupp*.\n\n.. |Build Status| image:: https://travis-ci.org/chrisb2/pi_ina219.svg?branch=master\n :target: https://travis-ci.org/chrisb2/pi_ina219\n.. |codecov| image:: https://codecov.io/gh/chrisb2/pi_ina219/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/chrisb2/pi_ina219\n.. |PyPI version| image:: https://badge.fury.io/py/pi-ina219.svg\n :target: https://badge.fury.io/py/pi-ina219\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/chrisb2/pi_ina219/", "keywords": "ina219 raspberrypi", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pi-ina219", "package_url": "https://pypi.org/project/pi-ina219/", "platform": "", "project_url": "https://pypi.org/project/pi-ina219/", "project_urls": { "Homepage": "https://github.com/chrisb2/pi_ina219/" }, "release_url": "https://pypi.org/project/pi-ina219/1.2.0/", "requires_dist": [ "Adafruit-GPIO", "mock" ], "requires_python": "", "summary": "This Python library for Raspberry Pi makes it easy to leverage the complex functionality of the Texas Instruments INA219 sensor to measure voltage, current and power.", "version": "1.2.0" }, "last_serial": 4002757, "releases": { "1.1.0": [ { "comment_text": "", "digests": { "md5": "139503acf24061b0096fec6cd11ab8b8", "sha256": "1cd3c88203e2a9e915cf507d30aa4bde9e8b8a6bfc0e5ad02cc5bbdccd2f6c99" }, "downloads": -1, "filename": "pi_ina219-1.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "139503acf24061b0096fec6cd11ab8b8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13190, "upload_time": "2017-03-02T07:20:30", "url": "https://files.pythonhosted.org/packages/bd/fd/0660c19b1ee0cae3eae0732002b0e8130e1153cfd5b26707a33a9aa12b05/pi_ina219-1.1.0-py2.py3-none-any.whl" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "c0ea7e8c9216204c66232cae37006c8e", "sha256": "52a0f4f8ec4c690d514cc3bf89a2ace274a885a9e953f75e774bc40ea9ae371a" }, "downloads": -1, "filename": "pi_ina219-1.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c0ea7e8c9216204c66232cae37006c8e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13370, "upload_time": "2018-06-26T07:36:38", "url": "https://files.pythonhosted.org/packages/0e/44/f85379a7d980422f98d9299876d599089ce3e2e37e2b0d095d3f3d22f907/pi_ina219-1.2.0-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c0ea7e8c9216204c66232cae37006c8e", "sha256": "52a0f4f8ec4c690d514cc3bf89a2ace274a885a9e953f75e774bc40ea9ae371a" }, "downloads": -1, "filename": "pi_ina219-1.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c0ea7e8c9216204c66232cae37006c8e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 13370, "upload_time": "2018-06-26T07:36:38", "url": "https://files.pythonhosted.org/packages/0e/44/f85379a7d980422f98d9299876d599089ce3e2e37e2b0d095d3f3d22f907/pi_ina219-1.2.0-py2.py3-none-any.whl" } ] }