Accelerometer MMA7361. Where to start?

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? :slight_smile:

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

Slightly different but same sensor - Triple Axis Accelerometer Breakout - MMA7361 - SEN-09652 - SparkFun Electronics -
below is a link to the datasheet , start reading ...

i printed about 30 pages of Arduino stuff..so i guess i gonna read that :slight_smile:

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?

#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);
}
  pinMode(X_PIN, INPUT);

?

What's on the external reference pin?

AWOL:

  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.

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

What have you done with the sleep pin?

AWOL:
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?

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.

AWOL:

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!

Not sure what the story is on a mega, but on an uno, you would want this:

  x =analogRead(A0);
  y =analogRead(A1);
  z =analogRead(A2);

wildbill:
Not sure what the story is on a mega, but on an uno, you would want this:

  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

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.

#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 

 
 

}

i only want to know now what's the max value of the Y axle

Tilt it.
Let gravity do the work.

AWOL:

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)

I'm pretty sure there are ways of smoothing or filtering explained at the Playground.