Baktha S / Mbed 2 deprecated payload_sensor

Dependencies:   mbed FXOS8700 FXAS21002 MPL3115A2

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 "MPL3115.h" 
00033 #include "mbed.h"
00034 
00035 // Initialize Serial port
00036 Serial pc(USBTX, USBRX);
00037 
00038 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
00039 FXOS8700 accel(PTC2,PTC1);
00040 FXOS8700 mag(PTC2,PTC1);
00041 FXAS21002 gyro(PTC2,PTC1,0x20);
00042 MPL3115 mpl3115(PTC2,PTC1);
00043 
00044 
00045     
00046 int main()
00047 {
00048 
00049 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
00050     accel.accel_config();
00051     mag.mag_config();
00052 //    gyro.gyro_config();
00053     mpl3115.MPL3115_config();
00054  
00055     
00056     float accel_data[3]; float accel_rms=0.0;
00057     float mag_data[3];   float mag_rms=0.0;
00058     int16_t gyro_data[3];  float gyro_rms=0.0;
00059     float alt_data[3];  float alt_rms=0.0;
00060     float temp_data[1]; 
00061     char data_bytes[7];
00062     printf("Begin Data Acquisition....\r\n\r\n");
00063     wait(0.5);
00064     
00065     while(1)
00066     {
00067       accel.acquire_accel_data_g(accel_data);
00068       accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
00069       //printf("AccX:%4.2f,AccY:%4.2f,AccZ:%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]);
00070       printf("%f,%f,%f,",accel_data[0],accel_data[1],accel_data[2]);
00071       wait(0.01);
00072       
00073          
00074       mag.acquire_mag_data_uT(mag_data);
00075       //printf("MagX:%4.2f,MagY:%4.2f,MagZ:%4.2f,\t",mag_data[0],mag_data[1],mag_data[2]);
00076       printf("%f,%f,%f,",mag_data[0],mag_data[1],mag_data[2]);
00077       mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
00078       wait(0.01);
00079 
00080      
00081 //      gyro.acquire_gyro_data_dps(gyro_data);
00082       //printf("GyrX:%d,GyrY:%d,GyrZ:%d,\t",gyro.getX(),gyro.getY(),gyro.getZ());
00083       printf("%d,%d,%d,",gyro.getX(),gyro.getY(),gyro.getZ());
00084 //      gyro_rms = sqrt(((gyro.getX()*gyro.getX())+(gyro.getY()*gyro.getY())+(gyro.getZ()*gyro.getZ()))/3);
00085       wait(0.01);
00086       
00087       mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data, temp_data, data_bytes);
00088 //      mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data);
00089      // printf("Alt:%2f,\tTemp:%2f",alt_data[0],temp_data[0]);
00090        printf("%2f,%2f",alt_data[0],temp_data[0]);
00091      // printf("\nDatabytes:%s\n", data_bytes);
00092 //      printf("Alt:%f",alt_data[0]);
00093       alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3);
00094       wait(0.2);
00095       
00096       printf("\n\r");
00097    
00098       
00099      }
00100       
00101 }