You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add INA226 support as both a battery voltage source and current meter source.
This uses the INA226 shunt-voltage and bus-voltage registers directly, so INAV keeps using its existing battery pipeline for filtering, power, mAh/mWh, alarms, OSD, telemetry, and stats. It does not depend on the INA226 calibration/current/power registers.
Details
Add CURRENT_SENSOR_INA226 and VOLTAGE_SENSOR_INA226.
Add INA226 to the CLI current_meter_type and vbat_meter_type settings.
Add an INA226 I2C driver behind USE_INA226.
Register INA226 through the bus-device system with:
INA226_I2C_BUS
optional INA226_I2C_ADDRESS
default address 0x40
Detect INA226 using manufacturer ID and die ID registers.
Read:
shunt voltage register 0x01
bus voltage register 0x02
Convert INA226 bus voltage using 1.25 mV/bit.
Convert shunt voltage to centiamps using ina_shunt_res_uohm.
Add ina_shunt_res_uohm as a CLI setting for INA226 shunt resistor value in micro-ohms.
Add shared USE_BATTERY_VOLTAGE_SENSOR gating so non-ADC voltage sources can use the normal battery voltage/profile/power-limit settings.
Keep existing ADC defaults unchanged unless a target explicitly opts into INA226.
Target Opt-In
This PR does not change any official target default voltage/current source.
Targets that have an INA226 can opt in with something like:
INA226_I2C_ADDRESS is optional and defaults to 0x40.
Notes
The setting is named ina_shunt_res_uohm instead of using ina226 in the CLI setting name. This avoids issues with the settings-name compressor on some F4 targets.
The first version supports one INA226 device per target. Address scanning and runtime address configuration can be added later if needed.
Hardware Test
Tested on:
Target: MATEKH743
INAV: 9.0.1-based branch
INA226 connected on CL2/DA2, which maps to I2C2 PB10/PB11
Shunt: 0.3 mOhm
CLI setting:
set ina_shunt_res_uohm = 300
save
Result:
Battery voltage reads correctly.
Current reads correctly.
INAV Configurator status page shows expected voltage/current values.
Verified against an external electronic load / power meter.
Observed values:
Source
Voltage
Current
Power
INAV Configurator
12.11 V
2.14 A
25.91 W
External meter
12.097 V
2.000 A
24.197 W
The current difference is expected to depend on shunt tolerance, wiring, load stability, and filtering/calibration.
You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:
maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.
maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x
If master is the correct target for this change, no action is needed.
This is an automated suggestion to help route contributions to the appropriate branch.
238 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.
Development build for testing only. Use Full Chip Erase when flashing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add INA226 support as both a battery voltage source and current meter source.
This uses the INA226 shunt-voltage and bus-voltage registers directly, so INAV keeps using its existing battery pipeline for filtering, power, mAh/mWh, alarms, OSD, telemetry, and stats. It does not depend on the INA226 calibration/current/power registers.
Details
CURRENT_SENSOR_INA226andVOLTAGE_SENSOR_INA226.INA226to the CLIcurrent_meter_typeandvbat_meter_typesettings.USE_INA226.INA226_I2C_BUSINA226_I2C_ADDRESS0x400x010x021.25 mV/bit.ina_shunt_res_uohm.ina_shunt_res_uohmas a CLI setting for INA226 shunt resistor value in micro-ohms.USE_BATTERY_VOLTAGE_SENSORgating so non-ADC voltage sources can use the normal battery voltage/profile/power-limit settings.Target Opt-In
This PR does not change any official target default voltage/current source.
Targets that have an INA226 can opt in with something like:
INA226_I2C_ADDRESSis optional and defaults to0x40.Notes
The setting is named
ina_shunt_res_uohminstead of usingina226in the CLI setting name. This avoids issues with the settings-name compressor on some F4 targets.The first version supports one INA226 device per target. Address scanning and runtime address configuration can be added later if needed.
Hardware Test
Tested on:
MATEKH7430.3 mOhmResult:
Observed values:
The current difference is expected to depend on shunt tolerance, wiring, load stability, and filtering/calibration.
Test Photos