Pages: [1]   Go Down
Author Topic: Accelerometer MMA7361. Where to start?  (Read 3036 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, i'v got my arduino now for 3 days. and i like it:). Did the basics, blinking led. fading led, potmeter+servo. now i just received my MMA7361 accelerometer. This one:
now i want to read out the data of it. i connected the 3V3 to the 3V3 on my Arduino 2560 board. and the X Y Z to analog 0 , 1, 2. i also see other pins on the board. like
SL - OG(?). and GS and ST. first i connected only the X, and loaded a code to the arduino wich i found here on the forum. then i got 3 random data. can someone help me this noobie? smiley

GS = G force select?
ST = Self test?
SL = Sleep pin?

« Last Edit: July 14, 2011, 10:39:11 am by holahoep » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13479
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Slightly different but same sensor - http://www.sparkfun.com/products/9652 -
below is a link to the datasheet , start reading ...

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i printed about 30 pages of Arduino stuff..so i guess i gonna read that smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a picture how the accelero meter is connected:



And this is the code ( copy past from a topic here on forum) The only output i get is 1023 on X - Y - X .. can someone push me in the right direction?

Code:
#define X_PIN 0 // X Axis input (analog pin #)
#define Y_PIN 1 // Y Axis input (analog pin #)
#define Z_PIN 2 // Z Axis input (analog pin #)

void setup(){
  Serial.begin(9600);

  analogReference(EXTERNAL); // set if Aref pin wired to 3.3V source

  pinMode(X_PIN, INPUT);
  pinMode(Y_PIN, INPUT);
  pinMode(Z_PIN, INPUT);

  Serial.println("Test started!");
}


void loop(){
  int x,y,z;
  x =analogRead(X_PIN);
  y =analogRead(Y_PIN);
  z =analogRead(Z_PIN);
  Serial.print(millis()) ;
  Serial.print(", x=");
  Serial.print(x) ;
  Serial.print(", y=");
  Serial.print(y) ;
  Serial.print(", z=");
  Serial.println(z) ;
  delay(5);
}
Logged

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

Code:
  pinMode(X_PIN, INPUT);
?

What's on the external reference pin?
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.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  pinMode(X_PIN, INPUT);
?

What's on the external reference pin?

I have pin X on Analog0, Y  on 1, and Z on 2.
3V3 to 3V3 on arduino board.
And Ground to ground. nothing else connected.
Logged

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

So why are you setting serial Rx and Tx to be inputs?

What have you done with the sleep pin?
« Last Edit: July 23, 2011, 10:15:05 am 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.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So why are you setting serial Rx and Tx to be inputs?

i only copy'd the code from a topic here on the forum. so this code is not correct?
Logged

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

Quote
so this code is not correct?
Yes. Analogue inputs (unless you really want them to be digital inputs) don't need to have their pinMode set,and anyway, you're using 0, 1 and 2, which are the pin numbers of digital pins.
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.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so this code is not correct?
Yes. Analogue inputs (unless you really want them to be digital inputs) don't need to have their pinMode set,and anyway, you're using 0, 1 and 2, which are the pin numbers of digital pins.

Shiit.. i need to start with the minimal code for this accelerometer sensor.  But i can't find it, and asking here feels so stupid!
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure what the story is on a mega, but on an uno, you would want this:
Code:
  x =analogRead(A0);
  y =analogRead(A1);
  z =analogRead(A2);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure what the story is on a mega, but on an uno, you would want this:
Code:
 x =analogRead(A0);
  y =analogRead(A1);
  z =analogRead(A2);

Oke i did some different now. and i get some steady values.  are these value's good?

Value's i get from Y axle:

353
354
353
353
353
352
352
355
353


Code:
int xAs =A8;


void setup() {

Serial.begin(9600);
pinMode(3, OUTPUT);   // SL PIN CONNECTED ON DIGITAL PIN 3
}

void loop() {
 digitalWrite(3, HIGH);  // SET THE SL PIN HIGH (do i need this?)
 Serial.println(analogRead(xAs)); //SHOW THE NUMBERS I GET FROM ANALOG PIN 8 (Y AXLE)
 delay(50);

}

EDIT,

Got this now, and it works! i only want to know now what's the max value of the Y axle. because i mapped now just some value's.

Code:
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo
int yAs =A8;
int waarde;


void setup() {

pinMode(3, OUTPUT);   // SL PIN CONNECTED ON DIGITAL PIN 3
digitalWrite(3, HIGH);  // SET THE SL PIN HIGH (do i need this?)
myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
 waarde = analogRead(yAs);
 waarde = map(waarde, 0, 600, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
 myservo.write(waarde);                  // sets the servo position according to the scaled value
 delay(15);                           // waits for the servo to get there

 
 

}
« Last Edit: July 23, 2011, 12:51:04 pm by holahoep » Logged

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

Quote
i only want to know now what's the max value of the Y axle
Tilt it.
Let gravity do the work.
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.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i only want to know now what's the max value of the Y axle
Tilt it.
Let gravity do the work.

Now i need to find a way to 'filter' a little bit. Because when the accelerometer is laying on my desk, the output numbers are slightly different. like the numbers in my previous  post.

353
354
353
353
353
352
352
355
353

So my servo is constantly changing position (you can't see it but you can hear the servo)
Logged

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

I'm pretty sure there are ways of smoothing or filtering explained at the Playground.
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.

Pages: [1]   Go Up
Jump to: