INA219 vs INA226

3,770 views
Skip to first unread message

Laurentp

unread,
May 24, 2021, 5:41:03 AM5/24/21
to TasmotaUsers
Hi there,
I have 24V solar plant (with batteries), so I need to measure voltages up to 31V and current shunt (750microOhm) up to 75mV.
Can't do this directly with INA219 (too low allowed input voltage), tried to use 2 1:2 voltage dividers but event with 0.1% resistors it gives unreasonable current reading.

How INA226 is supported in Tasmota (sensors)? I can see it detected as INA219 but voltage reading is a bit crazy (1.3V when connected to 3.3V power). According to datasheet INAs226 input ranges matches my needs.

Philip Knowles

unread,
May 24, 2021, 6:39:30 AM5/24/21
to Laurentp, TasmotaUsers

I couldn’t get my INA226s to work properly either so I ended up using a PZEM-017 on the Rx Tx .

BTW I use a separate USB PSU for the PZEM-017 – you can get a current flow from the USB supply if you use the same one for the ESP8266

 

Regards

 

Phil K

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/2f6c0814-0410-47b2-8fec-45baa6cb3414n%40googlegroups.com.

 

jonrus...@googlemail.com

unread,
May 24, 2021, 3:10:31 PM5/24/21
to TasmotaUsers
Hi.
I'm not sure I fully understand your question. But you shouldn't be reading the 75mV with the INA219 sensor.
The sensor gives you a current reading directly. In replaces the current shunt entirely and has a built in 2mR current shunt resistor.
What is the maximum voltage and current of your solar panels you need to measure?
The INA219 can sense 15A @ 36V

I get good results with Tasmota and the INA219.

I've never used an INA226, but it seems you need to configure it with calibration data matching your shunt resistor value.
It only reads raw voltages, so it needs to be calibrated to convert that to current. Not sure how the Tasmota code would do that. You might need to compile your own version.
Also, the datasheet seems to imply the maximum shunt voltage is about 80mV, which on a your 750uR shunt resistor give a maximum full scale reading of 106A.
Is that correct? 


Regards,

Jon.


Laurentp

unread,
May 24, 2021, 4:11:42 PM5/24/21
to TasmotaUsers
> The INA219 can sense 15A @ 36V

NOT correct, look at datasheet, at 26V "maximum absolute rating", it is clearly stated, that higher voltages WILL damage chip. And max 24V Pb battery voltage is 29-30V.
Thats why I have been thinking about voltage divider. But this works for voltage, not for current measuring (divider resistors tolerance is quite big part of measured shunt voltage).

This is why i think about INA226, there are small PCBs with this chip too.


Also, the datasheet seems to imply the maximum shunt voltage is about 80mV, which on a your 750uR shunt resistor give a maximum full scale reading of 106A.
Is that correct? 

Shunt is marked 100A 75mV, so You are right.
I hope find somebody that already played with Tasmota INA code internals. Knowing if there is need to change code handling INA readings.

Did not (yet) compare datasheets (I2C / digital part side)

But INA226 connected to Tasmotized Wemos D1 is detected as INA219 only with incorrect voltage (current sensor not connected) reading.


Laurent

jonrus...@googlemail.com

unread,
May 24, 2021, 5:29:45 PM5/24/21
to TasmotaUsers
Sorry. you're right. Getting my chips mixed up.
I'm also using the INA260 which is 15A @ 36V.
Not sure if Tasmota would recognise it.
But if you need 100A, then the INA226 is your only option.
The answer will be to look in the code. See what registers its calling.
I don't have one to play with, so I cant help debug it.

It seems to have been written by "Copyright (C) 2021  Stephen Rodgers" you might find him in this group, or in a previous post.

If you look in the code (xsns_54_ina226.ino) there's a bunch of commands you can use in the terminal to configure the device ! :-)

* Setup a single INA226 device at address 0x40:
*
* 1. Select a module type with free I2C pins.
* 2. Configure the module to use I2C on the correct pins.
* 3. Connect your ina226 module(s) to the I2C pins.
* 4. Use the i2cscan console command to probe the modules and check they are present.
* 5. Enable the first device at I2C address 0x40 using the following console commands:
*    a. Sensor54 11 [shunt resistance in ohms] e.g. Sensor54 11 0.1
*    b. Sensor54 12 [full scale current in amperes] e.g. Sensor54 12 3.0
*    c. Sensor54 2 saves the settings and restarts Tasmota. The device should show up after the system boots again.
*
*
* This driver will not probe I2C bus for INA226 devices unless the full scale current is set for a device number.

Laurentp

unread,
May 26, 2021, 3:49:32 AM5/26/21
to TasmotaUsers
Ok, looked at driver code, one thing is not 100% clear to me:
- INA219 and INA226 are mutually exclusive (same I2C addresses),
- default "sensors" BIN is built with INA219 support, NO INA226 support?
- so to CORRECTLY recognise / use INA226 I have to compile my own BIN?
(i2c scan returns "device found at 0x40", sensor54 10" returns "command : error").
Device main page displays "INA219: xxx".

Laurent

Laurentp

unread,
May 27, 2021, 5:53:31 AM5/27/21
to TasmotaUsers
"Side question"
- how do I build Tasmota BIN VERSION x.y.z using gitpod? Using default configuration xxxx. (To be changed in my case INA219 -> INA226).

In Wiki there are instructions for master and development, no manual for compiling arbitrary software version.
And how to find which version supports given config ("SetOptionXX") options? (othere than reading README / RELEASE NOTES for every version...

Philip Knowles

unread,
May 27, 2021, 6:59:16 AM5/27/21
to Laurentp, TasmotaUsers

Best way to find out about setoptions is to go into the Issues and search for it. There is normally an accepted pull request for it which version it was first implemented. If you mean which bins have which things in the builds page is the answer

Tasmota/BUILDS.md at development · arendst/Tasmota (github.com)

Regards

 

Phil K

 

Sent from Mail for Windows 10

 

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
May 27, 2021, 9:17:19 AM5/27/21
to TasmotaUsers
Thx,
this matrix confirms, that I have to build my own BIN, as INA226 is nowhere included.

This returns to previous question: - how to build arbitrary version using GITPOD?

Philip Knowles

unread,
May 27, 2021, 10:11:10 AM5/27/21
to Laurentp, TasmotaUsers

I don’t think you need to recompile. If you look at the datasheets the calibration is different so you may just be able to scale the readings you get.

INA219 - CALl = 0.04096(Current_LSB*R´ SHUN)

INA226 - CAL = 0.00512/(Current_LSB*RSHUN)

The Power register is set to 20x Current_LSB in INA219 and 25x in INA226.

All this points to the readings being offset by a consistent amount so it should be relatively easy to scale the output

INA219 Zerø-Drift, Bidirectional Current/Power Monitor With I2C Interface datasheet (Rev. G)

INA226 High-Side or Low-Side Measurement, Bi-Directional Current and Power Monitor with I2C Compatible Interface datasheet (Rev. A)

Regards

 

Phil K

Sent from Mail for Windows 10

 

From: Laurentp
Sent: 27 May 2021 14:17
To: TasmotaUsers
Subject: Re: INA219 vs INA226

 

Thx,

this matrix confirms, that I have to build my own BIN, as INA226 is nowhere included.

This returns to previous question: - how to build arbitrary version using GITPOD?

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
May 27, 2021, 10:26:18 AM5/27/21
to TasmotaUsers
czwartek, 27 maja 2021 o 16:11:10 UTC+2 knowles...@gmail.com napisał(a):

I don’t think you need to recompile. If you look at the datasheets the calibration is different so you may just be able to scale the readings you get.


I am not afraid of compiling, web based GitPod looks simple to use, only need  "for version x.y.z, "flavor" X,  use ...". How to build arbitrary version. Once learned may simplify things.

Philip Knowles

unread,
May 27, 2021, 10:32:48 AM5/27/21
to Laurentp, TasmotaUsers

Not sure about GitPod but when I compiled my own I followed these instructions – I used PlatformIO

Compiling - Tasmota

 

In your case it would be to add (or uncomment if it’s already there)

#ifndef USE_INA226

#define USE_INA226

#endif

 

Regards

 

Phil K

Sent from Mail for Windows 10

 

From: Laurentp
Sent: 27 May 2021 14:17
To: TasmotaUsers
Subject: Re: INA219 vs INA226

 

Thx,

this matrix confirms, that I have to build my own BIN, as INA226 is nowhere included.

This returns to previous question: - how to build arbitrary version using GITPOD?

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
May 27, 2021, 12:35:39 PM5/27/21
to TasmotaUsers
Don't have Win$ machine nor want one ;p.
GitPod looks attractive to me, no install, just use... browser based,
Anyone help?

Philip Knowles

unread,
May 27, 2021, 1:05:45 PM5/27/21
to Laurentp, TasmotaUsers

PlatformIO doesn’t need Windows. I think the process is the same in GitPod just never used it

 

Have you read the GitPod page?

Gitpod - Tasmota

Regards

 

PhilK

 

Sent from Mail for Windows 10

 

From: Laurentp
Sent: 27 May 2021 17:35
To: TasmotaUsers
Subject: Re: INA219 vs INA226

 

Don't have Win$ machine nor want one ;p.
GitPod looks attractive to me, no install, just use.. browser based,
Anyone help?

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
May 27, 2021, 3:04:40 PM5/27/21
to TasmotaUsers

Have you read the GitPod page?

Yes I did, I (think) need only URL to use instead of "https://github.com/arendst/Tasmota/tree/master"  for release of my choice.
I want to ask somebody who did it already not guess myself.

And I know about #define / #undef :).

Laurentp

unread,
May 27, 2021, 3:24:09 PM5/27/21
to TasmotaUsers
Is it so simple like "https://github.com/arendst/Tasmota/tree/v8.5.1" ? For 8.5.1.

Philip Knowles

unread,
May 27, 2021, 4:30:11 PM5/27/21
to Laurentp, TasmotaUsers

Yes that should be correct for 8.5.1

 

Sent from Mail for Windows 10

 

From: Laurentp
Sent: 27 May 2021 20:24
To: TasmotaUsers
Subject: Re: INA219 vs INA226

 

Is it so simple like "https://github.com/arendst/Tasmota/tree/v8.5.1" ? For 8.5.1.

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
Jun 10, 2021, 1:42:50 AM6/10/21
to TasmotaUsers
Ooops, not so simple:
started GitPod with this URL, but I am getting error:


```

Tool Manager: Installing toolchain-xtensa @ ~2.40802.191122
Tool Manager: Warning! More than one package has been found by toolchain-xtensa @ ~2.40802.191122 requirements:
 - platformio/toolchain-xtensa @ 2.100200.0
 - mcspr/toolchain-xtensa @ 5.100200.201223
 - tasmota/toolchain-xtensa @ 5.100200.210303
Tool Manager: Please specify detailed REQUIREMENTS using package owner and version (showed above) to avoid name conflicts
Downloading  [####################################]  100%         
Unpacking  [####################################]  100%         
Tool Manager: toolchain-xtensa @ 2.40802.200502 has been installed!
Tool Manager: Installing jason2866/framework-arduinoespressif8266 @ *
Error: Could not find the package with 'jason2866/framework-arduinoespressif8266 @ *' requirements for your system 'linux_x86_64'

```


"master" (whole URL from Wiki) compiles OK.

How to track / correct this error?

Laurentp

unread,
Jun 14, 2021, 2:01:40 AM6/14/21
to TasmotaUsers
Even with "master" branch have some problem:
- have put in "user_config_override.h" following

#ifdef USE_INA219
#undef USE_INA219
#endif

#ifndef USE_INA226
#define USE_INA226
#endif

can issue (with success): platformio -e tasmota-sensors,
BUT generated firmware has still INA219 NOT INA226 support.

What am I still missing?

sfromis

unread,
Jun 14, 2021, 4:52:01 AM6/14/21
to TasmotaUsers
You cannot add stuff to tasmota-sensors, only to the base "tasmota".

Laurentp

unread,
Jun 14, 2021, 8:56:33 AM6/14/21
to TasmotaUsers
Ok, so please tell me, step by step if You could, what have I to obtain firmwawe "like Tasmota-sensors only with INA226 instead of INA219 support"? Maybe adding Polish language instead of English. (but this is not "a must").

Philip Knowles

unread,
Jun 14, 2021, 9:31:04 AM6/14/21
to Laurentp, TasmotaUsers

The compiling your own firmware page sort of explains it

Compiling - Tasmota

You will need to copy user_config_override_sample.h to createuser_cofig_override.h

Look for

;#ifndef USE_INA226

;#define USE_INA226

;#endif

and remove the ; in front of each line

then, to remove INA219 support

add

#ifdef USE_INA219

#undef USE_INA219

#endif

 

Regards

 

Phil K

 

 

Sent from Mail for Windows 10

 

From: Laurentp
Sent: 14 June 2021 13:56
To: TasmotaUsers
Subject: Re: INA219 vs INA226

 

Ok, so please tell me, step by step if You could, what have I to obtain firmwawe "like Tasmota-sensors only with INA226 instead of INA219 support"? Maybe adding Polish language instead of English. (but this is not "a must").

poniedziałek, 14 czerwca 2021 o 10:52:01 UTC+2 sfromis napisał(a):

You cannot add stuff to tasmota-sensors, only to the base "tasmota".

 

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Laurentp

unread,
Jun 15, 2021, 2:36:19 AM6/15/21
to TasmotaUsers
That's exactly what I did.

But in my case, "user_config_override_sample.h" did NOT contained commented out config options for INA_226, it only contained sections for WiFi / MQTT parameters.
And it did NOT work despite "Building in release mode
*** use provided user_config_override.h as planned ***
*** use provided platformio_override.ini as planned ***"
messages in build log.

I finally manage this (I hope), by modifying "my_user_config.h" (I know, should do this) and compiling. Also uncommenting pl_PL language worked.
Now it is correctly shown in GUI as INA226-1, voltage displays as expected (connected to "3V3" - power displays 3.293V). Not tested (yet) current measure (I use 100A / 75mV shunt in final location).

Laurentp

unread,
Jun 15, 2021, 2:37:23 AM6/15/21
to TasmotaUsers
(I know, should do this) -> should NOT.

sfromis

unread,
Jun 15, 2021, 4:05:09 AM6/15/21
to TasmotaUsers
What you should have done was to modify user_config_override.h "inspired" by what you see in my_user_config.h, leaving the latter unchanged.

Philip Knowles

unread,
Jun 15, 2021, 4:11:16 AM6/15/21
to Laurentp, TasmotaUsers

No if it doesn’t contain the part you need to add it. Because of possible I2C driver conflicts not all of the options are available all the time.

I2C Devices - Tasmota gives you the driver code to use in user_config_override.h

 

Regards

 

Phil K

 

Sent from Mail for Windows 10

 

From: Laurentp
Sent: 15 June 2021 07:36
To: TasmotaUsers
Subject: Re: INA219 vs INA226

 

That's exactly what I did.

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages