FRDM-FXS-MULTI2-B-Stream sensor data using FRDM-KL25Z
Dependencies: FXOS8700_FXAS21002 mbed MAG3110 MMA8652FC MPL3115A2
Fork of FRDM-FXS-MULTI2-B_SensorShield_HelloWorld by
main.cpp
00001 /* 00002 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 00003 * Copyright 2016-2017 NXP 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * o Redistributions of source code must retain the above copyright notice, this list 00009 * of conditions and the following disclaimer. 00010 * 00011 * o Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * o Neither the name of the copyright holder nor the names of its 00016 * contributors may be used to endorse or promote products derived from this 00017 * software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 #include "FXAS21002.h" 00031 #include "FXOS8700.h" 00032 #include "MAG3110.h" 00033 #include "MMA8652.h" 00034 #include "MPL3115.h" 00035 #include "mbed.h" 00036 00037 // Initialize Serial port 00038 Serial pc(USBTX, USBRX); 00039 00040 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly. 00041 FXOS8700 accel(D14,D15); 00042 FXOS8700 mag(D14,D15); 00043 FXAS21002 gyro(D14,D15); 00044 MAG3110 mag3110(D14,D15); 00045 MMA8652 mma8652(D14,D15); 00046 MPL3115 mpl3115(D14,D15); 00047 00048 00049 00050 int main() 00051 { 00052 00053 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002 00054 accel.accel_config(); 00055 mag.mag_config(); 00056 gyro.gyro_config(); 00057 mag3110.MAG3110_config(); 00058 mma8652.MMA8652_config(); 00059 mpl3115.MPL3115_config(); 00060 00061 00062 float accel_data[3]; float accel_rms=0.0; 00063 float mag_data[3]; float mag_rms=0.0; 00064 float gyro_data[3]; float gyro_rms=0.0; 00065 float alt_data[3]; float alt_rms=0.0; 00066 00067 printf("Begin Data Acquisition....\r\n\r\n"); 00068 wait(0.5); 00069 00070 while(1) 00071 { 00072 accel.acquire_accel_data_g(accel_data); 00073 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); 00074 printf("%4.2f,%4.2f,%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]); 00075 wait(0.005); 00076 00077 // mma8652.acquire_MMA8652_data_g(accel_data); 00078 // accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); 00079 // printf("%4.2f,%4.2f,%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]); 00080 // wait(0.005); 00081 00082 // mag.acquire_mag_data_uT(mag_data); 00083 // printf("%4.2f,\t%4.2f,\t%4.2f,\t",mag_data[0],mag_data[1],mag_data[2]); 00084 // mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); 00085 // wait(0.005); 00086 00087 mag3110.acquire_MAG3110_data_uT(mag_data); 00088 printf("%f,%f,%f,\t",mag_data[0],mag_data[1],mag_data[2]); 00089 mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); 00090 wait(0.005); 00091 00092 gyro.acquire_gyro_data_dps(gyro_data); 00093 printf("%4.2f,%4.2f,%4.2f,",gyro_data[0],gyro_data[1],gyro_data[2]); 00094 gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3); 00095 wait(0.005); 00096 00097 mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data); 00098 printf("\t%f",alt_data[0]); 00099 alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3); 00100 wait(0.005); 00101 00102 printf("\n\r"); 00103 00104 00105 } 00106 00107 }
Generated on Wed Jul 13 2022 02:13:47 by 1.7.2