The CONTINUOUS MODE sketch works perfect with resistive loads, but the current reading jumps around when the load is an active circuit like my metal detector.
Can anyone sugest a way to smooth or average this current reading?
current_mA = ina219.getCurrent_mA();
I tried the usual For Loop routine, EG: "for (int i = 0; i < avgSamples; i++)", but could not get that to work!!
Thanks, Mac VE7DEP
PROBLEM SOLVED! I did finally get the Averaging code to work.
int avgSamples = 2000; // Added for averaging
void loop() {
ina219.startSingleMeasurement();
for (int i = 0; i < avgSamples; i++) {
current_mA = current_mA + ina219.getCurrent_mA();
}
current_mA = current_mA / avgSamples;
Thanks Everyone. Mac VE7DEP
You are correct gilshultz. The current is changing at the pulse rate of the detector's TX circuit even with a 4700uf buffer cap installed.
I did try delaying the readings, but even at 3 seconds if the display jumps up to an invalid reading, it stays displayed for the delay period which is irritating. It does display the correct reading most of the time.
Thanks for the information Paul.
I think your Exponential Moving Average Algorithm would solve my problem but with my limited coding experience I'm not sure how to add it to the sketch.