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@2:7eebb01e9954, 2016-06-14 (annotated)
- Committer:
- mwjanse
- Date:
- Tue Jun 14 14:54:20 2016 +0000
- Revision:
- 2:7eebb01e9954
- Parent:
- 1:50c76138a9be
Increased BAUD-rate to 115000 and enable form-feed to clear the screen: Enable this in your console application if needed.
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 | |
mwjanse | 2:7eebb01e9954 | 26 | |
AswinSivakumar | 0:ac1207304de6 | 27 | // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly. |
mwjanse | 1:50c76138a9be | 28 | FXOS8700 accel(PTE25,PTE24); |
mwjanse | 1:50c76138a9be | 29 | FXOS8700 mag(PTE25,PTE24); |
mwjanse | 1:50c76138a9be | 30 | FXAS21002 gyro(PTE25,PTE24); |
mwjanse | 1:50c76138a9be | 31 | MPL3115 mpl3115(PTE25,PTE24); |
AswinSivakumar | 0:ac1207304de6 | 32 | |
mwjanse | 1:50c76138a9be | 33 | //FXAS21002 gyro(PTC2,PTC1); |
mwjanse | 1:50c76138a9be | 34 | //MPL3115 mpl3115(PTC2,PTC1); |
AswinSivakumar | 0:ac1207304de6 | 35 | |
AswinSivakumar | 0:ac1207304de6 | 36 | |
AswinSivakumar | 0:ac1207304de6 | 37 | int main() |
AswinSivakumar | 0:ac1207304de6 | 38 | { |
mwjanse | 2:7eebb01e9954 | 39 | |
AswinSivakumar | 0:ac1207304de6 | 40 | |
AswinSivakumar | 0:ac1207304de6 | 41 | // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002 |
AswinSivakumar | 0:ac1207304de6 | 42 | accel.accel_config(); |
AswinSivakumar | 0:ac1207304de6 | 43 | mag.mag_config(); |
AswinSivakumar | 0:ac1207304de6 | 44 | gyro.gyro_config(); |
AswinSivakumar | 0:ac1207304de6 | 45 | mpl3115.MPL3115_config(); |
AswinSivakumar | 0:ac1207304de6 | 46 | |
mwjanse | 2:7eebb01e9954 | 47 | pc.baud(115200); |
AswinSivakumar | 0:ac1207304de6 | 48 | |
mwjanse | 1:50c76138a9be | 49 | float accel_data[3]; |
mwjanse | 1:50c76138a9be | 50 | float accel_rms=0.0; |
mwjanse | 1:50c76138a9be | 51 | float mag_data[3]; |
mwjanse | 1:50c76138a9be | 52 | float mag_rms=0.0; |
mwjanse | 1:50c76138a9be | 53 | float gyro_data[3]; |
mwjanse | 1:50c76138a9be | 54 | float gyro_rms=0.0; |
mwjanse | 1:50c76138a9be | 55 | float alt_data[3]; |
mwjanse | 1:50c76138a9be | 56 | float alt_rms=0.0; |
AswinSivakumar | 0:ac1207304de6 | 57 | |
AswinSivakumar | 0:ac1207304de6 | 58 | printf("Begin Data Acquisition....\r\n\r\n"); |
mwjanse | 1:50c76138a9be | 59 | wait(5.0); |
AswinSivakumar | 0:ac1207304de6 | 60 | |
AswinSivakumar | 0:ac1207304de6 | 61 | while(1) |
AswinSivakumar | 0:ac1207304de6 | 62 | { |
AswinSivakumar | 0:ac1207304de6 | 63 | accel.acquire_accel_data_g(accel_data); |
AswinSivakumar | 0:ac1207304de6 | 64 | accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); |
mwjanse | 2:7eebb01e9954 | 65 | printf("Accelleration readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n",accel_data[0],accel_data[1],accel_data[2]); |
mwjanse | 2:7eebb01e9954 | 66 | printf("Accelleration RMS: %4.2f\n",accel_rms); |
AswinSivakumar | 0:ac1207304de6 | 67 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 68 | |
AswinSivakumar | 0:ac1207304de6 | 69 | mag.acquire_mag_data_uT(mag_data); |
mwjanse | 2:7eebb01e9954 | 70 | printf("Magnetics readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n",mag_data[0],mag_data[1],mag_data[2]); |
AswinSivakumar | 0:ac1207304de6 | 71 | mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); |
mwjanse | 2:7eebb01e9954 | 72 | printf("Magnetic RMS: %4.2f\n",mag_rms); |
AswinSivakumar | 0:ac1207304de6 | 73 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 74 | |
AswinSivakumar | 0:ac1207304de6 | 75 | |
AswinSivakumar | 0:ac1207304de6 | 76 | gyro.acquire_gyro_data_dps(gyro_data); |
mwjanse | 2:7eebb01e9954 | 77 | printf("Gyroscope readings: X:%4.2f, Y:%4.2f, Z:%4.2f\n",gyro_data[0],gyro_data[1],gyro_data[2]); |
AswinSivakumar | 0:ac1207304de6 | 78 | gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3); |
mwjanse | 2:7eebb01e9954 | 79 | printf("Gyroscopic RMS: %4.2f\n",gyro_rms); |
AswinSivakumar | 0:ac1207304de6 | 80 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 81 | |
AswinSivakumar | 0:ac1207304de6 | 82 | mpl3115.acquire_MPL3115_data_Altitude_in_m(alt_data); |
mwjanse | 2:7eebb01e9954 | 83 | printf("Altitude: \t%f\n",alt_data[0]); |
AswinSivakumar | 0:ac1207304de6 | 84 | alt_rms = sqrt(((alt_data[0]*alt_data[0])+(alt_data[1]*alt_data[1])+(alt_data[2]*alt_data[2]))/3); |
mwjanse | 2:7eebb01e9954 | 85 | printf("Altitude RMS: %4.2f\n",alt_rms); |
AswinSivakumar | 0:ac1207304de6 | 86 | wait(0.005); |
AswinSivakumar | 0:ac1207304de6 | 87 | |
mwjanse | 2:7eebb01e9954 | 88 | printf("\f"); |
mwjanse | 2:7eebb01e9954 | 89 | //printf("\033[2J"); |
mwjanse | 2:7eebb01e9954 | 90 | wait(0.1); |
AswinSivakumar | 0:ac1207304de6 | 91 | |
AswinSivakumar | 0:ac1207304de6 | 92 | |
AswinSivakumar | 0:ac1207304de6 | 93 | } |
AswinSivakumar | 0:ac1207304de6 | 94 | |
AswinSivakumar | 0:ac1207304de6 | 95 | } |