{"id":475,"date":"2021-10-27T15:31:14","date_gmt":"2021-10-27T15:31:14","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=475"},"modified":"2022-04-11T20:22:59","modified_gmt":"2022-04-11T20:22:59","slug":"measure-current-voltage-and-power-with-the-adafruit-ina260","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/electronics\/measure-current-voltage-and-power-with-the-adafruit-ina260\/","title":{"rendered":"Measure current, voltage and power with the Adafruit INA260"},"content":{"rendered":"\n
Image by Adafruit<\/a><\/p>\n\n\n\n The INA260 can measure voltages up to 36V DC and current up to 15A continuously! I am planning on using three of these in my up coming project.<\/p>\n I will be following Adafruit’s guide<\/a> on how to use the INA260 board along with my own guide<\/a> on using the Adafruit MCP2221A board.<\/p>\n I will be using the modules in a project and not on a breadboard, thus I will be soldering the headers to point out to the top (like a Raspberry Pi’s GPIO).<\/p>\n I placed the headers inside of a breadboard with the longer leads going into the breadboard.<\/p>\n Then placed the INA260 on top of the headers and soldered them in place.<\/p>\n Next I removed the module from the breadboard and used my Third Hand tool to hold the module while I soldered on the terminal block.<\/p>\n I will be using the Adafruit MCP2221A breakout<\/a> board to communicate via I2C to the Adafruit INA260 board<\/a>.<\/p>\n Please see my post about the Adafruit MCP2221A breakout<\/a> for how I setup Python projects like these on my Mac.<\/p>\n My git repo for this module can be found here<\/a>.<\/p>\n I built a very simple LED circuit powered from the 5V output from the Adafruit MCP2221A that passes through the Adafruit INA260 so that the current draw can be measured. The multimeter is also placed in the circuit to measure the current.<\/p>\n It is basically a LED connected to a 1K resistor. The potentiometer is there so that I can tweak the current draw and verify that the INA260 picks up the change.<\/p>\n Each INA260 can be configured to have one of the following I2C addresses: 0x40, 0x41, 0x44 and 0x45. The default is 0x40. See Adafruit’s pinout<\/a> for more information.<\/p>\n I will be using 3 of the modules in a project and thus will have one that uses the default address of 0x40 and the other two will be 0x41 and 0x44.<\/p>\n Image by Adafruit […]<\/p>\nOverview<\/h2>\n
Soldering on the headers and terminal block<\/h2>\n
Initial I2C testing<\/h2>\n
\n
$ .\/new-project.sh\n$ .\/install-requirements.sh\n<\/code><\/pre>\n
\n
<\/p>\n
\n
# Active the venv and export the required environment variable for Blinka\n$ source source.sh\n(venv)$ cd examples\n(venv)$ python3 i2c-scan.py\n\nI2C addresses found: ['0x40']\n<\/code><\/pre>\n
\n
(venv)$ pip3 install adafruit-circuitpython-ina260\n(venv)$ .\/update-requirements.sh\n<\/code><\/pre>\n
\n
measure.py<\/code>.<\/li>\n<\/ul>\n
# Source from: https:\/\/learn.adafruit.com\/adafruit-ina260-current-voltage-power-sensor-breakout\/python-circuitpython\n# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries\n# SPDX-License-Identifier: MIT\n\nimport time\nimport board\nimport adafruit_ina260\n\ni2c = board.I2C()\nina260 = adafruit_ina260.INA260(i2c)\nwhile True:\n print(\n "Current: %.2f mA Voltage: %.2f V Power:%.2f mW"\n % (ina260.current, ina260.voltage, ina260.power)\n )\n time.sleep(1)\n<\/code><\/pre>\n
\n
(venv)$ python3 measure.py\n\nCurrent: 0.00 mA Voltage: 0.00 V Power:0.00 mW\nCurrent: 0.00 mA Voltage: 0.00 V Power:0.00 mW\nCurrent: 1.25 mA Voltage: 0.00 V Power:0.00 mW\nCurrent: 0.00 mA Voltage: 0.00 V Power:0.00 mW\nCurrent: 1.25 mA Voltage: 0.00 V Power:0.00 mW\nCurrent: 1.25 mA Voltage: 0.00 V Power:0.00 mW\n<\/code><\/pre>\n
Measure a simple circuit<\/h2>\n
<\/p>\n
<\/p>\n
\n
measure.py<\/code> program.<\/li>\n<\/ul>\n
(venv)$ python3 measure.py\nCurrent: 2.50 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 2.50 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 3.75 mA Voltage: 5.04 V Power:30.00 mW\nCurrent: 3.75 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 3.75 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 5.00 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 5.00 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 2.50 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 3.75 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 5.00 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 5.00 mA Voltage: 5.04 V Power:10.00 mW\nCurrent: 3.75 mA Voltage: 5.04 V Power:10.00 mW\n<\/code><\/pre>\n
\n
Change the I2C address<\/h2>\n
<\/p>\n
<\/p>\n
\n
$ python3 i2c-scan.py\nI2C addresses found: ['0x41']\n<\/code><\/pre>\n
\n
<\/p>\n
\n
$ python3 i2c-scan.py\nI2C addresses found: ['0x44']\n<\/code><\/pre>\n
\n
ina260 = adafruit_ina260.INA260(i2c, address=0x41)\n<\/code><\/pre>\n
Reference<\/h2>\n
\n
\n