Marnix Janse / Mbed 2 deprecated FRDM-STBC-AGMP01_SensorStream

Dependencies:   FXAS21002 FXOS8700 MPL3115A2 mbed

Fork of RD-KL25Z-AGMP01_SensorStream by NXP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001  /* Copyright (c) 2015 NXP Semiconductors. MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018 #include "FXAS21002.h"
00019 #include "FXOS8700.h"  
00020 #include "MPL3115.h" 
00021 #include "mbed.h"
00022 
00023 // Initialize Serial port
00024 Serial pc(USBTX, USBRX);
00025 
00026 
00027 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
00028 FXOS8700 accel(PTE25,PTE24);
00029 FXOS8700 mag(PTE25,PTE24);
00030 FXAS21002 gyro(PTE25,PTE24);
00031 MPL3115 mpl3115(PTE25,PTE24);
00032 
00033 //FXAS21002 gyro(PTC2,PTC1);
00034 //MPL3115 mpl3115(PTC2,PTC1);
00035 
00036     
00037 int main()
00038 {
00039      
00040 
00041 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
00042     accel.accel_config();
00043     mag.mag_config();
00044     gyro.gyro_config();
00045     mpl3115.MPL3115_config();
00046  
00047     pc.baud(115200);
00048     
00049     float accel_data[3];
00050     float accel_rms=0.0;
00051     float mag_data[3];
00052     float mag_rms=0.0;
00053     float gyro_data[3];
00054     float gyro_rms=0.0;
00055     float alt_data[3];
00056     float alt_rms=0.0;
00057        
00058     printf("Begin Data Acquisition....\r\n\r\n");
00059     wait(5.0);
00060     
00061     while(1)
00062     {
00063       accel.acquire_accel_data_g(accel_data);
00064       accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
00065       printf("Accelleration readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n",accel_data[0],accel_data[1],accel_data[2]);
00066       printf("Accelleration RMS: %4.2f\n",accel_rms);
00067       wait(0.005);
00068          
00069       mag.acquire_mag_data_uT(mag_data);
00070       printf("Magnetics readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n",mag_data[0],mag_data[1],mag_data[2]);
00071       mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
00072       printf("Magnetic RMS: %4.2f\n",mag_rms);
00073       wait(0.005);
00074 
00075      
00076       gyro.acquire_gyro_data_dps(gyro_data);
00077       printf("Gyroscope readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n",gyro_data[0],gyro_data[1],gyro_data[2]);
00078       gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
00079       printf("Gyroscopic RMS: %4.2f\n",gyro_rms);
00080       wait(0.005);
00081       
00082       mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data);
00083       printf("Altitude: \t%f\n",alt_data[0]);
00084       alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3);
00085       printf("Altitude RMS: %4.2f\n",alt_rms);
00086       wait(0.005);
00087       
00088       printf("\f");
00089       //printf("\033[2J");
00090       wait(0.1);
00091    
00092       
00093      }
00094       
00095 }