Loading...
Pages: [1]   Go Down
Author Topic: how to use a mma7361 accelerometer what is wrong?  (Read 923 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi every body! i bought a mma7361 accelerometer like this:
http://thmb.inkfrog.com/thumbn/geiliablestore/mma7361_conew1.jpg=450
I guess it could be use through i2c or analog in, and i want to use it via analog in!
I plugged like this:
A0 to X
A1 to Y
A2 to Z
3.3V to  3V3
GND to GND
 and i had this code:

#include <SoftwareSerial.h>

int axe_x=0;
int axe_y=0;
int axe_z=0;

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

void loop()
{
  axe_x=analogRead(A0);
  axe_y=analogRead(A1);
  axe_z=analogRead(A2);
  Serial.print(axe_x);
  Serial.print("\n");
  Serial.print(axe_y);
  Serial.print("\n");
  Serial.print(axe z);
 Serial.print("\n");
}

but in the terminal there is only some strange values, all the same for each axis, and wich don't move when shaking the accelerometer!
Any ideas what i m doing wrong?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 96
Posts: 6354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SL is the SLEEP signal.  Connect it to 3.3V or the accelerometer will stay in a low-power sleep mode.
Logged

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

thanks fo your help, now i have new questions smiley
how can i smooth a little bit the values i get? i guess there is already an RC filter on the pcb.
Thanks for help!!
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 87
Posts: 9387
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


try this ...
Code:
#include <SoftwareSerial.h>

long axe_x=0;
long axe_y=0;
long axe_z=0;

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

void loop()
{
  axe_x = (90* axe_x + 10 * analogRead(A0)) / 100;
  axe_y = (90* axe_y + 10 * analogRead(A1)) / 100;
  axe_z = (90* axe_z + 10 * analogRead(A2)) / 100;

  Serial.print(axe_x);
  Serial.print("\n");
  Serial.print(axe_y);
  Serial.print("\n");
  Serial.print(axe z);
 Serial.print("\n");
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 96
Posts: 6354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For a little more versatility:
Code:
const int STABILITY = 10;

long axe_x=0;
long axe_y=0;
long axe_z=0;

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

void loop()
{
  axe_x = ((STABILITY-1)* axe_x + analogRead(A0)) / STABILITY;
  axe_y = ((STABILITY-1)* axe_y + analogRead(A1)) / STABILITY;
  axe_z = ((STABILITY-1)* axe_z + analogRead(A2)) / STABILITY;

  Serial.println(axe_x);
  Serial.println(axe_y);
  Serial.println(axe z);
}
Logged

Pages: [1]   Go Up
Print
 
Jump to: