 # Weight Reading Code for 2 Scales

Hi All,
I am having a small problem with the following code that I am using to read two sets of scales to A0 and A1 input of a Due board and convert to Kg loads at the USB port.

The load in A0 seems to affect A1 i.e the output goes up on A1 if you only have an input on A0 and visa versa. It also appears when I have both scales the converted load is affected by each other scale. A1 appears to be worse that A0 and I have to re-calibrate with both scales connected and showing approx the same weight… I think it may be something to do with the average values calculated.

Is there any other code that I could add to keep the individual inputs / outputs totally independent. of each other.

Thank you for any assistance.

Nevjc

// Arduino as load cell amplifier
// by Christian Liljedahl
// christian.liljedahl.dk

// Load cells are linear. So once you have established two data pairs, you can interpolate the rest.

// You need two loads of well know weight. In this example A = 10 kg. B = 30 kg
// read the analog value showing (this is analogvalA)
// read the analog value B

// Enter you own analog values here
float load0A = 4.0; // kg

int analogval1A = 100;

float load0B = 69.1; // kg

int analogval1B = 2290;

float analogValueAverage0 = 0;
float analogValueAverage1 = 0;
// How often do we do readings?

int timeBetweenReadings = 200; // We want a reading every 200 ms;

void setup() {
Serial.begin(9600);
}

void loop() {

// running average - We smooth the readings a little bit
analogValueAverage0 = 0.99analogValueAverage0 + 0.01analogValue0;
analogValueAverage1 = 0.99analogValueAverage1 + 0.01analogValue1;

// Is it time to print?

}
}
Serial.print(" ");
}

// using a custom map-function, because the standard arduino map function only uses int

}

float mapfloat0(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float mapfloat1(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

You want to avoid performing analogRead() on multiple pins in quick succession, because, yes, the readings from one pin will be noticeable on other pins. The simplest solution is to perform two analogReads() on a given pin and discard the first result.

Thank you Karma for your suggestion. I will give it a try. Kind Regards Nevjc