Skip to content

Add INA219 usermod support and update platformio.ini#361

Open
Topchris18 wants to merge 2 commits intoMoonModules:mdevfrom
Topchris18:usermod_ina219
Open

Add INA219 usermod support and update platformio.ini#361
Topchris18 wants to merge 2 commits intoMoonModules:mdevfrom
Topchris18:usermod_ina219

Conversation

@Topchris18
Copy link
Copy Markdown

@Topchris18 Topchris18 commented Apr 16, 2026

Summary by CodeRabbit

  • New Features
    • Added INA219 I2C current and power sensor support for monitoring power consumption
    • Real-time current, power, and voltage readings displayed in device information
    • Fully configurable: I2C address, shunt resistor, maximum current range, and bus voltage range
    • Adjustable sensor read intervals

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@Topchris18 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 3 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 3 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec6d7b92-7667-48ac-bde2-72d7dff80651

📥 Commits

Reviewing files that changed from the base of the PR and between c3e9aec and 4bb2dfe.

📒 Files selected for processing (2)
  • platformio.ini
  • usermods/INA219_v2/usermod_ina219.h

Walkthrough

This PR adds INA219 I2C current/power sensor support to WLED via a new usermod. Changes include the Adafruit INA219 library dependency, the usermod implementation with I2C integration and sensor calibration, registration within the build system, and the usermod identifier constant definition.

Changes

Cohort / File(s) Summary
INA219 Usermod Implementation & Integration
usermods/INA219_v2/usermod_ina219.h, wled00/usermods_list.cpp, wled00/const.h
New INA219 usermod with I2C bus integration, sensor initialization, periodic voltage/current reading, configurable calibration presets, JSON info output, and persistent configuration storage. Build system registration added with usermod identifier constant.
Project Dependencies
platformio.ini
Added Adafruit INA219 library v1.2.1 as optional dependency.

Sequence Diagram(s)

sequenceDiagram
    actor System as WLED System
    participant Usermod as INA219 Usermod
    participant I2C as I2C Bus
    participant Sensor as INA219 Sensor
    participant Config as Config/JSON

    Note over System,Config: Initialization
    System->>Usermod: setup()
    Usermod->>I2C: joinWire()
    Usermod->>Sensor: Adafruit_INA219(address)
    Usermod->>Sensor: begin()
    Usermod->>Sensor: setCalibration_<br/>(bus voltage, max current)
    Sensor-->>Usermod: Calibration applied

    Note over System,Config: Periodic Reading Loop
    loop Every read interval
        System->>Usermod: loop()
        Usermod->>I2C: Read shunt voltage
        I2C->>Sensor: Request V_shunt
        Sensor-->>I2C: V_shunt value
        I2C-->>Usermod: V_shunt
        Usermod->>I2C: Read bus voltage
        I2C->>Sensor: Request V_bus
        Sensor-->>I2C: V_bus value
        I2C-->>Usermod: V_bus
        Usermod->>Usermod: Calculate current, power
    end

    Note over System,Config: Configuration & Output
    System->>Usermod: addToJsonInfo()
    Usermod-->>Config: Sensor readings (JSON)
    System->>Usermod: readFromConfig()
    Config->>Usermod: Updated settings
    Usermod->>Usermod: Reinit if address changed<br/>or reapply calibration
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main changes: adding INA219 usermod support and updating platformio.ini.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@platformio.ini`:
- Around line 297-298: The new global dependency line "adafruit/Adafruit INA219
@ 1.2.1" was added under the global [env] and therefore affects all build
environments; revert this change from the global section and either move the
dependency into the specific environment(s) that need the INA219 or leave it
commented with a clear TODO requiring explicit maintainer/WLED org approval
before enabling. Ensure you reference the dependency string "adafruit/Adafruit
INA219 @ 1.2.1" when making the change and add a brief sign-off note (e.g.,
"Requires maintainer approval") so reviewers can approve before it becomes
active.

In `@usermods/INA219_v2/usermod_ina219.h`:
- Around line 119-120: The computation of current (current_mA = shuntVoltage_mV
/ (shuntResistor_mOhm / 1000.0f)) can divide by zero or a tiny value if
shuntResistor_mOhm is misconfigured; validate and clamp shuntResistor_mOhm when
loading config (where it’s set) to a safe minimum (e.g. >0 and not near-zero)
and add a runtime guard before computing current in the measurement path (check
shuntResistor_mOhm against the minimum, skip or set current_mA/power_mW to 0 and
log/warn if invalid). Ensure you update symbols: shuntResistor_mOhm validation
at config load and the check around current_mA/power_mW calculation that uses
shuntVoltage_mV and loadVoltage_V.
- Around line 62-69: applyCalibration currently favors 32V calibrations whenever
maxCurrentRange_A > 0.4, ignoring a configured busVoltageRange_V of 16V; update
applyCalibration to first branch on busVoltageRange_V (e.g., if
busVoltageRange_V <= 16) and then choose the correct current-based calibration
(call ina219->setCalibration_16V_400mA for <=0.4A else a 16V+higher-current
routine if available), otherwise for busVoltageRange_V > 16 choose the 32V
calibrations (use ina219->setCalibration_32V_1A or ina219->setCalibration_32V_2A
based on maxCurrentRange_A); make the same voltage-first decision wherever the
settings from busVoltageRange_V/maxCurrentRange_A are applied (references:
function applyCalibration, variables busVoltageRange_V and maxCurrentRange_A,
and methods ina219->setCalibration_16V_400mA, ina219->setCalibration_32V_1A,
ina219->setCalibration_32V_2A).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ca8f889-7b42-4cb8-858e-7c6fa6fed515

📥 Commits

Reviewing files that changed from the base of the PR and between 83368c3 and c3e9aec.

📒 Files selected for processing (4)
  • platformio.ini
  • usermods/INA219_v2/usermod_ina219.h
  • wled00/const.h
  • wled00/usermods_list.cpp

Comment thread platformio.ini Outdated
Comment thread usermods/INA219_v2/usermod_ina219.h Outdated
Comment thread usermods/INA219_v2/usermod_ina219.h Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants