k
Dependencies: mbed FXOS8700 FXAS21002 MPL3115A2
main.cpp@3:04bf20362085, 2021-07-30 (annotated)
- Committer:
- sbk
- Date:
- Fri Jul 30 11:17:50 2021 +0000
- Revision:
- 3:04bf20362085
- Parent:
- 2:eaf68a908096
l
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AswinSivakumar | 1:835b21f32a6e | 1 | /* |
AswinSivakumar | 1:835b21f32a6e | 2 | * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. |
AswinSivakumar | 1:835b21f32a6e | 3 | * Copyright 2016-2017 NXP |
AswinSivakumar | 1:835b21f32a6e | 4 | * |
AswinSivakumar | 1:835b21f32a6e | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AswinSivakumar | 1:835b21f32a6e | 6 | * are permitted provided that the following conditions are met: |
AswinSivakumar | 1:835b21f32a6e | 7 | * |
AswinSivakumar | 1:835b21f32a6e | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
AswinSivakumar | 1:835b21f32a6e | 9 | * of conditions and the following disclaimer. |
AswinSivakumar | 1:835b21f32a6e | 10 | * |
AswinSivakumar | 1:835b21f32a6e | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
AswinSivakumar | 1:835b21f32a6e | 12 | * list of conditions and the following disclaimer in the documentation and/or |
AswinSivakumar | 1:835b21f32a6e | 13 | * other materials provided with the distribution. |
AswinSivakumar | 1:835b21f32a6e | 14 | * |
AswinSivakumar | 1:835b21f32a6e | 15 | * o Neither the name of the copyright holder nor the names of its |
AswinSivakumar | 1:835b21f32a6e | 16 | * contributors may be used to endorse or promote products derived from this |
AswinSivakumar | 1:835b21f32a6e | 17 | * software without specific prior written permission. |
AswinSivakumar | 1:835b21f32a6e | 18 | * |
AswinSivakumar | 1:835b21f32a6e | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AswinSivakumar | 1:835b21f32a6e | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AswinSivakumar | 1:835b21f32a6e | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AswinSivakumar | 1:835b21f32a6e | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AswinSivakumar | 1:835b21f32a6e | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AswinSivakumar | 1:835b21f32a6e | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AswinSivakumar | 1:835b21f32a6e | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AswinSivakumar | 1:835b21f32a6e | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AswinSivakumar | 1:835b21f32a6e | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AswinSivakumar | 1:835b21f32a6e | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AswinSivakumar | 1:835b21f32a6e | 29 | */ |
AswinSivakumar | 0:ac1207304de6 | 30 | #include "FXAS21002.h" |
AswinSivakumar | 0:ac1207304de6 | 31 | #include "FXOS8700.h" |
AswinSivakumar | 0:ac1207304de6 | 32 | #include "MPL3115.h" |
AswinSivakumar | 0:ac1207304de6 | 33 | #include "mbed.h" |
AswinSivakumar | 0:ac1207304de6 | 34 | |
AswinSivakumar | 0:ac1207304de6 | 35 | // Initialize Serial port |
AswinSivakumar | 0:ac1207304de6 | 36 | Serial pc(USBTX, USBRX); |
AswinSivakumar | 0:ac1207304de6 | 37 | |
AswinSivakumar | 0:ac1207304de6 | 38 | // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly. |
AswinSivakumar | 0:ac1207304de6 | 39 | FXOS8700 accel(PTC2,PTC1); |
AswinSivakumar | 0:ac1207304de6 | 40 | FXOS8700 mag(PTC2,PTC1); |
ikorolev | 2:eaf68a908096 | 41 | FXAS21002 gyro(PTC2,PTC1,0x20); |
AswinSivakumar | 0:ac1207304de6 | 42 | MPL3115 mpl3115(PTC2,PTC1); |
AswinSivakumar | 0:ac1207304de6 | 43 | |
AswinSivakumar | 0:ac1207304de6 | 44 | |
AswinSivakumar | 0:ac1207304de6 | 45 | |
AswinSivakumar | 0:ac1207304de6 | 46 | int main() |
AswinSivakumar | 0:ac1207304de6 | 47 | { |
AswinSivakumar | 0:ac1207304de6 | 48 | |
AswinSivakumar | 0:ac1207304de6 | 49 | // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002 |
AswinSivakumar | 0:ac1207304de6 | 50 | accel.accel_config(); |
AswinSivakumar | 0:ac1207304de6 | 51 | mag.mag_config(); |
ikorolev | 2:eaf68a908096 | 52 | // gyro.gyro_config(); |
AswinSivakumar | 0:ac1207304de6 | 53 | mpl3115.MPL3115_config(); |
AswinSivakumar | 0:ac1207304de6 | 54 | |
AswinSivakumar | 0:ac1207304de6 | 55 | |
AswinSivakumar | 0:ac1207304de6 | 56 | float accel_data[3]; float accel_rms=0.0; |
AswinSivakumar | 0:ac1207304de6 | 57 | float mag_data[3]; float mag_rms=0.0; |
sbk | 3:04bf20362085 | 58 | int16_t gyro_data[3]; float gyro_rms=0.0; |
AswinSivakumar | 0:ac1207304de6 | 59 | float alt_data[3]; float alt_rms=0.0; |
sbk | 3:04bf20362085 | 60 | float temp_data[1]; |
sbk | 3:04bf20362085 | 61 | char data_bytes[7]; |
AswinSivakumar | 0:ac1207304de6 | 62 | printf("Begin Data Acquisition....\r\n\r\n"); |
AswinSivakumar | 0:ac1207304de6 | 63 | wait(0.5); |
AswinSivakumar | 0:ac1207304de6 | 64 | |
AswinSivakumar | 0:ac1207304de6 | 65 | while(1) |
AswinSivakumar | 0:ac1207304de6 | 66 | { |
AswinSivakumar | 0:ac1207304de6 | 67 | accel.acquire_accel_data_g(accel_data); |
AswinSivakumar | 0:ac1207304de6 | 68 | accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); |
sbk | 3:04bf20362085 | 69 | //printf("AccX:%4.2f,AccY:%4.2f,AccZ:%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]); |
sbk | 3:04bf20362085 | 70 | printf("%f,%f,%f,",accel_data[0],accel_data[1],accel_data[2]); |
sbk | 3:04bf20362085 | 71 | wait(0.01); |
AswinSivakumar | 0:ac1207304de6 | 72 | |
AswinSivakumar | 0:ac1207304de6 | 73 | |
AswinSivakumar | 0:ac1207304de6 | 74 | mag.acquire_mag_data_uT(mag_data); |
sbk | 3:04bf20362085 | 75 | //printf("MagX:%4.2f,MagY:%4.2f,MagZ:%4.2f,\t",mag_data[0],mag_data[1],mag_data[2]); |
sbk | 3:04bf20362085 | 76 | printf("%f,%f,%f,",mag_data[0],mag_data[1],mag_data[2]); |
AswinSivakumar | 0:ac1207304de6 | 77 | mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); |
sbk | 3:04bf20362085 | 78 | wait(0.01); |
AswinSivakumar | 0:ac1207304de6 | 79 | |
AswinSivakumar | 0:ac1207304de6 | 80 | |
sbk | 3:04bf20362085 | 81 | // gyro.acquire_gyro_data_dps(gyro_data); |
sbk | 3:04bf20362085 | 82 | //printf("GyrX:%d,GyrY:%d,GyrZ:%d,\t",gyro.getX(),gyro.getY(),gyro.getZ()); |
sbk | 3:04bf20362085 | 83 | printf("%d,%d,%d,",gyro.getX(),gyro.getY(),gyro.getZ()); |
sbk | 3:04bf20362085 | 84 | // gyro_rms = sqrt(((gyro.getX()*gyro.getX())+(gyro.getY()*gyro.getY())+(gyro.getZ()*gyro.getZ()))/3); |
sbk | 3:04bf20362085 | 85 | wait(0.01); |
AswinSivakumar | 0:ac1207304de6 | 86 | |
sbk | 3:04bf20362085 | 87 | mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data, temp_data, data_bytes); |
sbk | 3:04bf20362085 | 88 | // mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data); |
sbk | 3:04bf20362085 | 89 | // printf("Alt:%2f,\tTemp:%2f",alt_data[0],temp_data[0]); |
sbk | 3:04bf20362085 | 90 | printf("%2f,%2f",alt_data[0],temp_data[0]); |
sbk | 3:04bf20362085 | 91 | // printf("\nDatabytes:%s\n", data_bytes); |
sbk | 3:04bf20362085 | 92 | // printf("Alt:%f",alt_data[0]); |
AswinSivakumar | 0:ac1207304de6 | 93 | alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3); |
sbk | 3:04bf20362085 | 94 | wait(0.2); |
AswinSivakumar | 0:ac1207304de6 | 95 | |
AswinSivakumar | 0:ac1207304de6 | 96 | printf("\n\r"); |
AswinSivakumar | 0:ac1207304de6 | 97 | |
AswinSivakumar | 0:ac1207304de6 | 98 | |
AswinSivakumar | 0:ac1207304de6 | 99 | } |
AswinSivakumar | 0:ac1207304de6 | 100 | |
AswinSivakumar | 0:ac1207304de6 | 101 | } |