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.

// Step 1: Upload this sketch to your arduino board

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

// Enter you own analog values here
float load0A = 4.0; // kg
int analogval0A = 900; // analog reading taken with load A on the load cell

float load1A = 4.0;
int analogval1A = 100;

float load0B = 69.1; // kg
int analogval0B = 3003; // analog reading taken with load B on the load cell

float load1B = 69.1;
int analogval1B = 2290;
// Upload the sketch again, and confirm, that the kilo-reading from the serial output now is correct, using your known loads

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() {
analogReadResolution(12);
int analogValue0 = analogRead(0);
int analogValue1 = analogRead(1);

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

// Is it time to print?
float load0 = analogToLoad(analogValueAverage0);
float load1 = analogToLoad(analogValueAverage1);

if (load0 < 0) { (load0=0);
}
if (load1 < 0) { (load1=0);
}
Serial.print(load0,1);
Serial.print(" ");
Serial.println(load1,1);
}

float analogToLoad(float analogval){

// using a custom map-function, because the standard arduino map function only uses int
float load0 = mapfloat0(analogval, analogval0A, analogval0B, load0A, load0B);
return load0;

float load1 = mapfloat1(analogval, analogval1A, analogval1B, load1A, load1B);
return load1;

}

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