Simple gyroscope program example for Hexiwear featuring UART

Dependencies:   FXAS21002

Fork of Hexi_gyro_app by Mac Lobdell

This project demonstrates the use of the FXAS21002CQ Gyroscope 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_Gyro_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

Every 1s the value of the Gyroscope for the Axis Roll, Pitch and Yaw plus their RMS value will be displayed in the Hyperterminal window and the LED will blink Green

Committer:
GregC
Date:
Mon Aug 15 23:33:04 2016 +0000
Revision:
1:d26e406e92f9
Parent:
0:b0767be19223
Gyroscope program example for Hexiwear

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:b0767be19223 1 #include "mbed.h"
maclobdell 0:b0767be19223 2 #include "FXAS21002.h"
maclobdell 0:b0767be19223 3
maclobdell 0:b0767be19223 4 /* Check out the full featured example application for interfacing to the
maclobdell 0:b0767be19223 5 * Gyro device at the following URL
maclobdell 0:b0767be19223 6 * https://developer.mbed.org/teams/ATT-Hackathon/code/Accel_Mag_Gyro_SensorStream_K64F_AGM01_M/
maclobdell 0:b0767be19223 7 */
maclobdell 0:b0767be19223 8
GregC 1:d26e406e92f9 9 DigitalOut led1(LED_GREEN);
GregC 1:d26e406e92f9 10 Serial pc(USBTX, USBRX);
maclobdell 0:b0767be19223 11
maclobdell 0:b0767be19223 12 // Pin connections for Hexiwear
maclobdell 0:b0767be19223 13 FXAS21002 gyro(PTC11,PTC10);
maclobdell 0:b0767be19223 14 // Storage for the data from the sensor
maclobdell 0:b0767be19223 15 float gyro_data[3]; float gyro_rms=0.0;
maclobdell 0:b0767be19223 16
maclobdell 0:b0767be19223 17
maclobdell 0:b0767be19223 18 // main() runs in its own thread in the OS
maclobdell 0:b0767be19223 19 // (note the calls to Thread::wait below for delays)
maclobdell 0:b0767be19223 20 int main() {
maclobdell 0:b0767be19223 21
maclobdell 0:b0767be19223 22 gyro.gyro_config();
maclobdell 0:b0767be19223 23 while (true) {
maclobdell 0:b0767be19223 24
maclobdell 0:b0767be19223 25 gyro.acquire_gyro_data_dps(gyro_data);
GregC 1:d26e406e92f9 26 pc.printf("Roll (G) %4.2f,\t Pitch (G) %4.2f,\t Yaw (G) %4.2f\r\n",gyro_data[0],gyro_data[1],gyro_data[2]);
maclobdell 0:b0767be19223 27 gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
GregC 1:d26e406e92f9 28 pc.printf("Gyroscope RMS %f \r\n\n",gyro_rms);
maclobdell 0:b0767be19223 29
maclobdell 0:b0767be19223 30 led1 = !led1;
maclobdell 0:b0767be19223 31 Thread::wait(1000);
maclobdell 0:b0767be19223 32 }
maclobdell 0:b0767be19223 33 }
maclobdell 0:b0767be19223 34