Go Down

Topic: Accelerometer MMA7361. Where to start? (Read 3695 times) previous topic - next topic

holahoep

Jul 14, 2011, 05:35 pm Last Edit: Jul 14, 2011, 05:39 pm by holahoep Reason: 1
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? :)

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


robtillaart


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

Rob Tillaart

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

holahoep

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

holahoep

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: [Select]
#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);
}

AWOL

Code: [Select]
  pinMode(X_PIN, INPUT);
?

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

holahoep


Code: [Select]
  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.

AWOL

#6
Jul 23, 2011, 05:10 pm Last Edit: Jul 23, 2011, 05:15 pm by AWOL Reason: 1
So why are you setting serial Rx and Tx to be inputs?

What have you done with the sleep pin?
"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.

holahoep


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?

AWOL

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

holahoep


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!

wildbill

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

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

holahoep

#11
Jul 23, 2011, 06:44 pm Last Edit: Jul 23, 2011, 07:51 pm by holahoep Reason: 1

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

 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: [Select]
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: [Select]

#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




}

AWOL

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

Tilt it.
Let gravity do the work.
"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.

holahoep


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)

AWOL

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

Go Up