Example application using the RM3100 magnetometer

Dependencies:   Rm3100

Committer:
fwrawx
Date:
Tue Feb 21 04:59:50 2017 +0000
Revision:
0:f939d6b78be6
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fwrawx 0:f939d6b78be6 1 #include "mbed.h"
fwrawx 0:f939d6b78be6 2 #include "Rm3100.hpp"
fwrawx 0:f939d6b78be6 3
fwrawx 0:f939d6b78be6 4 int main(void)
fwrawx 0:f939d6b78be6 5 {
fwrawx 0:f939d6b78be6 6 Serial pc(USBTX, USBRX);
fwrawx 0:f939d6b78be6 7 pc.baud(115200);
fwrawx 0:f939d6b78be6 8
fwrawx 0:f939d6b78be6 9 printf("### Hello RM3100 ###\r\n");
fwrawx 0:f939d6b78be6 10
fwrawx 0:f939d6b78be6 11 int addr = ((Rm3100::RM3100_ADDR | Rm3100::RM3100_ADDR_SSN) << 1);
fwrawx 0:f939d6b78be6 12 struct Rm3100::Status status = { 0 };
fwrawx 0:f939d6b78be6 13 struct Rm3100::Sample sample = { 0 };
fwrawx 0:f939d6b78be6 14
fwrawx 0:f939d6b78be6 15 Rm3100 sensor(I2C_SDA, I2C_SCL, addr);
fwrawx 0:f939d6b78be6 16
fwrawx 0:f939d6b78be6 17 sensor.Begin();
fwrawx 0:f939d6b78be6 18 osDelay(1);
fwrawx 0:f939d6b78be6 19
fwrawx 0:f939d6b78be6 20 sensor.SetCycleCounts(200);
fwrawx 0:f939d6b78be6 21 osDelay(1);
fwrawx 0:f939d6b78be6 22
fwrawx 0:f939d6b78be6 23 sensor.SetRate(100.0f);
fwrawx 0:f939d6b78be6 24 osDelay(1);
fwrawx 0:f939d6b78be6 25
fwrawx 0:f939d6b78be6 26 sensor.SetContinuousMeasurementMode(true);
fwrawx 0:f939d6b78be6 27 osDelay(1);
fwrawx 0:f939d6b78be6 28
fwrawx 0:f939d6b78be6 29 while (true) {
fwrawx 0:f939d6b78be6 30 sensor.GetStatus(&status);
fwrawx 0:f939d6b78be6 31 if (status.drdy) {
fwrawx 0:f939d6b78be6 32 sensor.GetSample(&sample);
fwrawx 0:f939d6b78be6 33 printf("x: %f, y: %f, z: %f\r\n", sample.x, sample.y, sample.z);
fwrawx 0:f939d6b78be6 34 }
fwrawx 0:f939d6b78be6 35 osDelay(10);
fwrawx 0:f939d6b78be6 36 }
fwrawx 0:f939d6b78be6 37 }