element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member and Staff Blogs Analog Discovery 3 - current and power measurement
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: kk99
  • Date Created: 16 May 2026 6:22 PM Date Created
  • Views 70 views
  • Likes 4 likes
  • Comments 2 comments
  • ina219
  • Analog Discovery 3
Related
Recommended

Analog Discovery 3 - current and power measurement

kk99
kk99
16 May 2026

image

Background 

The Analog Discovery 3 has support for two programmable power supplies with a voltage range 0.5V to 5V and -0.5V to -5V. These power supplies have support for voltage readback, but there is no information about current usage. Even though these power supplies are limited, but they are very useful in the case of testing of low voltage devices. To measure current, we can use a shunt resistor and oscilloscope/voltmeter channel, but this causes this channel to not be available for other purposes. Thus, I have decided to use a separate module with INA219 to measure of current and power of a given used power line of power supply.

Implementation

image

The INA219 is a high-precision current sensor integrated circuit developed by Texas Instruments. It allow to measure current, voltage, and power in electronic circuits through an I2C communication interface. The INA219 can measure bus voltages from 0-26V and currents up to +/-3.2A using a shunt resistor. It includes a 12-bit ADC and provides accurate digital readings. The INA219 requires configuration and calibration before accurate measurements can be obtained. The configuration register is used to set parameters such as voltage range, ADC resolution, and operating mode, while the calibration register defines the scaling for current and power measurements. After initialization, the device allows reading voltage, current, and power values directly from dedicated registers through the I2C interface. I have set the configuration register to value 0x019F, which sets bus voltage to range 16V, programmable gain amplifier to range +/- 40mV, usage of 12 bit ADC and continuous shunt and bust measurements. The calibration register was set to value 0xA000, which corresponds to 10uA/bit and 200uW/bit register resolutions for current and power. In the INA219 datasheets there are equations that allow us to calculate the calibration value based on the expected maximum current. In my case, it was around 327,68mA.

image

I have decided to power supply the INA219 device via a DIO2 pin. Other connections are standard. In my test circuit, I used V+ line to measure and power the load. The connections to the Analog Discovery 3 are on the above diagram, marked by green labels.

In WaveForms, I have used the Script instrument to do my main job. This Script instrument executes a script which uses StaticIO to drive a DIO2 pin, which provides power supply for INA219. The Protocol instrument was used to provide communication via I2C. After setting the power supply for the INA219 and initializing the I2C protocol, the script configures calibration and configuration for INA219. Then the main loop which reads voltage, current and power starts. The results are presented in the console output. There is an option to enable a plot, which starts displaying the trend of the current. Below is the source code of the script: 

clear()

if(!('StaticIO' in this)) throw "Please open the StaticIO instrument";
if(!('Protocol' in this)) throw "Please open the Protocol instrument";

print("Enable INA219 power supply");
StaticIO.Channel0.DIO2.Mode.text = "Switch";
StaticIO.Channel0.DIO2.Switch.text = "PP";
StaticIO.Channel0.DIO2.text = "1";

wait(0.1);

print("Configure I2C settings");
Protocol.I2C.SCL.DIO = 0;
Protocol.I2C.SDA.DIO = 1;
Protocol.I2C.Rate = 100000;

// INA219 I2C address
var addr = 0x40;

// ---------- Registers ----------
var REG_CONFIG = 0x00;
var REG_BUS     = 0x02;
var REG_POWER   = 0x03;
var REG_CURRENT = 0x04;
var REG_CALIB   = 0x05;

function readRegister(reg){
    Protocol.I2C.Write(addr, [reg]);
    var data = Protocol.I2C.Read(addr, 2);
    return (data[0] << 8) | data[1];
}

function readBusVoltage(){
    var raw = readRegister(REG_BUS);
    // remove CNVR + OVF flags
    raw = raw >> 3;
    // 4mV per bit
    return raw * 0.004;
}

function readCurrent(){
    var raw = readRegister(REG_CURRENT);
    // signed conversion
    if(raw > 32767)
        raw -= 65536;
    // 10uA per bit
    return raw * 0.01;
}

function readPower(){
    var raw = readRegister(REG_POWER);
    // 200uW per bit = 0.2mW
    return raw * 0.2;
}

// ============================================
// INA219 configuration
// ============================================
//
// Config      = 0x019F
// Calibration = 0xA000
//
// Current_LSB = 10uA/bit
// Power_LSB   = 200uW/bit
// ============================================

// ---------- Write Calibration ----------
Protocol.I2C.Write(addr, [
    REG_CALIB,
    0xA0,
    0x00
]);

// ---------- Write Configuration ----------
Protocol.I2C.Write(addr, [
    REG_CONFIG,
    0x01,
    0x9F
]);

print("INA219 configured");
wait(0.1);

if(typeof plot1 !== "undefined" && plot1) {
    plot_values = [];
    plot1.Y1.Units.text = "mA";
    plot1.X.Units.text = "s";
    plot1.X.Range.text = '0.5s/div';
    plot1.Y1.AutoScale.checked = true;
}

while(wait(0.5)) {
    var voltage   = readBusVoltage();
    var current_mA = readCurrent();
    var power_mW   = readPower();

    if(typeof plot1 !== "undefined" && plot1) {
        plot_values.push(current_mA);
        plot1.Y1.data = plot_values;
    }

    print(
        "Voltage: " + voltage.toFixed(3) + " V" +
        " | Current: " + current_mA.toFixed(3) + " mA" +
        " | Power: " + power_mW.toFixed(3) + " mW"
    );
}

print("Disable INA219 power supply");
StaticIO.Channel0.DIO2.Mode.text = "Switch";
StaticIO.Channel0.DIO2.Switch.text = "PP";
StaticIO.Channel0.DIO2.text = "0";

Results

image

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

The module with INA219 is really useful and with a simple script allowing to track current and power usage of the load device. At the same time, we are still able to use both channels of the oscilloscope for other purposes. Additionally, with the usage of only the Protocol instrument and I2C/Sensor mode, we could create a setup that will perform logging, e.g. to file this information about power/current usage of load under test. This is really useful in the case of long-term measurements or low-power modes of the tested device.

  • Sign in to reply
  • kk99
    kk99 6 days ago in reply to DAB

    I am trying to get the most of this instrument.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB 7 days ago

    Nice experiment.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube