Go Down

Topic: how to use a mma7361 accelerometer what is wrong? (Read 3 times) previous topic - next topic

victorjung

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?

johnwasser

SL is the SLEEP signal.  Connect it to 3.3V or the accelerometer will stay in a low-power sleep mode.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

victorjung

thanks fo your help, now i have new questions :)
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!!

robtillaart


try this ...
Code: [Select]

#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");
}
Rob Tillaart

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

johnwasser

For a little more versatility:
Code: [Select]

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);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


robtillaart

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)
Rob Tillaart

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

Go Up