10 axis data logger to UART with NXP FRDM-K64F with FRDM-STBC-AGM01
Dependencies: FXAS21002 FXOS8700 MPL3115A2 mbed
Fork of RD-KL25Z-AGMP01_SensorStream by
main.cpp@1:50c76138a9be, 2016-06-14 (annotated)
- Committer:
- mwjanse
- Date:
- Tue Jun 14 14:21:45 2016 +0000
- Revision:
- 1:50c76138a9be
- Parent:
- 0:ac1207304de6
- Child:
- 2:7eebb01e9954
RMS measurement
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AswinSivakumar | 0:ac1207304de6 | 1 | /* Copyright (c) 2015 NXP Semiconductors. MIT License |
AswinSivakumar | 0:ac1207304de6 | 2 | * |
AswinSivakumar | 0:ac1207304de6 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
AswinSivakumar | 0:ac1207304de6 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
AswinSivakumar | 0:ac1207304de6 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
AswinSivakumar | 0:ac1207304de6 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
AswinSivakumar | 0:ac1207304de6 | 7 | * Software is furnished to do so, subject to the following conditions: |
AswinSivakumar | 0:ac1207304de6 | 8 | * |
AswinSivakumar | 0:ac1207304de6 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
AswinSivakumar | 0:ac1207304de6 | 10 | * substantial portions of the Software. |
AswinSivakumar | 0:ac1207304de6 | 11 | * |
AswinSivakumar | 0:ac1207304de6 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
AswinSivakumar | 0:ac1207304de6 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
AswinSivakumar | 0:ac1207304de6 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
AswinSivakumar | 0:ac1207304de6 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
AswinSivakumar | 0:ac1207304de6 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
AswinSivakumar | 0:ac1207304de6 | 17 | */ |
AswinSivakumar | 0:ac1207304de6 | 18 | #include "FXAS21002.h" |
AswinSivakumar | 0:ac1207304de6 | 19 | #include "FXOS8700.h" |
AswinSivakumar | 0:ac1207304de6 | 20 | #include "MPL3115.h" |
AswinSivakumar | 0:ac1207304de6 | 21 | #include "mbed.h" |
AswinSivakumar | 0:ac1207304de6 | 22 | |
AswinSivakumar | 0:ac1207304de6 | 23 | // Initialize Serial port |
AswinSivakumar | 0:ac1207304de6 | 24 | Serial pc(USBTX, USBRX); |
AswinSivakumar | 0:ac1207304de6 | 25 | |
AswinSivakumar | 0:ac1207304de6 | 26 | // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly. |
mwjanse | 1:50c76138a9be | 27 | FXOS8700 accel(PTE25,PTE24); |
mwjanse | 1:50c76138a9be | 28 | FXOS8700 mag(PTE25,PTE24); |
mwjanse | 1:50c76138a9be | 29 | FXAS21002 gyro(PTE25,PTE24); |
mwjanse | 1:50c76138a9be | 30 | MPL3115 mpl3115(PTE25,PTE24); |
AswinSivakumar | 0:ac1207304de6 | 31 | |
mwjanse | 1:50c76138a9be | 32 | //FXAS21002 gyro(PTC2,PTC1); |
mwjanse | 1:50c76138a9be | 33 | //MPL3115 mpl3115(PTC2,PTC1); |
AswinSivakumar | 0:ac1207304de6 | 34 | |
AswinSivakumar | 0:ac1207304de6 | 35 | |
AswinSivakumar | 0:ac1207304de6 | 36 | int main() |
AswinSivakumar | 0:ac1207304de6 | 37 | { |
AswinSivakumar | 0:ac1207304de6 | 38 | |
AswinSivakumar | 0:ac1207304de6 | 39 | // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002 |
AswinSivakumar | 0:ac1207304de6 | 40 | accel.accel_config(); |
AswinSivakumar | 0:ac1207304de6 | 41 | mag.mag_config(); |
AswinSivakumar | 0:ac1207304de6 | 42 | gyro.gyro_config(); |
AswinSivakumar | 0:ac1207304de6 | 43 | mpl3115.MPL3115_config(); |
AswinSivakumar | 0:ac1207304de6 | 44 | |
AswinSivakumar | 0:ac1207304de6 | 45 | |
mwjanse | 1:50c76138a9be | 46 | float accel_data[3]; |
mwjanse | 1:50c76138a9be | 47 | float accel_rms=0.0; |
mwjanse | 1:50c76138a9be | 48 | float mag_data[3]; |
mwjanse | 1:50c76138a9be | 49 | float mag_rms=0.0; |
mwjanse | 1:50c76138a9be | 50 | float gyro_data[3]; |
mwjanse | 1:50c76138a9be | 51 | float gyro_rms=0.0; |
mwjanse | 1:50c76138a9be | 52 | float alt_data[3]; |
mwjanse | 1:50c76138a9be | 53 | float alt_rms=0.0; |
AswinSivakumar | 0:ac1207304de6 | 54 | |
AswinSivakumar | 0:ac1207304de6 | 55 | printf("Begin Data Acquisition....\r\n\r\n"); |
mwjanse | 1:50c76138a9be | 56 | wait(5.0); |
AswinSivakumar | 0:ac1207304de6 | 57 | |
AswinSivakumar | 0:ac1207304de6 | 58 | while(1) |
AswinSivakumar | 0:ac1207304de6 | 59 | { |
AswinSivakumar | 0:ac1207304de6 | 60 | accel.acquire_accel_data_g(accel_data); |
AswinSivakumar | 0:ac1207304de6 | 61 | accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); |
mwjanse | 1:50c76138a9be | 62 | //printf("Accelleration: X:%4.2f, Y:%4.2f, Z:%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]); |
mwjanse | 1:50c76138a9be | 63 | printf("Accelleration RMS: %4.2f\t",accel_rms); |
AswinSivakumar | 0:ac1207304de6 | 64 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 65 | |
AswinSivakumar | 0:ac1207304de6 | 66 | |
AswinSivakumar | 0:ac1207304de6 | 67 | mag.acquire_mag_data_uT(mag_data); |
mwjanse | 1:50c76138a9be | 68 | //printf("Magnetics: X:%4.2f, Y:%4.2f, Z:%4.2f,\t",mag_data[0],mag_data[1],mag_data[2]); |
AswinSivakumar | 0:ac1207304de6 | 69 | mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); |
mwjanse | 1:50c76138a9be | 70 | printf("Magnetic RMS: %4.2f\t",mag_rms); |
AswinSivakumar | 0:ac1207304de6 | 71 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 72 | |
AswinSivakumar | 0:ac1207304de6 | 73 | |
AswinSivakumar | 0:ac1207304de6 | 74 | gyro.acquire_gyro_data_dps(gyro_data); |
mwjanse | 1:50c76138a9be | 75 | //printf("Gyroscope: X:%4.2f, Y:%4.2f, Z:%4.2f,",gyro_data[0],gyro_data[1],gyro_data[2]); |
AswinSivakumar | 0:ac1207304de6 | 76 | gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3); |
mwjanse | 1:50c76138a9be | 77 | printf("Gyroscopic RMS: %4.2f\t",gyro_rms); |
AswinSivakumar | 0:ac1207304de6 | 78 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 79 | |
AswinSivakumar | 0:ac1207304de6 | 80 | mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data); |
mwjanse | 1:50c76138a9be | 81 | //printf("Altitude: \t%f",alt_data[0]); |
AswinSivakumar | 0:ac1207304de6 | 82 | alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3); |
mwjanse | 1:50c76138a9be | 83 | printf("Altitude RMS: %4.2f\t",alt_rms); |
AswinSivakumar | 0:ac1207304de6 | 84 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 85 | |
AswinSivakumar | 0:ac1207304de6 | 86 | printf("\n\r"); |
mwjanse | 1:50c76138a9be | 87 | wait(1.0); |
AswinSivakumar | 0:ac1207304de6 | 88 | |
AswinSivakumar | 0:ac1207304de6 | 89 | |
AswinSivakumar | 0:ac1207304de6 | 90 | } |
AswinSivakumar | 0:ac1207304de6 | 91 | |
AswinSivakumar | 0:ac1207304de6 | 92 | } |