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?
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.
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:
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.
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)