Trouble monitoring battery charger circuit with INA219

Thread Starter

zirconx

Joined Mar 10, 2010
130
Hi, I'm trying to monitor the health of my sump pump battery. This is a backup pump system, the main pump is a 120v unit.

It's a large deep cycle 12v lead acid battery. I have a harbor freight float charger on it. I've installed the INA219 breakout board inline with the positive line from the charger to the battery. I am using a raspberry pi to read data from the INA219, with a node script using the ina219 module.

I think am I reading the charging current correctly, but my voltage readings are not right. See my chart below, I'm only reading around 1v or less when I expect to read 12-13v or so. I think this might be because the grounds of the battery charging circuit and the ground of the raspberry pi circuit are not tied together? When I put a DVM between the two grounds I read around 12v. I have a small LED voltmeter always connected to the battery and at the time it was showing 12.9, so this might be where I'm getting my approximately 1v reading from?

Is it safe to tie these grounds together? The raspberry pi is powered from a phone charger plugged into a 120v outlet.

BTW the spike in charging current (green line) towards the right side of the chart happened after I ran the pump for a moment.
 

Attachments

LesJones

Joined Jan 8, 2017
3,249
You do not have any connection between the INA219 ground pin and the battery negative so it does not have a reference to measure the + 12V. You will need to be sure that there is no voltage between the battery charger negative output and the negative of the power supply for the Raspberry Pi. The power supply you are using will probably have a floating output but check that there is no connection between it's output and mains earth (If it has an earth connection) If it is from an unknown source such as ebay then also check that there is no connection (I.E Resistance reading greater than 20 Meg ohms.) between it's output and either mains input.

Les
 

Thread Starter

zirconx

Joined Mar 10, 2010
130
You do not have any connection between the INA219 ground pin and the battery negative so it does not have a reference to measure the + 12V. You will need to be sure that there is no voltage between the battery charger negative output and the negative of the power supply for the Raspberry Pi.
Ok, and then what? I did test this, as I mentioned above, and found a difference of around 12v. But I think something may have gone wrong, my board stopped recording around this time, so I think I may have accidentally unplugged the ground wire on the INA219, causing my meter to see a 12v difference between that ground wire and the battery ground. I will try again. But I'm still a little clear about what you are suggesting - I need to see if there is a voltage difference, and then what? If there is no difference then it's ok to tie the grounds together? Or if there is no difference then there is no reason to tie them together, since they are already at the same potential? Or if there is a difference then that is evidence that I do need to tie them together?

The power supply you are using will probably have a floating output but check that there is no connection between it's output and mains earth (If it has an earth connection) If it is from an unknown source such as ebay then also check that there is no connection (I.E Resistance reading greater than 20 Meg ohms.) between it's output and either mains input.
Ok I'll do that, and then what? If it's a floating output then it's safe to tie them together? Or if it's not a floating output then it's safe to tie them together? Or do I need to use a different kind of power supply?

Eventually I plan to power the raspberry pi from the battery (via 12v-5v converter) so that everything continues to function even when the power goes out. When that happens, then for sure both systems will have the same ground potential. If this is the best/easiest fix, I can pursue that now. I haven't yet because I'm not sure that my 12v battery charger will keep up with the load, I may need to upgrade to a larger charger.

Thanks for your help.
 

LesJones

Joined Jan 8, 2017
3,249
If either the power supply or the charger are floating it is safe to connect the negative rails (Logic ground.) together. Also if both negative rails are connected to the mains earth pin on the plug it is safe to connect them together. This MAY cause some noise pickup. Powering the Raspberry Pi from the battery that is being charged via a voltage regulator is probably the best way. I do it this way with my charge monitoring system but I interface the INA219 to a PIC12F1840. The PIC converts the readings to an ASCII text string which is sent to a pair of HC-12 RF serial links and the results can be displayed on a Raspberry Pi, or a PC running a terminal emulator program. I have it set so that a reading is sent out when two characters are typed into the terminal emulator. I use the # character followed by a letter. This way I can select a reading from a number of remote sensors. Some are temperature monitors. As the PIC and HC-12 only take a combined current of about 20 mA the load on the battery is not a problem. I think from memory that the Raspberry Pi takes about 500 mA. If only a short range was required Bluetooth communication could be used instead of HC-12 modules.

Les.
 

Thread Starter

zirconx

Joined Mar 10, 2010
130
If either the power supply or the charger are floating it is safe to connect the negative rails (Logic ground.) together. Also if both negative rails are connected to the mains earth pin on the plug it is safe to connect them together. This MAY cause some noise pickup. ...
You are right, I think I am getting some noise. The program crashed during my first pump, something about failing to read from the I2C device. Is there something I can do to reduce the noise? A capacitor somewhere.?

Also my ic2 wire harness is about 8 feet long, when I get that cut to size (will probably end up being 3-4 feet), that might help with the noise? Depends on where the noise is coming from.
 

Thread Starter

zirconx

Joined Mar 10, 2010
130
I am able to catch the exceptions in software, so the program continues to run instead of crashing. But sometimes I get so many errors I am missing data on the chart. The pump is NOT pumping right now, so the noise isn't coming from that.

Edit - I just thought of something. I changed the polling interval (from 1 second to 200ms) at the same time I connected the grounds. So maybe it's not noise, maybe it's a problem with polling that often. I'm going to reduce it to 1s again and see if I get any errors overnight.
 

Attachments

Last edited:

LesJones

Joined Jan 8, 2017
3,249
I2C is only intended for communication between devices on the same PCB. You need to have the INA219 within a few inches of the Raspberry Pi. Your problem is more likely to be caused by your very long connection between the INA219 and the Raspberry Pi. I have the INA219 on the same board as the PIC12F1840. Here is a picture of my remote voltage and current monitor.
IMG_1667 (Medium).JPG
The module at the bottom of the board is the HC-12. I have added extra shunt resistors to the INA219 to measure currents up to about 5 amps.

Les.
 

bobcroft

Joined Aug 22, 2011
11
Hi, if you really must have I2C over long cables / wires then you could consider using a P82B715 I2C extender IC. I have successfully used this device over a 10 metre CAT 5e network cable to link INA219 sensors to an ESP32 device.
 

Thread Starter

zirconx

Joined Mar 10, 2010
130
I2C is only intended for communication between devices on the same PCB. You need to have the INA219 within a few inches of the Raspberry Pi. Your problem is more likely to be caused by your very long connection between the INA219 and the Raspberry Pi. ....
Hi, if you really must have I2C over long cables / wires then you could consider using a P82B715 I2C extender IC. I have successfully used this device over a 10 metre CAT 5e network cable to link INA219 sensors to an ESP32 device.
I have read this (that i2c is only to be used locally on the circuit board), but have also read that i2c spec says the wiring should have less than 400pF of capacitance for fast mode and 550pF for I2C fast mode plus. Cat5 has 52pf per meter, cat6 has 46pf per meter. Should be ok to run 5 feet then?

I *think* am using cat3 right now (just grabbed the cheapest, least-likely-to-need-later stuff I had laying around) which has a rating of 65pf per meter. And I think I might have almost 2 meters of cable right now, like I said I was planning on shortening it for the final install.

I need to either run i2c cabling from the raspberry pi down to the battery, or run the charging cables up (and back down) to the raspberry pi. Which will affect the battery charging circuit, unless I use some heavier wiring like 14g. I'm leaning toward sending the charging current up to the pi, and keeping the INA219 close to the pi.

Here's the state of my circuit so far. Not shown is the INA219 board, that's what I need to hook up next. I'll be monitoring 12v battery voltage, 12v battery charging current, sump pump1 current (120vac), sump pump2 current (12vdc), float switch status, raspberry pi voltage (5v) and water depth.
 

Attachments

Last edited:
Top