Go Down

Topic: ADXL335 accelerometer (Read 12040 times) previous topic - next topic

nagesh123

Hello Everybody..
I bought a new sensor IMU Analog Combo Board - 5 Degrees of Freedom IDG500/ADXL335. I am trying to connect the accelerometer to the arduino and monitor the readings using Serial.print, but the readings that I am getting is 1023 for all three axis, X, Y and Z.  The connections are,

X - Acc: port 5
Y - Acc: port 4
Z - Acc: port 3
GND    : GND
3.3V    : 3.3V

The code I am using is:

#include <Wire.h>
#include <stdint.h>
#include <avr/io.h>
#include <avr/pgmspace.h>

byte sensorpin = 5;
byte Sensorpin = 4;
byte sensorPin = 3;

volatile uint16_t X;
volatile uint16_t Y;
volatile uint16_t Z;

void setup()
{               
  Serial.begin(9600);     
  Serial.println("\n Start");
  analogReference(EXTERNAL);
}

void loop()
{
  X = analogRead(sensorpin);
  Serial.println("\n\n X");
  Serial.print(X);
  Y = analogRead(Sensorpin);
  Serial.println("\n\n Y");
  Serial.print(Y);
  Z = analogRead(sensorPin);
  Serial.println("\n\n Z");
  Serial.print(Z);
}

I think everything is good, but I don't know why it's not working
please help me out with this.
Thank You..

liuzengqiang

You didn't connect external analog reference to anything, such as the 3.3V on arduino board, did you?

BTW, what's wrong with your creativity naming variables? You gotta be kidding me to name your sensor pins the way you did it.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

nagesh123

Thank You..
                        I have changed the code and it gives reading in between 200 to 300, but there is another problem that I am facing. When I move my accelerometer the serial monitor stops displaying the readings, in other words, it hangs. It says error in Serial.serial event(), IO Exception: I/O error in nativeavailable and  RXTX port. nativeavailable

The code that I am using is this:

#include <stdint.h>
#include <avr/io.h>
#include <avr/pgmspace.h>

uint16_t X;
uint16_t Y;
uint16_t Z;

void setup()
{
Serial.begin(9600);           // sets the serial port to 9600
}
void loop()
{
X = analogRead(50);   
Y = analogRead(53);     
Z = analogRead(49);

Serial.println("\n\n X");
Serial.print(X);
Serial.println("\n\n Y");
Serial.print(Y);
Serial.println("\n\n Z");
Serial.print(Z);         
}

WillR

#3
Feb 11, 2011, 09:51 pm Last Edit: Feb 11, 2011, 10:02 pm by WillR Reason: 1
The sensor I use is the same one really... You really should check the libraries for example code...


Code: [Select]

/*
MMA7361L
Minor modifications by D. Robinson Feb 1, 2011

NOTE -- ANALOG REFERENCE MUST BE CONNECTED AFTER UPLOAD

NOTE 3.3 V Sensor -- Must be connected to 3.3V power!
Not having the EXTERNAL REFERENCE connected before reading the sensor may damage the arduino...

Reads an Analog Devices ADXL3xx or an MMA7361L accelerometer and communicates the
acceleration to the computer.  The pins used are designed to be easily
compatible with the breakout boards from Sparkfun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80

http://www.arduino.cc/en/Tutorial/ADXL3xx

The circuit:

analog 5: z-axis
analog 4: y-axis
analog 3: x-axis

created 2 Jul 2008
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe

This example code is in the public domain.

*/


const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A4;                  // y-axis
const int zpin = A5;                  // z-axis (only on 3-axis models)

void setup()
{
 // initialize the serial communications:
 Serial.begin(9600);

 analogReference(EXTERNAL);  /// NOTE!!!!!!!

 Serial.println("  ++++ MMA7361L Sensor ++++");
 Serial.println();
 Serial.print("X Sensor");

 Serial.print("\t");
 Serial.print("Y Sensor");

 Serial.print("\t");
 Serial.println("Z Sensor");
 
 

void loop()
{
 // print the sensor values:
 Serial.print(analogRead(xpin));
 // print a tab between values:
 Serial.print("\t");
 Serial.print("\t");
 Serial.print(analogRead(ypin));
 // print a tab between values:
 Serial.print("\t");
 Serial.print("\t");
 Serial.print(analogRead(zpin));
 Serial.println();
 // delay before next reading:
 delay(200);
}



Use the proper pin numbers. It does work really. Maybe you damaged the pins you tried first.

Let people know which unit you are running... UNO? Mega2560? what?

I just ran and tested this on the MMA7361L -- it has a G selection, and a Self test as well -- as I said really the same thing. ADXL335 is less noisy tho.


nagesh123

Thank You..
I have connected the 3.3 terminal on the accelerometer to the 3.3V on the Arduino Mega..
and when I add
analogReference(External);
in the setup, the serial monitor displays 1023 for all, X, Y and Z
my earlier code gives me reading between 200 to 300.
I don't know why the serial monitor hangs while doing so.

My connections:

Acc. 3.3: 3.3V on the Arduino Mega.(The 3.3V is not connected to any other terminal)
do I have to short the Aref and 3.3V terminal through a resistor (5Kohm)?
Acc. GND: GND on the Mega
X,Y and Z on Acc: to 38, 39 and 40 (As you said, I tried using different pins but still it doesn't work)

retrolefty

Quote
do I have to short the Aref and 3.3V terminal through a resistor (5Kohm)?



To utilize the external reference, you must wire the desired reference voltage to the Aref pin. The need for a series resistor is only if you change the software back to internal (+5vdc Avcc pin) reference while there is still a different voltage wired to the Aref pin, then there can be a high current path (not good) between the internal and external reference source voltages.

Read about using external reference details here: http://arduino.cc/en/Reference/AnalogReference

Lefty

WillR

#6
Feb 12, 2011, 03:57 pm Last Edit: Feb 12, 2011, 04:01 pm by WillR Reason: 1
I suspect that you have damaged some pins on the Arduino.

Use a good quality voltmeter to measure the output of the ADXL335 chip. I am sure that it survived.

I am guessing that with the silk screen side up the board will be reading something like the following:

But, First measure the supply voltage -- it should be 3.3V (Between ground and VCC)
Since there is not a lot of room on the sensor breakout position the probes wherever necessary so that you don't short things ... But do measure the voltage at the board. Make sure that your ground wire actually connects -- you could have floating voltages.

Then measure the outputs...

1.8 - 2.2V for Z
about 1.2 -1.5 V for X and Y

The main thing is that there is approximately that difference -- don't get hung up on exact numbers. If the sensor is not positioned level it will be different....

Once you know that the voltages are correct then you can move the leads to three new analog pins and try those pins.

YOU DO NOT NEED TO USE THE External Reference to start -- just see that you get something other than 1024...

Then once you know it is correct (And you have the command in your script) plug in the AREF and you should get about:

Z -- around 650 ~ more or less
X&Y about 520 ~ more or less

Don't have a voltmeter? Get one $60 US/CDN gets one with Frequency Measurement and all that. I have the equivalent of the UT60E -- I got mine from Steren.

This is basic troubleshooting.

The Compiler on this site is your friend. Use it -- it's simple and there are LOTS of examples to start out.

I have been at this over 40 years and designed math and communications systems. I was not the least bit embarrassed to start with the simpler scripts and learn from the people who already tried this stuff. The examples are for the most part excellent!

That is the best advice I can give.


PS: One more thing... Maybe you ran a PINMODE script and a digital write that set the pull up resistors high. There are a lot of scripts where the anlog pins are used to "do something digital" or they will condition pins to provide power and ground to switch devices on or off...  I avoid them, or If I do want to try the example, I convert them to "normal" digital pins and I just use normal continuous power. Get fancy after you have some experience. See the reference area for a better explanation!





nagesh123

Thank you guys...
but the serial monitor is displaying the readings if I do not move the accelerometer and when I move it, the serial monitor hangs.
It's giving error related to serial monitor and also I have to select the specific serial port every time my serial monitor hangs.
If the connections are wrong then I think it shouldn't display anything..
I tried using other pins but still I am getting the same problem.

I have one question:

I am not using analogReference(External) in my code, as I am using 3.3V terminal on the arduino (Mega) so I don't have to worry about Aref, is that so?
I am not connecting anything else, just the accelerometer.
Also, I noticed one thing, if I connect my accelerometer to the digital pins or analog pins it gives the same readings, isn't it strange? I am using Mega (ATmega 1280). I am facing the same problem, doesn't matter if I connect ADXL335 to digital or analog pins.


WillR

Thank you guys...
but the serial monitor is displaying the readings if I do not move the accelerometer and when I move it, the serial monitor hangs.
It's giving error related to serial monitor and also I have to select the specific serial port every time my serial monitor hangs.


That is a different issue. Nothing to do with the sensor.

Sort out that issue first.

Try the compiler (V22) on this site and run the simplest script you can find that gives serial output.

Till you do that we're all wasting time.


nagesh123

Hello Guys...

I think I got it working..
Actually I am using a combo which has accelerometer and gyroscope both in one sensor..
It has a terminal Vref. I connected this terminal to the 3.3V terminal of my Arduino Mega and it worked...It gives me 0 0 0 for x, y and z axis and also when I move my accelerometer in any specific axis it gives the correct readings..
Also, I got to know that we have to connect the accelerometer to the Analog Input pins. It doesn't work if you connect it to digital pins. I think as the input is analog, the displacement we have to connect it to the analog input pins.
I was confused because I worked on RF communication and I connected my receiver to the digital pins and it was working fine. Now I know that it was digital signal and not the analog signal and thats why it was working fine. If you are using any sensor that converts analog value to digital you have to connect it to the analog input terminal. I am so dumb..

I think I am right please do correct me if I'm wrong.

Anyways, thank you guys for your help. This forum is awesome. You guys rock...


WillR

Also, I got to know that we have to connect the accelerometer to the Analog Input pins. It doesn't work if you connect it to digital pins.

I think if you check what I said earlier about the simplest possible examples... lol

Been there done that got a T-Shirt to match.

We old timers have a T-Shirt that says RTFI.

I= Instructions
R= Read

I leave that with you....
:P

Go Up