Go Down

Topic: Accelerometer data (Read 707 times) previous topic - next topic

BN.barak

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:
Code: [Select]
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:
Code: [Select]
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 :
Code: [Select]
val =analogRead(0) * 1000000 ;
the output is:
Code: [Select]
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.

AWOL

You're reading the analogue input in two different places - you can't expect it to be the same.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BN.barak

Cant you see the diffrents? its not like 430 and 431.
Any way i changed it:
Code: [Select]
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:
Code: [Select]
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

AWOL

Code: [Select]
val =(x * 1000000[glow]L[/glow]) + (y * 1000[glow]L[/glow]) + z;
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BN.barak


AWOL

#5
Oct 03, 2010, 10:14 pm Last Edit: Oct 03, 2010, 10:16 pm by AWOL Reason: 1
[glow]L[/glow]ong

http://arduino.cc/en/Reference/IntegerConstants
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BN.barak

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.


Go Up