ADXL345 3-axis Acceleration Sensor sample

Dependencies:   ADXL345_I2C mbed

Fork of ADXL345 by James Allen

About ADXL345

ADXL345 is a 3-axis acceleration sensor and can be controlled by using the I2C.

About sample program

This program outputs the acceleration information of 3-axis to the terminal.
The 3-axis is as follows:
/media/uploads/1050186/adxl345_axis_1.png
In the graph, the acceleration information of 3-axis showes.
/media/uploads/1050186/tilt.png /media/uploads/1050186/adxl345_output_to_graph_1.png

About wiring

SensorGR-PEACH
VDD3.3V
GNDGND
SCLD15
SDAD14

Files at this revision

API Documentation at this revision

Comitter:
jrha
Date:
Fri Mar 11 15:54:40 2011 +0000
Child:
1:c835cfa8b41c
Commit message:

Changed in this revision

ADXL345_I2C.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADXL345_I2C.lib	Fri Mar 11 15:54:40 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/nimbusgb/code/ADXL345_I2C/#92fa975dab32
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 11 15:54:40 2011 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "ADXL345_I2C.h"
+ 
+//ADXL345 accelerometer(p5, p6, p7, p8);
+ADXL345_I2C accelerometer(p9, p10);
+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.getDevId());
+ 
+    //Go into standby mode to configure the device.
+    accelerometer.setPowerControl(0x00);
+ 
+    //Full resolution, +/-16g, 4mg/LSB.
+    accelerometer.setDataFormatControl(0x0B);
+     
+    //3.2kHz data rate.
+    accelerometer.setDataRate(ADXL345_3200HZ);
+ 
+    //Measurement mode.
+    accelerometer.setPowerControl(0x08);
+ 
+    while (1) 
+    {
+     
+        wait(0.1);
+        
+        accelerometer.getOutput(readings);
+         
+        //13-bit, sign extended values.
+        pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
+    }
+ 
+}