Pages: [1]   Go Down
Author Topic: how to use a mma7361 accelerometer what is wrong?  (Read 3179 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 33
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: 201
Posts: 8667
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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 33
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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13478
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 -
(Please do not PM for private consultancy)

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8667
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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe this can help future readers
https://code.google.com/p/mma7361-library/
Logged

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

Thanks for the link!
(There are several optimizations possible in this lib by the way e.g. using bytes for pin numbers reducing the footprint)
Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: