Example application using the RM3100 magnetometer

Dependencies:   Rm3100

Files at this revision

API Documentation at this revision

Comitter:
fwrawx
Date:
Tue Feb 21 04:59:50 2017 +0000
Commit message:
initial commit

Changed in this revision

Rm3100.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-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rm3100.lib	Tue Feb 21 04:59:50 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/fwrawx/code/Rm3100/#b6ab7f28cde2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 21 04:59:50 2017 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "Rm3100.hpp"
+
+int main(void)
+{
+    Serial pc(USBTX, USBRX);
+    pc.baud(115200);
+
+    printf("### Hello RM3100 ###\r\n");
+
+    int addr = ((Rm3100::RM3100_ADDR | Rm3100::RM3100_ADDR_SSN) << 1);
+    struct Rm3100::Status status = { 0 };
+    struct Rm3100::Sample sample = { 0 };
+
+    Rm3100 sensor(I2C_SDA, I2C_SCL, addr);
+
+    sensor.Begin();
+    osDelay(1);
+
+    sensor.SetCycleCounts(200);
+    osDelay(1);
+
+    sensor.SetRate(100.0f);
+    osDelay(1);
+
+    sensor.SetContinuousMeasurementMode(true);
+    osDelay(1);
+
+    while (true) {
+        sensor.GetStatus(&status);
+        if (status.drdy) {
+            sensor.GetSample(&sample);
+            printf("x: %f, y: %f, z: %f\r\n", sample.x, sample.y, sample.z);
+        }
+        osDelay(10);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Feb 21 04:59:50 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#bcf7085d85b2811b5d68bdda192c754eadfb8f88