Daniel Delsuc
/
RM3100BB_Sample_Code
Sample program for interfacing with PNI's RM3100 Breakout Board
Diff: main.cpp
- Revision:
- 0:6ddf88b49483
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 26 18:40:57 2017 +0000 @@ -0,0 +1,66 @@ +/** +* @file main.cpp +* +* @brief Sample code for RM3100. +* @authors Betty Zhang, Daniel Delsuc +* @date 03/03/2017 +* @copyright (C) 2017 PNI Corp +* +* @copyright This sample code is provided "as is" without express or implied warranty. +* +*/ + +// Note: This program assumes the RM3100 is connected using the I2C Interface + +#include "main.h" + +// Check if DRDY was triggered +bool DataReady() +{ + if (DRDY_PIN == 1) + return true; + else + return false; +} + +int main() +{ + pc.baud(115200); + int dataInCount[3]; + float x, y, z; + + mag_initialize_sensor(); + + mag_set_sample_rate(100); //100Hz + + mag_set_power_mode(SensorPowerModeActive); + + //while (!DataReady()); //wait here, if using DRDY Int + //If not using DRDY, user can check status Reigster 0x34 for dataready. + + //From User Manual Table 3-1 : Geomagnetic Sensor Performance + //50 CycleCount ~ 20 LSB/uT + //100 CycleCount ~ 38 LSB/uT + //200 CycleCount ~ 75 LSB/uT + //Linear equation: gain (LSB/uT) = (0.3671 * CycleCount + 1.5) + + int CycleCount = CCP0 | (CCP1 << 8); + float gain = 0.3671 * CycleCount + 1.5; + + while(1) + { + //Get sample data in counts + mag_get_sample_data((int*)&dataInCount); + + while (!DataReady()); //wait here, if using DRDY Int + + //Convert to uT + x = (float)dataInCount[0] / gain; + y = (float)dataInCount[1] / gain; + z = (float)dataInCount[2] / gain; + + pc.printf("X: %f, Y: %f, Z: %f\n", x, y, z); + //wait(1); + } + return 0; +} \ No newline at end of file