article

ks4z avatar image
ks4z posted

DIY INA226 based Smart Shunt released

I just released the first version of an INA226 based smart shunt. It's a cheap DIY altrernative to a Victron SmartShunt and can be built by anybody who can flash an ESP MCU and solder some components to a perfboard. You can find the code, some firmware files and a documentation on how to build the hardware on GitHub https://github.com/kscholty/SmartShuntINA226.

The INA226 is a shunt amplifier with an SPI interface. It can measure the small voltage drops that are produced by shunt resistors. My contribution is mainly the software that interfaces with the amplifier and implements an interface to the victrron world (or via modbus for other applications) and a hint which components to use to build the required hardware.

The current version of the software supports a PZEM-017 style modbus interface or alternatively the Victron Ve.Direct protocol. The Hex variant of that protocol is only implemented as far as it's required for connecting the shunt to a Victron GX system. It's working fine on my VenusOs RapberryPi and the Multiplus II GX I use in my production system.
It also offers a web based interface for configuration and human interaction.

I also started working on a VenusOs service that can handle this Shunt and also PZEM-017 sensors, but it's not finished yet. Let me know if you would find that useful, then I will polish it up and post it on GitHub as well.

I hope you find it useful and would like to hear your feedback.


ks4z

BMV Battery MonitorSmartShunt
8 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

von-baron avatar image von-baron commented ·

You might like to put a link to your github link above, presently it goes nowhere.

What is a 'PZEM-017 style modbus', I have not heard of it ?

Modbus is Modbus, ASCII, RTU or TCP to handle the various transport media, and modbus has nothing to do with any interface, that is always separate.

You might also like to describe the specifications of your INA226 based shunt, what are its operating parameters ?

But good to see some development.

Von Baron - VK7KPA

0 Likes 0 ·
ks4z avatar image ks4z von-baron commented ·

Thanks for your comment.

1) I have no idea why the link is not working. In the editor and the preview it works fine. As soon as I save the test, the link either disappears completely or gets non-functional. I added the link as text. (Edit: It suddenly worked without my intervention)

2) I didn'twant to imply that I created a special type of modbus. It's a standard modbus RTU protocol. What I meant was that the registers are compatible with those of the PZEM-017 sensor. That's why I wrote "interface", not "protocol".

3) Technical details can be found on Github. Didn't want to reapeat all the stuff here. However, I added some details.

0 Likes 0 ·
Michelle Konzack avatar image Michelle Konzack von-baron commented ·

Search AliExcess for PZEM-017 which is a product of Peacefair...

0 Likes 0 ·
robsweet avatar image robsweet commented ·

Hi, ks4z. Thanks for the project!

I've got it running and mostly working on an ESP32 WROOM (Adafruit ESP32 Feather). I've got a 12v system so I didn't do the voltage divider and I adjusted the voltage calibration accordingly. My volts/amps are coming through properly and I thought everything was working but when I connected it to the Cerbo and started reporting usage data, I realized that it's *way* over-reporting my usage. This is a tiny system (200W of solar panels ~25W of total load) but my consumption today is showing as 168kW so far today. It seems like either there's another place that needs to be adjusted for being a 12v system or something it's to do with the time calculation/alerting. I've been digging in the code but my C++ is sketchy at best and I haven't figured it out. Can you suggest any troubleshooting steps?

Thanks!

Rob

0 Likes 0 ·
Michelle Konzack avatar image Michelle Konzack robsweet commented ·

How many readings do you per hour?


Mixed up Ah, Am and As?

0 Likes 0 ·
robsweet avatar image robsweet Michelle Konzack commented ·

I haven't dug into how the code does the calculations (and was trying not to get that deep into it if I could help it) so I'm not sure how many samples it's using. I'm assuming that the OP is using this code for his own setup so it's unlikely that it's some kind of mixup like you describe or his wouldn't be working either.

0 Likes 0 ·
Michelle Konzack avatar image Michelle Konzack robsweet commented ·
Oh, I use an 2-Channel A/D-Converter which support parallel sampling. Both internal ADCs sample exact the same time and I do this 36.000 times an hour or 10 times a second. The precision is entirely enough. (I use 12 shunts 100A/50mV and the NXP LPC11C24 for the CAN communication)
0 Likes 0 ·
ks4z avatar image ks4z robsweet commented ·

Sorry for not answering for so long.

Since you say voltage and current are reported correctly, I have no idea why the wattage should be wrong. The code internally does nowhere assume any specific voltage. It uses the measured values for the statistics.

Could you solve the problem in the mean time?

0 Likes 0 ·

Article

Contributors

ks4z contributed to this article WKirby contributed to this article