DIY Electronics
— Building circuits, programming microcontrollers, and making things blinkBootloader not detected on STM32 — common causes
Measuring Current with INA219
The INA219 is a $1 current sensor IC that measures both current and voltage over I2C and gives you power directly. Here's how to use it correctly.
The shunt resistor value determines your current range and resolution. The INA219 measures ±320mV across the shunt. For a 0.1 ohm shunt, maximum current is 3.2A with 100μA LSB. For a 0.01 ohm shunt, maximum current is 32A with 1mA LSB. Choose the shunt based on your expected current range and the voltage drop budget — a 0.1 ohm shunt at 3A drops 300mV, acceptable for a 12V system but significant for a 3.3V system.
Calibration register: the INA219 has a calibration register that scales the current register to read in natural units (amps) directly. The formula is in the datasheet. Program it once during initialization and the current and power registers give you correct values without any floating-point math in your MCU.