Offset calibration program for an SPI ADXL345. Tested with mbed LPC1768.

Dependencies:   ADXL345 mbed

Fork of Accelerometer_ADXL345 by Thomas Emil

This is a program for offset calibration of ADXL345, it will also compute a fine offset correction number which cannot be corrected on ADXL345 itself. The IMU will need to be re-oriented 6x2 times for the calibration first 6 times for the coarse calibration, during which offsets on the ADXL will be calibrated and the next 6 will compute the fine offsets...

Files at this revision

API Documentation at this revision

Comitter:
Tuxitheone
Date:
Mon Mar 31 19:09:14 2014 +0000
Child:
1:a1d998b362e9
Commit message:
Test program for testing the ADXL345 brake outboard.

Changed in this revision

ADXL345.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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	Mon Mar 31 19:09:14 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/ADXL345/#bd8f0f20f433
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon Mar 31 19:09:14 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wim/code/TextLCD/#e0da005a777f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 31 19:09:14 2014 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "ADXL345.h"
+#include "TextLCD.h"
+
+ADXL345 accelerometer(p5, p6, p7, p8); // (SDA, SDO, SCL, CS);
+Serial pc(USBTX, USBRX); //For raw data
+TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7
+
+float x,y,z;
+
+
+int main()
+{
+
+    int readings[3] = {0, 0, 0};
+
+    lcd.cls();
+    lcd.printf("Starting ADXL345 test...\n");
+    lcd.printf("Device ID is: 0x%02x\n", accelerometer.getDevId());
+        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, +/-4g, 3.9mg/LSB.
+    accelerometer.setDataFormatControl(0x0B);
+
+    //3.2kHz data rate.
+    accelerometer.setDataRate(ADXL345_3200HZ);
+
+    //Measurement mode.
+    accelerometer.setPowerControl(0x08);
+
+    while (1) {
+
+        wait(0.1); //Intaval
+
+        accelerometer.getOutput(readings);
+
+        x=(int16_t)readings[0];
+        x=x*4e-3;
+        y=(int16_t)readings[1];
+        y=y*4e-3;
+        z=(int16_t)readings[2];
+        z=z*4e-3;
+
+        //13-bit, sign extended values.
+        lcd.cls();
+        lcd.printf("%.1f, %.1f, %.1f\n", x,y,z); //Convertet to G
+        lcd.printf(" X    Y    Z  ");
+            pc.printf("%i, %i, %i\n\r", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); //Raw data
+
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 31 19:09:14 2014 +0000
@@ -0,0 +1,1 @@
+http://world3.dev.mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file