Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod ACL with Arduino Uno

Application notes for Pmod ACL and Arduino Uno. The 3 components, X, Y & Z, of the accelerometer are displayed in the serial monitor.

BeginnerShowcase (no instructions)1 hour529
Using the Pmod ACL with Arduino Uno

Things used in this project

Story

Read more

Schematics

Pmod ACL and Arduino Uno Fritzing file

Fritzing file displaying the connection of the Pmod ACL to the Arduino Uno.

Pmod ACL and Arduino Uno Fritzing Image

Fritzing image displaying the connection between the Pmod ACL and Arduino Uno.

Code

Pmod ACL and Arduino Uno Code

Arduino
Using this code will display the 3 components X, Y, and Z of the accelerometer on the serial monitor.
/************************************************************************
*
* Test of the Pmod
*
*************************************************************************
* Description: Pmod_ACL
* The 3 components X, Y, and Z of the accelerometer
* are displayed in the serial monitor
*
* Material
* 1. Arduino Uno
* 2. Pmod ACL 
*
************************************************************************/

// Déclaration of the adress of the module
#define ADXL345_Adresse 0x53 // ADXL345 adress
#define POWER_CTL 0x2D // Power Control register
#define DATA_FORMAT 0x31 // Data Format register
#define DATAX0 0x32 // LSB axe X
#define DATAX1 0x33 // MSB axe X
#define DATAY0 0x34 // LSB axe Y
#define DATAY1 0x35 // MSB Y
#define DATAZ0 0x36 // LSB axe Z
#define DATAZ1 0x37 // bMSB Z

// Configuration of the module
#define ADXL345_Precision2G 0x00
#define ADXL345_Precision4G 0x01
#define ADXL345_Precision8G 0x02
#define ADXL345_Precision16G 0x03
#define ADXL345_ModeMesure 0x08

// call library
#include <Wire.h>

byte buffer[6]; // storage of data of the module
int i = 0;
int composante_X;
int composante_Y;
int composante_Z;

void setup(void)
{
 Serial.begin(9600); // initialization of serial communication
 Wire.begin (); // initialization of I2C communication
 Wire.beginTransmission (ADXL345_Adresse); // configuration of the module
 Wire.write (DATA_FORMAT);
 Wire.write (ADXL345_Precision4G);
 Wire.endTransmission ();
 Wire.beginTransmission (ADXL345_Adresse);
 Wire.write (POWER_CTL);
 Wire.write (ADXL345_ModeMesure);
 Wire.endTransmission ();
}

void loop()
{
 Wire.beginTransmission (ADXL345_Adresse);
 Wire.write(DATAX0);
 Wire.endTransmission ();
 Wire.beginTransmission (ADXL345_Adresse);
 Wire.requestFrom(ADXL345_Adresse, 6); // Recovery of the 6 components
 i=0;
 while(Wire.available())
 {
  buffer[i] = Wire.read();
  i++;
 }
 Wire.endTransmission();
 composante_X=(buffer[1] << 8) | buffer[0]; // Development of the 3 components
 composante_Y=(buffer[3] << 8) | buffer[2];
 composante_Z=(buffer[5] << 8) | buffer[4];
 Serial.print("X="); // Display of components in the serial monitor
 Serial.print (composante_X);
 Serial.print('\t'); // tabulation
 Serial.print("Y=");
 Serial.print (composante_Y);
 Serial.print('\t');
 Serial.print("Z="); 
 Serial.print (composante_Z);
 Serial.println("");
 delay(500);
}

Credits

Martha Migliacio

Martha Migliacio

5 projects • 7 followers
Alex Wong

Alex Wong

5 projects • 19 followers
I work in Digilent and like creating projects
Thanks to Lextronics.

Comments