Hi, I'm trying to measure current to/from a 12V battery using a low-side shunt resistor (75mV drop at 200A). The battery is charged by a solar panel using a Triron MPPT charge controller (represented by solar cells in the curcuit diagram). The Arduino is powered by the battery/charge controller using a 12V DC/DC converter. Here is the diagram:
(Seeing the circuit now, I think the ground might have been on the wrong side of the shunt, so I moved it to 4. Didn't make a difference though.)
The problem I have is this: the battery current I measure is completely off when I switch on the load (the inverter in this case). But I have no idea what to try next to fix this. Here is a screenshot of the values I got:
(I'm not allowed to add this here, will post later)
Between 8 o'clock and about 10, the battery was being charged and you can see that the battery current on the top left panel and on the right panel (red/orange, red is min, orange is max over 10 seconds) agrees with the solar current on the right (which is the lowest graph starting at 4A) as well as with the Triron measured battery current, which is the cyan graph on the right).
However, at about 10:25 I switched the inverter on, drawing about 100W. The solar current jumped up to 4A (at 40V) and the battery current in reality stayed at about 2A. The Arduino, however, gives me values that are all over the place. The max is at 8A, the min is all the way to -80A.
And last, here is my Arduino program:
#include <Wire.h>
#include <ADS1115_WE.h>
#define I2C_ADDRESS 0x48
ADS1115_WE ads(I2C_ADDRESS);
//float ampsPerMv = 2.66666666; // 200A at 75mV
// the setup function runs once when you press reset or power the board
void setup() {
Wire.begin();
Serial.begin(115200);
while (!Serial) {}
if (!ads.init()) {
Serial.println("ADS1115 not connected!");
}
ads.setVoltageRange_mV(ADS1115_RANGE_0256);
ads.setCompareChannels(ADS1115_COMP_0_1);
ads.setConvRate(ADS1115_128_SPS);
ads.setMeasureMode(ADS1115_CONTINUOUS);
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
// the loop function runs over and over again forever
void loop() {
// send data only when we receive data
while (Serial.available() == 0) {}
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
while (Serial.available() > 0)
Serial.read(); // read the incoming byte, discard, we don't care
int16_t voltage = 0;
// take average of 4 samples
for (int i = 0; i < 4; i++) {
//voltage = ads.getResult_mV();
voltage += ads.getRawResult();
}
Serial.print('#');
Serial.print(voltage/4);
Serial.print('#');
//Serial.println(voltage * ampsPerMv);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
As you can see, I used to calculate the current in Arduino. Now I just send the average raw value of 4 measurements and to the math on the computer. Didn't help. I padded the value with # to detect when I get garbage, happens every 10-20 seconds, and then I just request a new reading.
I know that currently I only use 75mV of the 256mV range and I want to add an op amp. But I think before I do that, I have to get stable readings.
Any idea what I did wrong?