MBed LPC1768 and ADXL345 GY-291 example

The ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface.

The ADXL345 is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (4 mg/LSB) enables measurement of inclination changes less than 1.0°.

Several special sensing functions are provided. Activity and inactivity sensing detect the presence or lack of motion and if the acceleration on any axis exceeds a user-set level. Tap sensing detects single and double taps. Free-fall sensing detects if the device is falling.

These functions can be mapped to one of two interrupt output pins. An integrated, patent pending 32-level first in, first out (FIFO) buffer can be used to store data to minimize host processor intervention.






I used the following connection from the module above to my MBED 1768

MBED Connection Module Connection
3v3 – VOUT VCC
Gnd Gnd
SDA – Pin 28 SDA
SCL – Pin 27 SCL

This is a layout showing the connection







This needs the following example – https://developer.mbed.org/users/peterswanson87/code/ADXL345_I2C/ – Add this to the MBed compiler

Here is the code

#include "ADXL345_I2C.h"
 ADXL345_I2C accelerometer(p28, p27);
 Serial pc(USBTX, USBRX);
 int main() {
 int readings[3] = {0, 0, 0};
 pc.printf("Starting ADXL345 test...\n");
 pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID());
 // These are here to test whether any of the initialization fails. It will print the failure
 if (accelerometer.setPowerControl(0x00)){
 pc.printf("didn't intitialize power control\n"); 
 return 0; }
 //Full resolution, +/-16g, 4mg/LSB.
 pc.printf("didn't set data format\n");
 return 0; }
 //3.2kHz data rate.
 pc.printf("didn't set data rate\n");
 return 0; }
 //Measurement mode.
 if(accelerometer.setPowerControl(MeasurementMode)) {
 pc.printf("didn't set the power control to measurement\n"); 
 return 0; } 
 while (1) {
 pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);



GY-291 ADXL345 3-Axis Digital Gravity Sensor Acceleration Module IIC/SPI transmission

Be Sociable, Share!

24/7 Customer Service (800) 927-7671