Pages: [1]   Go Down
Author Topic: Accelerometer data  (Read 684 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're reading the analogue input in two different places - you can't expect it to be the same.
Logged

"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.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
val =(x * 1000000[glow]L[/glow]) + (y * 1000[glow]L[/glow]) + z;
Logged

"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.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Whats the L means?
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[glow]L[/glow]ong

http://arduino.cc/en/Reference/IntegerConstants
« Last Edit: October 03, 2010, 03:16:16 pm by AWOL » Logged

"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.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged


Pages: [1]   Go Up
Jump to: