Marco Merlin / Mbed OS rIoTwear-sensorstream

Dependencies:   FXOS8700 FXAS21002 MPL3115A2

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 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
00027 //    I2C_SCL = PTC10,  I2C_SDA = PTC11,
00028 FXOS8700  accel(I2C_SDA , I2C_SCL );
00029 FXOS8700    mag(I2C_SDA , I2C_SCL );
00030 FXAS21002  gyro(I2C_SDA , I2C_SCL );
00031 MPL3115 mpl3115(I2C_SDA , I2C_SCL );
00032 
00033 #define SHORT_WAIT 0.1
00034 #define LONG_WAIT  1.0
00035      
00036 int main()
00037 {     
00038  
00039 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
00040     accel.accel_config();
00041     mag.mag_config();
00042     gyro.gyro_config();
00043     mpl3115.MPL3115_config();
00044  
00045     //pc.baud(115200);
00046     
00047     float accel_data[3];
00048     float accel_rms=0.0;
00049     float mag_data[3];
00050     float mag_rms=0.0;
00051     float gyro_data[3];
00052     float gyro_rms=0.0;
00053     float alt_data[3];
00054     float alt_rms=0.0;
00055        
00056     printf("\n\rBegin Data Acquisition....\n\r");
00057     wait(5.0);    
00058     
00059     while(1)
00060     {
00061       accel.acquire_accel_data_g(accel_data);
00062       wait(SHORT_WAIT);
00063       printf("Accelleration: X:%4.2f, Y:%4.2f, Z:%4.2f\n\r",accel_data[0],accel_data[1],accel_data[2]);
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("\n\rAccelleration RMS: %4.2f\n\r",accel_rms);
00066 
00067       mag.acquire_mag_data_uT(mag_data);
00068       printf("Magnetics readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n\r",mag_data[0],mag_data[1],mag_data[2]);
00069       mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
00070       printf("Magnetic RMS: %4.2f\n\r",mag_rms);
00071       wait(SHORT_WAIT);
00072       
00073       gyro.acquire_gyro_data_dps(gyro_data);
00074       printf("Gyroscope readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n\r",gyro_data[0],gyro_data[1],gyro_data[2]);
00075       gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
00076       printf("Gyroscopic RMS: %4.2f\n\r",gyro_rms);
00077       wait(SHORT_WAIT);
00078       
00079       mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data);
00080       printf("Altitude: \t%f\n\r",alt_data[0]);
00081       alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3);
00082       printf("Altitude RMS: %4.2f\n\r",alt_rms);
00083       wait(SHORT_WAIT);
00084 
00085       wait(LONG_WAIT);
00086          
00087      }
00088       
00089 }