Accelerometer help! Code writing

Hey, My assignment is due next week and i am using the Triple Axis Accelerometer MMA7361 from Sparkfun. (Triple Axis Accelerometer Breakout - MMA7361 - SEN-09652 - SparkFun Electronics). I have used this forum and received many helpful tips but for some reason. I just can't write the code, most of them return with no results and some of them won't even compile and some came out with funny numbers. If you guys don't mind of writing me a sample code so I can get started. Please help me as my assignment is due next week! Thank you so much! Btw, I'm using the 3.3 v rail and sleep and g-select button are connected to the 3.3 rail as well cause my logic pin in the UNO is 5v. If im doing it wrong, please tell me.

Post the code you're having problems with.

alright.. This is the one where I've got proper readings but not in Gs. I've tried to convert it by setting the offset, setting the sensitivity, and the mV/g count. Sorry if its very simple.

int x_axis = 0;
int y_axis = 1;
int z_axis = 2;
int x_result;
int y_result;
int z_result;
int sleep = 2;
int g_select = 4;

void setup ()
{
  Serial.begin(9600);
  digitalWrite(sleep, HIGH);
  digitalWrite(g_select, HIGH);
}

void loop ()

{
  int x_result = analogRead(x_axis);
  int y_result = analogRead(y_axis);
  int z_result = analogRead(z_axis);
  Serial.print(x_result);
  Serial.print(" ");
  Serial.print(y_result);
  Serial.print(" ");
  Serial.print(z_result);
  Serial.println();
  delay(150);
}

It isn't really simple enough - you should concentrate on just getting the values for one axis working - after that, the rest is easy.
OK, so assuming the code above produces results, what do those results look like with the device horizontal on a stable, level surface?

Ohk, Next time I should start small! The numbers are pretty much the same when it is left untouched. Here is a snippet.

337 343 378
336 343 376
336 343 377
337 343 377
336 343 378
337 343 378
336 343 377
336 343 377
336 343 377
336 343 377
336 343 377
336 342 377

So, assuming 5V Aref, about 1.64V 1.67V and 1.84V.
Looking OK, assuming 0g, 0g and +1g.
What's the problem?

I've read so many threads and a lot of them said to use AREF pin. I don't know what the AREF pin is. The accelerometer can only accept 3.3 volts, so I don't know why you are telling me it's 5v? and that I'm in dire need of writing a code whereby it can convert the '300' number values to proper G force

The accelerometer can only accept 3.3 volts, so I don't know why you are telling me it's 5v?

The acclerometer may be a 3.3V device, but the Arduino's voltage reference is, by default (and you haven't changed the default in the sketch you posted) 5V.

Whatever the accelerometer outputs, it is measured on a scale of 0 to 5V.
The voltage measurement is made on the Arduino, not the accelerometer.

If you want to change that, then you need to select the external voltage reference and connect 3.3V to it.

Ohh! I think i got it. So now I have to add a jumper from the 3.3v to the AREF pin. but must I type anything in the environment?

but must I type anything in the environment?

Did you read the link I posted?

I'd probably select the 1.5g range on the accelerometer - it will give you better sensitivity.

Navin2012:
I've read so many threads and a lot of them said to use AREF pin. I don't know what the AREF pin is. The accelerometer can only accept 3.3 volts, so I don't know why you are telling me it's 5v? and that I'm in dire need of writing a code whereby it can convert the '300' number values to proper G force

I highly recommend working through the examples that come with the version 22 compiler. Then you can also read the Reference Section on the main site which has excellent examples. The playground and libraries section are helpful too.

All of your questions were already answered by the examples -- which apparently you did not review.

I hope you agree that the people that helped you were knowledgeable, thoughtful and patient.

Welcome to the forum and best wishes.

Hey, sry for the late reply. I had soccer and assignments. firstly, AWOL, I would like to say sorry if I offended you. I didn't mean to, I was confused about the AREF and the VCC of the accelerometer and yes, I did read the link you gave me but I am kinda new into Arduino and sorry if I didn't tell you guys in the first post. secondly! I finally found a library for the MMA7361, I tried it on the IDE v22 but it had errors compiling, so i'm trying to download v21 and give it a try. Here's the link (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291717903/all).

No offence taken.

The library looks interesting - I haven't tried compiling it, but it looks pretty complete and simple to use, though I see it uses I/O pins for range and sleep, so you may have to spoof these.

Well, I added it to my library folder but it had errors compiling so I emailed the writer and he is yet to reply. I also found a blog using a similar accelerometer and i'll to use his formula to write the code. (DigitalStew : Maker Projects: Trashcan Accelerometer)

I haven't got 0022, so what are the compilation errors you're getting?

When I try to use one of his example code. It had errors when compiling.

#include <AcceleroMMA7361.h>

AcceleroMMA7361 accelero;
int x;
int y;
int z;

void setup()
{
  Serial.begin(9600);
  accelero.begin(13, 12, 11, A0, A1, A2);
  accelero.callibrate();
  accelero.setARefVoltage(3.3); //sets the AREF voltage to 3.3V
}

void loop()
{
  x = accelero.getXAccel();
  y = accelero.getYAccel();
  z = accelero.getZAccel();
  Serial.print("\nx: ");
  Serial.print(x);  
  Serial.print(" \ty: ");
  Serial.print(y);  
  Serial.print(" \tz: ");
  Serial.print(z);
  Serial.print("\tG*10^-2");
  delay(100);
}

Here is the error message:

/Users/Navin/Documents/Arduino/libraries/MMA7361/AcceleroMMA7361.cpp:58: error: prototype for 'void AcceleroMMA7361::begin()' does not match any in class 'AcceleroMMA7361'
/Users/Navin/Documents/Arduino/libraries/MMA7361/AcceleroMMA7361.h:59: error: candidate is: void AcceleroMMA7361::begin(int, int, int, int, int, int)

Yes, "begin" has 9 parameters, and you've given it six.

Is there a way to fix this?

Fix your code or fix the library.
Since you don't want sleep or g-select, I'd fix the library.
YMMV.

Is it hard? Cause the library itself looks pretty intimidating. :sweat_smile: