LSM303DLHC basic accelerometer test

Dependencies:   LSM303DLHC mbed

This is a very basic accelerometer test program.

It was done on Nordic nrf51 platform but it should run on any mbed with I2c. Just be careful on changing the I2C pins accordingly.

Files at this revision

API Documentation at this revision

Comitter:
LuisMSanchezB
Date:
Tue May 24 01:35:41 2016 +0000
Commit message:
publish

Changed in this revision

LSM303DLHC.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
diff -r 000000000000 -r d017e94ed612 LSM303DLHC.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM303DLHC.lib	Tue May 24 01:35:41 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/julioefajardo/code/LSM303DLHC/#ffed7ef0b248
diff -r 000000000000 -r d017e94ed612 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 24 01:35:41 2016 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+#include "LSM303DLHC.h"
+
+#define Rad2Dree       57.295779513082320876798154814105f
+
+DigitalOut led1(LED1);
+
+int main()
+{
+    Serial sp(USBTX, USBRX);
+    sp.baud(115200);
+    sp.printf("Accelerometer example\r\n");
+
+    LSM303DLHC lsm303(p30, p7);
+    lsm303.init();
+    
+    int accelReading[3];
+
+    while(1)
+    {
+        led1 = 1;
+        lsm303.readAcc(accelReading);
+        
+        sp.printf("Accelerometer read x = %d, y = %d, z = %d\r", accelReading[0], accelReading[1], accelReading[2]);
+        
+        wait(0.5);
+        led1 = 0;
+        wait(0.5);
+    }
+}
+
diff -r 000000000000 -r d017e94ed612 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 24 01:35:41 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file