Simple accelerometer and magnetometer program example for Hexiwear featuring UART

Dependencies:   FXOS8700

Fork of Hexi_Accelero_Magneto_Example by Hexiwear

This project demonstrates the use of the FXOS8700CQ combo Accelerometer and Magnetometer sensor embedded in hexiwear

Open a Hyperterminal tool on your computer and connect it to the "mbed Serial port (COMxx)" with Baud rate "9600bps"

Compile the project and copy the binary "Hexi_Accelero_Magneto_Example_HEXIWEAR.bin" in the DAP-LINK drive from your computer file explorer Press the K64F-RESET button on the docking station to start the program on your board

Message "Begin Data Acquisition from FXOS8700CQ sensor..." will appear in the Hyperterminal window
Then every 500ms the value of the Accelerometer and the Magnetometer for the Axis X, Y and Z plus their RMS value will be displayed in the Hyperterminal window and the LED will blink Green

Mon Aug 15 23:31:10 2016 +0000
Accelerometer and magnetometer program example for hexiwear

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:207337d58f96 1 #include "mbed.h"
GregC 2:f9c24c129575 2 #include "FXOS8700.h"
maclobdell 0:207337d58f96 3
GregC 2:f9c24c129575 4 // Check out the full featured example application for interfacing to the
GregC 2:f9c24c129575 5 // Accelerometer/Magnetometer device at the following URL
GregC 2:f9c24c129575 6 //
maclobdell 1:6da908234299 7
GregC 2:f9c24c129575 8 DigitalOut led1(LED_GREEN);
GregC 2:f9c24c129575 9
GregC 2:f9c24c129575 10 // Initialize Serial port
GregC 2:f9c24c129575 11 Serial pc(USBTX, USBRX);
maclobdell 0:207337d58f96 12
maclobdell 0:207337d58f96 13 // Pin connections & address for Hexiwear
GregC 2:f9c24c129575 14 FXOS8700 accel(PTC11, PTC10);
GregC 2:f9c24c129575 15 FXOS8700 mag(PTC11, PTC10);
maclobdell 0:207337d58f96 16
maclobdell 0:207337d58f96 17 // main() runs in its own thread in the OS
maclobdell 0:207337d58f96 18 // (note the calls to Thread::wait below for delays)
maclobdell 0:207337d58f96 19 int main() {
maclobdell 0:207337d58f96 20
GregC 2:f9c24c129575 21 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700
GregC 2:f9c24c129575 22 accel.accel_config();
GregC 2:f9c24c129575 23 mag.mag_config();
GregC 2:f9c24c129575 24
GregC 2:f9c24c129575 25 float accel_data[3]; float accel_rms=0.0;
GregC 2:f9c24c129575 26 float mag_data[3]; float mag_rms=0.0;
GregC 2:f9c24c129575 27
GregC 3:9f60cb7455c4 28 printf("Begin Data Acquisition from FXOS8700CQ sensor....\r\n\r\n");
GregC 2:f9c24c129575 29 wait(0.5);
GregC 2:f9c24c129575 30
GregC 2:f9c24c129575 31 while (1) {
maclobdell 0:207337d58f96 32 led1 = !led1;
maclobdell 0:207337d58f96 33 // Example data printing
GregC 2:f9c24c129575 34
GregC 2:f9c24c129575 35 accel.acquire_accel_data_g(accel_data);
GregC 2:f9c24c129575 36 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
GregC 2:f9c24c129575 37 printf("Accelerometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\r",accel_data[0],accel_data[1],accel_data[2],accel_rms);
GregC 2:f9c24c129575 38 wait(0.01);
GregC 2:f9c24c129575 39
GregC 2:f9c24c129575 40 mag.acquire_mag_data_uT(mag_data);
GregC 2:f9c24c129575 41 mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
GregC 2:f9c24c129575 42 printf("Magnetometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\n\r",mag_data[0],mag_data[1],mag_data[2],mag_rms);
GregC 2:f9c24c129575 43 wait(0.01);
maclobdell 0:207337d58f96 44
maclobdell 0:207337d58f96 45 Thread::wait(500);
maclobdell 0:207337d58f96 46 }
maclobdell 0:207337d58f96 47 }