system
October 3, 2010, 7:24pm
1
Hello,
I am trying to send the computer the accelerometer data;
for example if:
x: 111 y:222 z:333
then i will send 111222333
this is my code:
long val;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val =analogRead(0) * 1000000 + analogRead(1) * 1000+ (analogRead(2));
Serial.print (val);
Serial.print(" x: ");
Serial.print(analogRead(0));
Serial.print(" y: ");
Serial.print(analogRead(1));
Serial.print(" z: ");
Serial.println(analogRead(2));
}
//
this is the output:
452031782 x: 452 y: 359 z: 463
454029783 x: 454 y: 360 z: 465
456027784 x: 450 y: 359 z: 463
I found something odd:
if I change the val line to :
val =analogRead(0) * 1000000 ;
the output is:
453000000 x: 453 y: 720 z: 460
453000000 x: 452 y: 720 z: 460
452000000 x: 452 y: 721 z: 461
453000000 x: 453 y: 720 z: 460
the analog values are changed!! and the final val in wrong.
Whats wrong? :-? :-?
Thank you.
system
October 3, 2010, 7:31pm
2
You're reading the analogue input in two different places - you can't expect it to be the same.
system
October 3, 2010, 7:46pm
3
Cant you see the diffrents? its not like 430 and 431.
Any way i changed it:
long val;
int x,y,z;
void setup()
{
Serial.begin(9600);
}
void loop()
{
x = analogRead(0);
y = analogRead(1);
z = analogRead(2);
val =x * 1000000 + y * 1000+ z;
Serial.print (val);
Serial.print(" x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.println(z);
}
//
and the output is:
446981567 x: 447 y: 702 z: 463
445981568 x: 446 y: 702 z: 464
446981567 x: 447 y: 702 z: 463
446980567 x: 447 y: 701 z: 463
// 446 980 567 x: 447 y: 701 z: 463
system
October 3, 2010, 8:00pm
4
val =(x * 1000000[glow]L[/glow]) + (y * 1000[glow]L[/glow]) + z;
system
October 3, 2010, 8:39pm
7
Thank you,
And i got one more question.
I think i have some problem with my accelerometer. When the accelerometer is stable the values are increasing from 490 to 500 to 510 etc.
Thank you.