ADXL345 triple axis, digital accelerometer example.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
aberk
Date:
Tue Aug 03 08:31:00 2010 +0000
Commit message:
Version 1.0

Changed in this revision

ADXL345_lib.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADXL345_lib.lib	Tue Aug 03 08:31:00 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/programs/ADXL345_lib/latest
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 03 08:31:00 2010 +0000
@@ -0,0 +1,36 @@
+#include "ADXL345.h"
+
+ADXL345 accelerometer(p5, p6, p7, p8);
+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]);
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 03 08:31:00 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da