Accelerometer Help

Hi there, I'm a bit new to the microcontroller world so please bear with me.

I have a Arduino Duemilanove and a MMA7361 accelerometer (http://www.sparkfun.com/commerce/product_info.php?products_id=9652), and basically I'd just like to get some reading sfrom the accelerometer.

As far as setting it up, I have the power connected to the arduino's 3.3volt supply. Also, I have the AREF pin connected to the 3.3volts as well so I could take advantage of the analogReference. The x,y,z outputs are connected to 1-3 of the analog inputs.

The code is below:

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

 void loop() 
 {
   int xaxis = analogRead(1);
   int yaxis = analogRead(2);
   int zaxis = analogRead(3);
   
   Serial.print("x-axis");
   Serial.print("\t");   
   Serial.println(xaxis);

   Serial.print("y-axis");
   Serial.print("\t");   
   Serial.println(yaxis);
   
   Serial.print("z-axis");
   Serial.print("\t");   
   Serial.println(zaxis);

   Serial.println("");   
   delay(1000);
 }

From what I understand I should get 10 bit resolution over the 3.3 volts, or 1024 points of over the 3.3 volts, and the accelerometer says I should get around 2.45volts for 1g. My problem is, I seem to be getting junk data. The numbers are averaging around 80 for all the outputs and don't change when I move the sensor.

To test the arduino, I directly put the 3.3volts to each one of the analog input pins and it read 1024, so I'm under the impression that the arduino and analogReference are working.

I'm sure I may be doing something wrong, but I can't figure it out. I'd love for someone to point it out to me, and I could hit myself on the head. Thanks for any help in advance.

After reading it's datasheet, I am guessing that it is in sleep mode. To operate at normal mode, the datasheet says apply high input to pin seven. So maybe it will work after you do so :) Good luck!

I directly put the 3.3volts to each one of the analog input pins and it read 1024

[pedant alert] No, you didn't or, if you did, you've got serious problems ;D

Yes, sleep mode is the usual problem with these devices.

and just like i hoped, i got to hit myself on the head, ha.
thanks alot, i was under the assumption it didn’t need to be connected.

by the way Groove, why is bad to put the arduino power supply directly to the analog inputs? i’m not that great with electronics.

anyways, i added a crappy averaging function in there. i still haven’t gotten familiar with the whole programming language, so please tell me how it should be. i kept getting confused with the stuff i found from searching, guess i’m not on that level yet.

 int x_avg[10];
 int y_avg[10];
 int z_avg[10];
 
 int x_axis = 0;
 int y_axis = 0;
 int z_axis = 0;
 
 int slp_pin = 5;
 int i;
 
 void setup() 
 {
   Serial.begin(9600); 
   analogReference(EXTERNAL);
 }
 
 void loop() 
 {
   digitalWrite(slp_pin, HIGH);
   
   for (i=0; i<10; i=i+1)
   {
     x_avg[i] = analogRead(1);
     y_avg[i] = analogRead(2);
     z_avg[i] = analogRead(3);
   }
   
   for (i=0; i<10; i=i+1)
   {
     if (i == 0)
     {
       x_axis = x_avg[i];
       y_axis = y_avg[i];
       z_axis = z_avg[i];
     }
     else
     {
       x_axis = x_axis + x_avg[i];
       y_axis = y_axis + y_avg[i];
       z_axis = z_axis + z_avg[i];
     }
   }
     
   Serial.print("x-axis");
   Serial.print("\t");   
   Serial.println(x_axis/10);
 
   Serial.print("y-axis");
   Serial.print("\t");   
   Serial.println(y_axis/10);
   
   Serial.print("z-axis");
   Serial.print("\t");   
   Serial.println(z_axis/10);

   Serial.println("");   
   delay(1000);
 }

I suspect what Groove was saying is that you didn't read 1024, not that you shouldn't connect supplies to analogue inputs.

0-1023, ohhhhhhh. i just hit myself on the head again.