Hello,
I try to read data from 4 ADXL335 accelerometers placed on various points of a robotics arm. The acquisition of a single accelerometer takes place very well, even by connecting the others. The problem is when I want to read data from a second accelerometer at the same time, the data become then totally inconsistent....
Has Anybody already realized this kind of project ?
Is there something particular to add/change in this code?
Thanks a lot.
/*
ADXL335
*/
// these constants describe the pins.
const int xpin1 = A0; // x-axis of the accelerometer#1
const int ypin1 = A1; // y-axis
const int zpin1 = A2; // z-axis
const int xpin2 = A3; // x-axis of the accelerometer #2
const int ypin2 = A4; // y-axis
const int zpin2 = A5; // z-axis
//const int xpin3 = A6; // x-axis of the accelerometer #3
//const int ypin3 = A7; // y-axis
//const int zpin3 = A8; // z-axis
void setup()
{
Serial.begin(115200);
}
void loop()
{
unsigned long tmp1;
unsigned char h1, l1, h2, l2, h3, l3;
tmp1=analogRead(xpin1);
h1=(unsigned char)(tmp1>>8);
l1=(unsigned char)(tmp1 & ((1<<8)-1));
Serial.print(l1,BYTE);
Serial.print(h1,BYTE);
unsigned long tmp2;
tmp2=analogRead(ypin1);
h2=(unsigned char)(tmp2>>8);
l2=(unsigned char)(tmp2 & ((1<<8)-1));
Serial.print(l2,BYTE);
Serial.print(h2,BYTE);
unsigned long tmp3;
tmp3=analogRead(zpin1);
h3=(unsigned char)(tmp3>>8);
l3=(unsigned char)(tmp3 & ((1<<8)-1));
Serial.print(l3,BYTE);
Serial.print(h3,BYTE);
unsigned long tmp4;
unsigned char h4, l4, h5, l5, h6, l6;
tmp4=analogRead(xpin2);
h4=(unsigned char)(tmp4>>8);
l4=(unsigned char)(tmp4 & ((1<<8)-1));
Serial.print(l4,BYTE);
Serial.print(h4,BYTE);
delay(10);
unsigned long tmp5;
tmp5=analogRead(ypin2);
h5=(unsigned char)(tmp5>>8);
l5=(unsigned char)(tmp5 & ((1<<8)-1));
Serial.print(l5,BYTE);
Serial.print(h5,BYTE);
delay(10);
unsigned long tmp6;
tmp6=analogRead(zpin2);
h6=(unsigned char)(tmp6>>8);
l6=(unsigned char)(tmp6 & ((1<<8)-1));
Serial.print(l6,BYTE);
Serial.print(h6,BYTE);
/*
unsigned long tmp3;
unsigned char h3, l3;
tmp3=analogRead(xpin3);
h3=(unsigned char)(tmp3>>8);
l3=(unsigned char)(tmp3 & ((1<<8)-1));
Serial.print(l3,BYTE);
Serial.print(h3,BYTE);
tmp3=analogRead(ypin3);
h3=(unsigned char)(tmp3>>8);
l3=(unsigned char)(tmp3 & ((1<<8)-1));
Serial.print(l3,BYTE);
Serial.print(h3,BYTE);
tmp3=analogRead(zpin3);
h3=(unsigned char)(tmp3>>8);
l3=(unsigned char)(tmp3 & ((1<<8)-1));
Serial.print(l3,BYTE);
Serial.print(h3,BYTE);
*/
Serial.println();
// delay(1);
}