FRDM-STBC-AG01 sensor board with MultiTech Dragonfly

Dependencies:   FXAS21002 FXOS8700 mbed-rtos mbed

Fork of Accel_Mag_Gyro_SensorStream_K64F_AGM01_M by NXP

Committer:
BlueShadow
Date:
Tue Aug 16 23:43:27 2016 +0000
Revision:
3:e779546f1e1b
Parent:
2:6a7a8f0af87c
Dragonfly using FRDM-STBC-AG01 sensor board with FXAS21002 and FSOS8700.  Forked from NXP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BlueShadow 2:6a7a8f0af87c 1 /* Copyright (c) 2015 NXP Semiconductors. MIT License
AswinSivakumar 0:4fd1b0bd1594 2 *
AswinSivakumar 0:4fd1b0bd1594 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
AswinSivakumar 0:4fd1b0bd1594 4 * and associated documentation files (the "Software"), to deal in the Software without
AswinSivakumar 0:4fd1b0bd1594 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
AswinSivakumar 0:4fd1b0bd1594 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
AswinSivakumar 0:4fd1b0bd1594 7 * Software is furnished to do so, subject to the following conditions:
AswinSivakumar 0:4fd1b0bd1594 8 *
AswinSivakumar 0:4fd1b0bd1594 9 * The above copyright notice and this permission notice shall be included in all copies or
AswinSivakumar 0:4fd1b0bd1594 10 * substantial portions of the Software.
AswinSivakumar 0:4fd1b0bd1594 11 *
AswinSivakumar 0:4fd1b0bd1594 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
AswinSivakumar 0:4fd1b0bd1594 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
AswinSivakumar 0:4fd1b0bd1594 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
AswinSivakumar 0:4fd1b0bd1594 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AswinSivakumar 0:4fd1b0bd1594 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BlueShadow 1:f41fb323b392 17
BlueShadow 2:6a7a8f0af87c 18 * 8/12/2016 I will be making mistakes in this code.
BlueShadow 2:6a7a8f0af87c 19 * 8/15/2016 I2C bus in the code is on D14/D15 Arduino Pinout. FRDM-STBD-AGM01 board is jumpered
BlueShadow 3:e779546f1e1b 20 * to use the wrong pins vs the code. Move the Jumpers from I2C-SCL1 to 0 and I2C-SDA1 to 0
AswinSivakumar 0:4fd1b0bd1594 21 */
AswinSivakumar 0:4fd1b0bd1594 22 #include "FXAS21002.h"
BlueShadow 2:6a7a8f0af87c 23 #include "FXOS8700.h"
AswinSivakumar 0:4fd1b0bd1594 24 #include "mbed.h"
AswinSivakumar 0:4fd1b0bd1594 25
AswinSivakumar 0:4fd1b0bd1594 26 // Initialize Serial port
BlueShadow 2:6a7a8f0af87c 27 Serial pc(USBTX, USBRX);
BlueShadow 2:6a7a8f0af87c 28 int pc_baud = 115200;
AswinSivakumar 0:4fd1b0bd1594 29
AswinSivakumar 0:4fd1b0bd1594 30 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
AswinSivakumar 0:4fd1b0bd1594 31 FXOS8700 accel(D14,D15);
AswinSivakumar 0:4fd1b0bd1594 32 FXOS8700 mag(D14,D15);
AswinSivakumar 0:4fd1b0bd1594 33 FXAS21002 gyro(D14,D15);
AswinSivakumar 0:4fd1b0bd1594 34
AswinSivakumar 0:4fd1b0bd1594 35 // Set Sensor Stream details
AswinSivakumar 0:4fd1b0bd1594 36 char streamAcc[] = "acc_rms"; // Stream you want to push to
AswinSivakumar 0:4fd1b0bd1594 37 char streamMag[] = "mag_rms"; // Stream you want to push to
AswinSivakumar 0:4fd1b0bd1594 38 char streamGyr[] = "gyr_rms"; // Stream you want to push to
AswinSivakumar 0:4fd1b0bd1594 39
AswinSivakumar 0:4fd1b0bd1594 40 int main()
AswinSivakumar 0:4fd1b0bd1594 41 {
BlueShadow 2:6a7a8f0af87c 42 pc.baud(pc_baud);
BlueShadow 2:6a7a8f0af87c 43
AswinSivakumar 0:4fd1b0bd1594 44 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
AswinSivakumar 0:4fd1b0bd1594 45 accel.accel_config();
AswinSivakumar 0:4fd1b0bd1594 46 mag.mag_config();
AswinSivakumar 0:4fd1b0bd1594 47 gyro.gyro_config();
AswinSivakumar 0:4fd1b0bd1594 48
BlueShadow 2:6a7a8f0af87c 49 float accel_data[3];
BlueShadow 2:6a7a8f0af87c 50 float accel_rms=0.0;
BlueShadow 2:6a7a8f0af87c 51 float mag_data[3];
BlueShadow 2:6a7a8f0af87c 52 float mag_rms=0.0;
BlueShadow 2:6a7a8f0af87c 53 float gyro_data[3];
BlueShadow 2:6a7a8f0af87c 54 float gyro_rms=0.0;
BlueShadow 2:6a7a8f0af87c 55
AswinSivakumar 0:4fd1b0bd1594 56 printf("Begin Data Acquisition from FXOS8700 and FXAS21002....\r\n\r\n");
AswinSivakumar 0:4fd1b0bd1594 57 wait(0.5);
BlueShadow 2:6a7a8f0af87c 58
BlueShadow 2:6a7a8f0af87c 59 while(1) {
BlueShadow 2:6a7a8f0af87c 60 accel.acquire_accel_data_g(accel_data);
BlueShadow 2:6a7a8f0af87c 61 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
BlueShadow 2:6a7a8f0af87c 62 printf("accel %4.2f,\t%4.2f,\t%4.2f,\t\n",accel_data[0],accel_data[1],accel_data[2]);
BlueShadow 2:6a7a8f0af87c 63 wait(0.01);
BlueShadow 2:6a7a8f0af87c 64
BlueShadow 2:6a7a8f0af87c 65 mag.acquire_mag_data_uT(mag_data);
BlueShadow 2:6a7a8f0af87c 66 printf("mag %4.2f,\t%4.2f,\t%4.2f,\t\n",mag_data[0],mag_data[1],mag_data[2]);
BlueShadow 2:6a7a8f0af87c 67 mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
BlueShadow 2:6a7a8f0af87c 68 wait(0.01);
BlueShadow 2:6a7a8f0af87c 69
BlueShadow 2:6a7a8f0af87c 70 gyro.acquire_gyro_data_dps(gyro_data);
BlueShadow 2:6a7a8f0af87c 71 printf("gyro %4.2f,\t%4.2f,\t%4.2f\r\n",gyro_data[0],gyro_data[1],gyro_data[2]);
BlueShadow 2:6a7a8f0af87c 72 gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
BlueShadow 2:6a7a8f0af87c 73 wait(0.01);
BlueShadow 2:6a7a8f0af87c 74
BlueShadow 2:6a7a8f0af87c 75 printf("\r\nAccelerometer shock %f\r\n", accel_rms);
BlueShadow 2:6a7a8f0af87c 76 printf("Magnitometer max value vs 1.0 %f\r\n", mag_rms);
BlueShadow 2:6a7a8f0af87c 77 printf("Gyro RMS %f\r\n\n", gyro_rms);
BlueShadow 2:6a7a8f0af87c 78 wait(1);
AswinSivakumar 0:4fd1b0bd1594 79 }
BlueShadow 2:6a7a8f0af87c 80
AswinSivakumar 0:4fd1b0bd1594 81 }