Skip to content

[P132] Additional support for INA226, INA228, INA230, INA231 and INA260#5462

Merged
TD-er merged 18 commits intoletscontrolit:megafrom
tonhuisman:feature/P132-add-support-for-other-INA-chips
Mar 2, 2026
Merged

[P132] Additional support for INA226, INA228, INA230, INA231 and INA260#5462
TD-er merged 18 commits intoletscontrolit:megafrom
tonhuisman:feature/P132-add-support-for-other-INA-chips

Conversation

@tonhuisman
Copy link
Contributor

@tonhuisman tonhuisman commented Dec 26, 2025

Resolves #2622
Resolves #2602
Forum request: https://www.letscontrolit.com/forum/viewtopic.php?t=10746
Forum request: https://www.letscontrolit.com/forum/viewtopic.php?p=74843

Features:

  • [P132] Add support for:
    • INA219 (Is already supported in P027, with more configuration options, it's also included in this library)
    • INA226
    • INA228 (waiting for hardware to arrive)
    • INA230 (no hardware available)
    • INA231 (often detected as INA226, but has lower specs)
    • INA260 (built-in shunt resistor)
  • By default only enabled for ESP32, but can be enabled in an ESP8266 Custom build

TODO:

  • Update documentation
  • Testing!
    • INA3221
    • INA219
    • INA226
    • INA228
    • INA230 (not able to test for no hardware available)
    • INA231 (is detected as INA226)
    • INA260 (waiting for hardware to arrive)
  • Refactor 'Max. current' and 'Shunt resistor' settings for higher resolution and better match.

@Gonzol999
Copy link

Great job, thank you very much, I'm interested in INA228 support myself. Will there be binaries available for download for the ESP32?

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Dec 28, 2025

Will there be binaries available for download for the ESP32?

Assuming you mean ESP32-Classic, here are the builds that this plugin is included in:

ESP_Easy_mega_20251228_energy_ESP32_4M316k-2.zip for ESP32 with 4MB Flash
ESP_Easy_mega_20251228_max_ESP32_16M8M-2.zip for ESP32 with 16MB Flash

Both include the OTA .bin and the Serial-flashable .factory.bin (address 0x0).

Edit: Re-uploaded the zip files (appended -2) with the adjusted Conversion rate settings I pushed a few minutes ago.

NB: Possibly the INA228 Power setting might not return the expected result, as the code shows a TODO there... 🤔

@Gonzol999
Copy link

Thanks for the binaries. I loaded the 4M316k.factory module, and it boots up, but I doubt it will work correctly. There's no option to select the shunt value. Without checking the documentation, I'm not entirely sure if all the INA3221/INA226/INA228/INA231/INA260 models have the same registers. At first glance, the INA3221 is a 3-channel model, while the others aren't. So how would this work without selecting the INA model in the plugin?

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Dec 28, 2025

So how would this work without selecting the INA model in the plugin?

Not sure what/how you installed the binary, but the P132 plugin ("Energy (DC) - INA3221/INA226/INA228/INA231/INA260") should show an INA type selector, where you can choose what INA chip is used on the board, and ditto for the Shunt resistor value (that selector was already available in the original version of the plugin, and now has 2 extra values added).
Can you show a screenshot of the device configuration for the plugin? Does it show the name of the build near the bottom-right end of the web page? It should be of today, 20251228, as I made a fresh build (also reflected in the name of the .zip files).

@Gonzol999
Copy link

Config ESP32 Devices INA228_1 Devices INA228_2

@tonhuisman
Copy link
Contributor Author

Ah, this is a phenomenon we sometimes see when some other firmware (ESPHome, Espruna, Tasmota?) has been used on the esp, and the flash hasn't been wiped before installing ESPEasy. It tries to re-use an existing file system, but if that's too small it fails in writing the configuration file(s), causing weird behavior and/or crashed like you have shown.
Solution: First wipe the entire flash, you can do that using the web-flasher at https://td-er.nl/ESPEasy/latest, flash the last Energy build on it, connect to WiFi as usual and then install the above build via OTA (Tools/Firmware update) using the .bin file (not the .factory.bin file). Your current configuration is crooked anyway, so starting from scratch is the best way to solve that.

@Gonzol999
Copy link

Thank you again for your involvement and willingness to help. It's possible this is a hardware issue with my ESP32; none of the methods I know of for clearing the memory have yielded positive results. Since I only have one ESP32 board (I have many, but they're ESP8266s), I've ordered another ESP32, but it will probably take some time for them to arrive.

@tonhuisman
Copy link
Contributor Author

I have many, but they're ESP8266s

I've built you a Custom Energy build with this feature enabled for ESP8266 with 4MB Flash:
ESP_Easy_mega_20251229_energy_ESP8266_4M1M.zip
(The .bin.gz is a gzipped version of the .bin file, for faster upload via OTA, allow about 20 seconds after the OTA upload has finished so the data is unpacked in the correct flash location)

@Gonzol999
Copy link

Another huge thank you. The ESP8266 binary is better. Almost everything seems to work, but there's a problem with reading data. Admittedly, I've been experimenting with the INA226 for a while now. I have a question: instead of selecting the internal resistor value, there should be an option to select a shunt, e.g., 30A (75mV), etc., because these built-in resistors are intended for small pads.

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Dec 29, 2025

Selecting a different shunt resistor is mostly a wiring issue, finding the right shunt value (for 30A the 2 mOhm setting should be just right for an INA226), find a 0.002 Ohm resistor that can handle the power dissipation, remove the existing shunt from the board and wire the new shunt to the board.
Currently 0.002 Ohm is the smallest shunt supported, (and previously 0.005 Ohm was the smallest, allowing ca. 16A), but nobody ever asked for smaller or more flexible configuration (the plugin was available in the ESPEasy PluginPlayground before we added it to ESPEasy), so until now there was no reason to change that 🤔

@Gonzol999
Copy link

I don't care about such currents, but this connector allows you to select a current in the range [1-1022 A], but there's still no option to change the shunt, and that's where I see a lack of consistency. A while ago, a similar build for the ESP8266 and INA226 was posted on the forum, with the option to change the shunt to an external one. Again, I don't care about that.

@tonhuisman
Copy link
Contributor Author

Those shunts are for 75mV. Some of the INA chips, like INA219 and INA228, can handle higher shunt voltages, up to 320mV for INA219, and 160mV (fixed) for INA228. But that would still work fine, would just be a resolution-related issue.

@tonhuisman
Copy link
Contributor Author

allows you to select a current in the range [1-1022 A], but there's still no option to change the shunt,

Well, I can limit that max. value to, say, 30A, I just added the max current setting as it is required for the new library I'm using.

@Gonzol999
Copy link

These currents don't bother me at all, so they can stay as they are.

@tonhuisman
Copy link
Contributor Author

I've changed the resolution for the Shunt setting, and added more options for high-current shunts, to better match those to the Max. current setting.
@Gonzol999 Here's a Custom Energy build for ESP8266 for testing:
ESP_Easy_mega_20251230_energy_ESP8266_4M1M.zip

@Gonzol999
Copy link

I don't have a shunt at home because I don't measure such high currents. I downloaded your binary; in my opinion, it offers much more options. I'll get myself a shunt, let's say the smallest one, and run some tests. Thanks again.

@Gonzol999
Copy link

The current readings are stable but unrealistic. I'm testing a current of about 3 A, and the ESP with the current load shows 2732.02 A.
What is the purpose of the Max. Current: checkbox if there's a shunt resistor:?

@TD-er
Copy link
Member

TD-er commented Jan 25, 2026

Hmm sounds like a mixup of mA and uA somewhere. (or mV vs uV)

@Gonzol999
Copy link

Have you tested this yourself, or has anyone else done it? Maybe the problem is how I do it.

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Jan 25, 2026

The current readings are stable but unrealistic. I'm testing a current of about 3 A, and the ESP with the current load shows 2732.02 A.

It's not obvious from either the configuration or the documentation, but this plugin shows the Current values in mA, as it always has. It seems that the value is in the expected range. You can use the Formula field to convert to A, if desired.

What is the purpose of the Max. Current: checkbox if there's a shunt resistor:?

The actual current to measure doesn't have to match the capacity of the shunt, then only a part of the 75mV output is being used.
The Max. expected current setting (as documented but not yet published) is used to set the resolution as optimal as possible. If high currents are expected, then the range is larger, so resolution is lowered, but also reducing precision.

@Gonzol999
Copy link

Thanks for the replies.

If the plugin is supposed to return measurement results in mA, then it's probably OK. Yesterday, I solved the problem with the formula, dividing the measured value by 1000. You've clarified my doubts about the measurement range selection field. I'll continue testing your results with other settings.

@TD-er
Copy link
Member

TD-er commented Jan 26, 2026

Do you have other chips which are also supported by this plugin?
If so, I would greatly appreciate it if you could also try those on the same setup, just to make sure switching chip-models is also working properly and there isn't something else which is not intuitive.

Ton did move quite a lot of code around, so it is possible something got overlooked.

@Gonzol999
Copy link

I already have an INA228 at home, but I'm still waiting for the ESP32 from AliExpress. Testing would need to be done on the ESP32. For testing, I need to build a receiver with a more stable current source, preferably a resistor, because as you mentioned earlier, a UPS isn't the best receiver for such tests. But I can still test.

@Gonzol999
Copy link

Gonzol999 commented Jan 31, 2026

Hello everyone.

I started testing the INA228 plug-in today, still with a low voltage of around 14V and a very low current of around 0.2A. The voltage measurements are OK, but the current is significantly off. The value measured by the plug-in fluctuates between 1.86 and 5.37mA. If, as Ton wrote earlier, the plug-in returns a value in mA, this result is outrageous. The board has a standard shunt resistor of 0.002Ω, and I have the Max. Current set to the lowest range, which is 1A. I noticed another problem: in the Tools/Interfaces tab, there's an I2C Scan tool. The Supported Devices field should indicate which module was found on the bus, but it's blank. The same is true for the INA226, so it's probably the plug-in's fault. One more question: INA228 modules have GPIO alerts. Do you plan to support this feature in the plug-in?

@tonhuisman
Copy link
Contributor Author

but the current is significantly off.

Hm, that's somewhat unexpected. I recently (today) received an INA228. I'll hook that up and see what results I can achieve.

... I2C Scan tool. The Supported Devices field should indicate which module was found on the bus, but it's blank. The same is true for the INA226, so it's probably the plug-in's fault.

Depending on the build, many known device names are included. For ESP8266 builds these names are not included for space reasons.

One more question: INA228 modules have GPIO alerts. Do you plan to support this feature in the plug-in?

That's currently not planned.

@Gonzol999
Copy link

ale prąd jest znacznie odchylony.

Hm, to trochę nieoczekiwane. Niedawno (dzisiaj) dostałem INA228. Podłączę go i zobaczę, jakie efekty uda mi się osiągnąć.

With our voltages, the discrepancies and instability in the reading are similar. It's possible that my INA228 board is of poor quality. How are your tests?

... Narzędzie skanujące I2C. Pole „Obsługiwane urządzenia” powinno wskazywać, który moduł został znaleziony na magistrali, ale jest puste. To samo dotyczy INA226, więc prawdopodobnie wina leży po stronie wtyczki.

W zależności od wersji, uwzględniono wiele znanych nazw urządzeń. W przypadku wersji ESP8266 nazwy te nie są uwzględniane ze względu na brak miejsca.

This is not a problem, the found module address is returned and if someone connects the module to the I2C bus, they probably know what they are connecting

Jeszcze jedno pytanie: moduły INA228 mają alerty GPIO. Czy planujecie obsługę tej funkcji we wtyczce?

Na razie nie ma takich planów.

this is also not a problem, similar functionality can be achieved using rules and e.g. the ESP GPIO port

@sracing
Copy link

sracing commented Feb 12, 2026

Hi, I am also desperately looking for INA226 integration, found this discussion here. Just ordered a ESP32-S3 with 16MB. Wanted to use the Max Firmware, since I have a couple of other sensors that need to be connected as well. However, I guess if I downlad the latest Release build from the Github Releases page, probably the P132 update for the INA 226 will not (yet) be in?

@tonhuisman
Copy link
Contributor Author

This PR isn't merged yet, so the code isn't included in any of the available builds.
You can try to create your own ESP32-S3 MAX build using this PR, though if you don't have any coding experience that can be a bit challenging (here's documentation on how to set up your local development environment for ESPEasy). I won't be able to create a build for you today because of other obligations.

@sracing
Copy link

sracing commented Feb 12, 2026

You are right, no coding experience yet. So far I was always quite happy with the official builds. Guess I will have to wait.
In case you feel you need someone to test, let me know.

@TD-er
Copy link
Member

TD-er commented Feb 12, 2026

You are right, no coding experience yet. So far I was always quite happy with the official builds. Guess I will have to wait. In case you feel you need someone to test, let me know.

I started a GH Actions build for this: https://github.com/letscontrolit/ESPEasy/actions/runs/21550809663
Should be ready in +/- 2 hours

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Feb 12, 2026

@sracing
The above build seems to have failed for some unknown reason, GH does that sometimes 🫣
Here's the ESP32-S3 MAX build for testing (it's the build without PSRAM support, not sure if your board has that, may go into a boot-loop, then just report here and I'll upload the PSRAM build, ESP32-S3 is quite picky about that):
ESP_Easy_mega_20260212_max_ESP32s3_16M8M.zip
Has both the .factory.bin for uploading by using a flash tool at address 0 (initial install), and the .bin for uploading via OTA.

@sracing
Copy link

sracing commented Feb 13, 2026

Wasted quite some time to find out why the flashing does not work till I noticed I got the non-PSRAM version this morning (although I ordered the PSRAM version). So actually I was happy, cause I could use then the .bin from tonhuisman for uploading via OTA. I now have the Git Build "feature/P132-add-support-for-other-INA-chips_348c745" installed, but the P132 does not show a selector for the INA version (I have the INA226):

image

The device settings are actually not visible...

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Feb 13, 2026

What if you enable the device (and Submit the page)?

NB: ESPEasy does not (in fact: shouldn't) communicate with the device until the plugin is enabled, and for auto-detection, it has to communicate with the device... 🤷‍♂️

@sracing
Copy link

sracing commented Feb 13, 2026

Same view. No Device Settings.
But I am actually checking the device if there is a issue. I´ve got a ESP32-S3-N16R8. I should have PSRAM, but I only manage to get the non-PASM firmware running. The PASM firmware does not boot. Give me a bit time to do some checks.

@sracing
Copy link

sracing commented Feb 13, 2026

OK, for reasons whatever, I now managed the PASM version to boot after installation. With the Git Build "feature/P132-add-support-for-other-INA-chips_348c745". Plugin is enabled. I get the same view, no device setting. Plugin is enabled.

The issue was that the I2C Adress was not yet configured in the Hardware tab (as this was a brand new board). Now Device Settings are visible.

Thanks for all the support, I will start testing phase over the weekend and provide feedback.

@TD-er
Copy link
Member

TD-er commented Feb 13, 2026

FYI
The ESP32-S3 with 16M flash and 8M PSRAM needs to access the PSRAM via an OPI SPI link.
The ESP32-S3 with less PSRAM need to access PSRAM with a QIO SPI link.
Sadly this cannot be changed at runtime, and if you try to access PSRAM via the wrong setup SPI link the device will bootloop.
That's why it is a safe bet to use a non-PSRAM build on the S3.

N.B. If you try to use addressable LEDs, like NeoPixel LEDs, you should not run an OPI SPI PSRAM build even if you have a matching board, as this PSRAM OPI SPI mode does interfere with how we try to address those LEDs and you cannot use those LEDs. On those boards you need to run a non-PSRAM build.

See: https://espeasy.readthedocs.io/en/latest/ESPEasy/ESPchips.html#quad-octal-spi-mode

@sracing
Copy link

sracing commented Feb 16, 2026

Thats helpfull information, thanks. I am running the Git Build "feature/P132-add-support-for-other-INA-chips_348c745" from tonhuisman (non PSRAM built) on my ESP32-S3-N16R8 PSRAM since a few days now. The P132 with a INA226 (Standard 0.1 Ohm shunt version, max 0,81A measurement range) works flawless so far. My focus in the application is on the current output for a range of 50mA to 230mA. I made some tests with various sampling and conversion rates, but the standard 1 sample avg. and 1.1 msec already provides stable output under lab conditions. Will continue to do some more tests under field conditions next week, but the additional support for additional INA versions (at least for the INA 226 which I use) is definitively an enrichment.

@sracing
Copy link

sracing commented Mar 2, 2026

Just to add on my last post. P132 with a INA226 still runs stable. No issues during configuration or operations. The Sensor is placed in a area with short, but very strong EMI. A first sensor immediately showed a non-linear behaviour. I suspect the calibration register being impacted by EMI. A second sensor placed in a larger distance has no issues. But thats not related to the Plugin. As said, happy to see the extended plugin in the master.

@TD-er
Copy link
Member

TD-er commented Mar 2, 2026

Which part of your measurements is showing non-linear behavior?
Current measurement or voltage? (or both)

You may want to check if the shunt is getting warm and also if there may be other currents present.
Typically if there is some electrical connection between the power supply of the ESP + sensor and the current you try to measure, you have to make sure there is no potential difference between both grounds.

I think it is unlikely the I2C communication is disturbed, otherwise it would show up as highly 'unstable' readings (if any)

If the shunt is getting warm and the heat is not equally distributed, you may create some offset in the readings of microVolts (or even more) due to the thermocouple effect.
This is caused by joining different metals which create a voltage difference which is highly correlated by the temperature.
Usually this cancels out as this voltage is positive going from metal A to B and negative from B to A. However if there is somehow 1 side which is much warmer (e.g. bad contact), it can make a difference and for a shunt (which already has a low voltage drop) this low voltage offset may be enough to make the readings noticable non-linear.

@sracing
Copy link

sracing commented Mar 2, 2026

Appreciate the input. Actually voltage is not connected. Its the current measurement that shows stable, but non-linear outcome since it was placed close to a ignition wiring - before it was showing inconspicuous results. ESP & Sensor and the current to be measured are on different grounds. Not sure its getting warm, but as mentioned a new sensor now placed in bigger distance works fine since 1 week.

@TD-er
Copy link
Member

TD-er commented Mar 2, 2026

It could be that the EMI disturbances wipe some settings/data in the sensor, but then I would expect it to mess with the calibration points which are just a 2-point calibration. The ADC itself is still linear.

Or is this ignition wire 'firing' quite often, like from a "benzine" engine?
Then it is just messing with the readings.

@sracing
Copy link

sracing commented Mar 2, 2026

The inition firing is not constant during operations, just when starting the device - probably 15 impulses over 3 seconds. I am suspecting the calibration settings in the sensor. I tried to re-install and re-configure the plugin, but the linearity only came back instantly with a new sensor. So it seems to me the first sensor got somehow impacted.

…feature/P132-add-support-for-other-INA-chips
@TD-er TD-er merged commit 586ab10 into letscontrolit:mega Mar 2, 2026
@tonhuisman tonhuisman deleted the feature/P132-add-support-for-other-INA-chips branch March 2, 2026 21:58
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.

Add INA226 Add INA260

5 participants