ADXL335 Accelerometer Interfacing with MSP-EXP430G2 TI Launchpad

Overview of Accelerometer

ADXL335 Accelerometer Module
ADXL335 Accelerometer Module

 

The accelerometer is an electromechanical device that measures the force of acceleration due to gravity in the g unit.

It can be used in applications requiring tilt sensing.

The ADXL335 measures acceleration along X, Y, and Z axes and gives analog voltage output proportional to the acceleration along these 3 axes.

Microcontrollers can process these voltages by converting them to digital signals using ADC.

For more information about the ADXL335 accelerometer and how to use it, refer to the topic ADXL335 Accelerometer Module in the sensors and modules section.

 

Connection Diagram of ADXL335 with MSP-EXP430G2 TI Launchpad

Interfacing ADXL335 Accelerometer Module With MSP-EXP430G2 TI Launchpad
Interfacing ADXL335 Accelerometer Module With MSP-EXP430G2 TI Launchpad

 

Read X, Y, and Z access of Accelerometer ADXL335 using MSP-EXP430G2 TI Launchpad

Finding the roll and pitch of the device using analog voltages of the accelerometer module and displaying on the Energia serial monitor.

 

Tread Carefully: MSP-EXP430G2 TI Launchpad board has a RAM of 512 bytes which is easily filled, especially while using different libraries. There are times when you need the Serial buffer to be large enough to contain the data you want and you will have to modify the buffer size for the Serial library. While doing such things, we must ensure that the code does not utilize more than 70% RAM. This could lead to the code working in an erratic manner, working well at times, and failing miserably at others. 

There are times when the RAM usage may exceed 70% and the codes will work absolutely fine, and times when the code will not work even when the RAM usage is 65%. 

In such cases, a bit of trial and error with the buffer size and/or variables may be necessary.

 

Accelerometer ADXL335 Code for MSP-EXP430G2 TI Launchpad

#include <math.h>
const int x_out = A3; /* connect x_out of module to A3 of TI Launchpad board */
const int y_out = A4; /* connect y_out of module to A4 of TI Launchpad board */
const int z_out = A5; /* connect z_out of module to A5 of TI Launchpad board */

void setup() {
  Serial.begin(9600); /* Define baud rate for serial communication */ 
}

void loop() {
  int x_adc_value, y_adc_value, z_adc_value; 
  double x_g_value, y_g_value, z_g_value;
  double roll, pitch, yaw;
  x_adc_value = analogRead(x_out); /* Digital value of voltage on x_out pin */ 
  y_adc_value = analogRead(y_out); /* Digital value of voltage on y_out pin */ 
  z_adc_value = analogRead(z_out); /* Digital value of voltage on z_out pin */ 
  Serial.print("x = ");
  Serial.print(x_adc_value);
  Serial.print("\t\t");
  Serial.print("y = ");
  Serial.print(y_adc_value);
  Serial.print("\t\t");
  Serial.print("z = ");
  Serial.print(z_adc_value);
  Serial.print("\t\t");
  //delay(100);
  
  x_g_value = ( ( ( (double)(x_adc_value * 3.3)/1024) - 1.65 ) / 0.330 ); /* Acceleration in x-direction in g units */ 
  y_g_value = ( ( ( (double)(y_adc_value * 3.3)/1024) - 1.65 ) / 0.330 ); /* Acceleration in y-direction in g units */ 
  z_g_value = ( ( ( (double)(z_adc_value * 3.3)/1024) - 1.80 ) / 0.330 ); /* Acceleration in z-direction in g units */ 

  roll = ( ( (atan2(y_g_value,z_g_value) * 180) / 3.14 ) + 180 ); /* Formula for roll */
  pitch = ( ( (atan2(z_g_value,x_g_value) * 180) / 3.14 ) + 180 ); /* Formula for pitch */
  //yaw = ( ( (atan2(x_g_value,y_g_value) * 180) / 3.14 ) + 180 ); /* Formula for yaw */
  /* Not possible to measure yaw using accelerometer. Gyroscope must be used if yaw is also required */

  Serial.print("Roll = ");
  Serial.print(roll);
  Serial.print("\t");
  Serial.print("Pitch = ");
  Serial.print(pitch);
  Serial.print("\n\n");
  delay(1000);
}

 

Video of ADXL335 Accelerometer Reading using MSP-EXP430G2 TI Launchpad


Components Used

TI Launchpad MSP-EXP430G2
TI Launchpad MSP-EXP430G2
1
ADXL335 Accelerometer Module
Accelerometer ADXL335 sensor measures acceleration of gravity. It is used to measure the angle of tilt or inclination in application systems such as in mobile devices, gaming applications, laptops, digital cameras, aeroplanes etc.
1

Downloads

Accelerometer_Interfacing_With_TI_Launchpad_INO Download
Ad