The INA3221 uses shunt resistors to measure current. The system automatically calibrates for 500mΩ (0.5Ω) shunt resistors by default. If you have different values, you need to recalibrate.
Common shunt resistor values and their micro-ohm equivalents:
| Resistance | Micro-ohms | Use Case |
|---|---|---|
| 5mΩ | 5000 | Very high current (>10A) |
| 10mΩ | 10000 | High current (5-10A) |
| 100mΩ | 100000 | Medium current (1-5A) |
| 500mΩ | 500000 | Low current (<1A) - Default |
| 1Ω | 1000000 | Very low current (<500mA) |
Important: Ensure your shunt resistor can handle the expected current and power dissipation.
Use the provided calibration script:
# For default 500mΩ shunt resistors
sudo ./calibrate_ina3221.sh
# For custom values, edit the script first:
nano calibrate_ina3221.sh
# Change: SHUNT_VALUE=500000 # to your value in micro-ohms
sudo ./calibrate_ina3221.shSet shunt resistor values directly:
# Find your hwmon device first
HWMON=$(ls -d /sys/bus/i2c/devices/1-0041/hwmon/hwmon* 2>/dev/null | head -n1)
# Set values (in micro-ohms):
sudo bash -c "echo 100000 > $HWMON/shunt1_resistor" # Channel 0: 100mΩ
sudo bash -c "echo 100000 > $HWMON/shunt2_resistor" # Channel 1: 100mΩ
sudo bash -c "echo 100000 > $HWMON/shunt3_resistor" # Channel 2: 100mΩ
# Verify the values were set
cat $HWMON/shunt1_resistor
cat $HWMON/shunt2_resistor
cat $HWMON/shunt3_resistor
# Test readings
sudo ./read_ina3221_sensors.shTo make custom calibration persistent across reboots, edit the setup script:
# Edit the setup script
nano setup_ina3221.sh
# Find the calibration section and change these lines:
# From:
echo 500000 > $HWMON/shunt1_resistor
echo 500000 > $HWMON/shunt2_resistor
echo 500000 > $HWMON/shunt3_resistor
# To (example for 100mΩ):
echo 100000 > $HWMON/shunt1_resistor
echo 100000 > $HWMON/shunt2_resistor
echo 100000 > $HWMON/shunt3_resistor
# Re-run setup to apply changes
sudo ./setup_ina3221.shIf you need to measure your shunt resistor value:
- Disconnect the shunt resistor from the circuit
- Use a 4-wire (Kelvin) measurement if possible
- Set multimeter to lowest resistance range
- Measure multiple times and average
Check your INA3221 breakout board documentation for the shunt resistor value.
If you know the actual current:
- Read the voltage across the shunt:
cat /sys/class/hwmon/hwmonX/in1_input - Measure actual current with a known-good ammeter
- Calculate: R = V / I (in ohms)
- Convert to micro-ohms: multiply by 1,000,000
After calibration, verify accuracy:
# Method 1: Compare with known load
# - Connect a known load (e.g., resistor with measured voltage)
# - Calculate expected current
# - Compare with INA3221 reading
# Method 2: Use external ammeter
# - Connect ammeter in series
# - Compare readings
# Method 3: Check power calculation
# Power should equal: (Voltage × Current) / 1000
sudo ./read_ina3221_sensors.shThe shunt resistor dissipates power: P = I² × R
Example: 5A through 100mΩ = 5² × 0.1 = 2.5W
Ensure your shunt resistor is rated for the power dissipation!
The INA3221 has these limits:
- Shunt voltage: ±163.8mV max
- Bus voltage: 0-26V
- Maximum current depends on shunt resistor
Calculate max current: I_max = 163.8mV / R_shunt
Examples:
- 5mΩ → 32.76A max
- 100mΩ → 1.638A max
- 500mΩ → 327.6mA max
- Use precision shunt resistors (1% or better tolerance)
- Temperature coefficient affects accuracy
- Kelvin (4-wire) connection recommended for low values
You can use different shunt values for each channel:
HWMON=$(ls -d /sys/bus/i2c/devices/1-0041/hwmon/hwmon* 2>/dev/null | head -n1)
# Different values for each channel
sudo bash -c "echo 10000 > $HWMON/shunt1_resistor" # Ch0: 10mΩ (high current)
sudo bash -c "echo 100000 > $HWMON/shunt2_resistor" # Ch1: 100mΩ (medium current)
sudo bash -c "echo 500000 > $HWMON/shunt3_resistor" # Ch2: 500mΩ (low current)HWMON=$(ls -d /sys/bus/i2c/devices/1-0041/hwmon/hwmon* 2>/dev/null | head -n1)
# Check current calibration
echo "Channel 0: $(cat $HWMON/shunt1_resistor) µΩ"
echo "Channel 1: $(cat $HWMON/shunt2_resistor) µΩ"
echo "Channel 2: $(cat $HWMON/shunt3_resistor) µΩ"
# Calculate max measurable current for each channel
echo "Max current Ch0: $(echo "scale=2; 163800 / $(cat $HWMON/shunt1_resistor)" | bc) mA"
echo "Max current Ch1: $(echo "scale=2; 163800 / $(cat $HWMON/shunt2_resistor)" | bc) mA"
echo "Max current Ch2: $(echo "scale=2; 163800 / $(cat $HWMON/shunt3_resistor)" | bc) mA"-
Verify shunt resistor value:
cat $HWMON/shunt1_resistor -
Check actual shunt resistor with multimeter
-
Recalibrate with correct value
-
Verify connections (ensure good contact)
- Shunt resistor value too high for the current
- No current flowing through the circuit
- Shunt resistor not properly connected
- Shunt voltage exceeds ±163.8mV
- Need smaller shunt resistor value
- Current exceeds measurement range
This is normal! Negative current indicates:
- Current flowing in opposite direction
- Typical for battery charging/discharging monitoring
- Channel 1 in your setup likely shows negative when charging