Sensors sample code , Sample Acc gyro at 200 hz
Dependencies: X_NUCLEO_IKS01A1_Local mbed
Fork of HelloWorld_IKS01A1 by
main.cpp@12:73fd70c4e857, 2017-05-21 (annotated)
- Committer:
- Arkadi
- Date:
- Sun May 21 13:01:32 2017 +0000
- Revision:
- 12:73fd70c4e857
- Parent:
- 11:4a99e73b88cc
Local changes to increase sample rate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
0:c71c9af137dd | 1 | /** |
Wolfgang Betz |
0:c71c9af137dd | 2 | ****************************************************************************** |
Wolfgang Betz |
0:c71c9af137dd | 3 | * @file main.cpp |
Wolfgang Betz |
0:c71c9af137dd | 4 | * @author AST / EST |
Wolfgang Betz |
0:c71c9af137dd | 5 | * @version V0.0.1 |
Wolfgang Betz |
0:c71c9af137dd | 6 | * @date 14-August-2015 |
Arkadi | 11:4a99e73b88cc | 7 | * @brief Simple Example application for using the X_NUCLEO_IKS01A1 |
Wolfgang Betz |
0:c71c9af137dd | 8 | * MEMS Inertial & Environmental Sensor Nucleo expansion board. |
Wolfgang Betz |
0:c71c9af137dd | 9 | ****************************************************************************** |
Wolfgang Betz |
0:c71c9af137dd | 10 | * @attention |
Wolfgang Betz |
0:c71c9af137dd | 11 | * |
Wolfgang Betz |
0:c71c9af137dd | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
Wolfgang Betz |
0:c71c9af137dd | 13 | * |
Wolfgang Betz |
0:c71c9af137dd | 14 | * Redistribution and use in source and binary forms, with or without modification, |
Wolfgang Betz |
0:c71c9af137dd | 15 | * are permitted provided that the following conditions are met: |
Wolfgang Betz |
0:c71c9af137dd | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
Wolfgang Betz |
0:c71c9af137dd | 17 | * this list of conditions and the following disclaimer. |
Wolfgang Betz |
0:c71c9af137dd | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Wolfgang Betz |
0:c71c9af137dd | 19 | * this list of conditions and the following disclaimer in the documentation |
Wolfgang Betz |
0:c71c9af137dd | 20 | * and/or other materials provided with the distribution. |
Wolfgang Betz |
0:c71c9af137dd | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Wolfgang Betz |
0:c71c9af137dd | 22 | * may be used to endorse or promote products derived from this software |
Wolfgang Betz |
0:c71c9af137dd | 23 | * without specific prior written permission. |
Wolfgang Betz |
0:c71c9af137dd | 24 | * |
Wolfgang Betz |
0:c71c9af137dd | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Wolfgang Betz |
0:c71c9af137dd | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Wolfgang Betz |
0:c71c9af137dd | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Wolfgang Betz |
0:c71c9af137dd | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Wolfgang Betz |
0:c71c9af137dd | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Wolfgang Betz |
0:c71c9af137dd | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Wolfgang Betz |
0:c71c9af137dd | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Wolfgang Betz |
0:c71c9af137dd | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Wolfgang Betz |
0:c71c9af137dd | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Wolfgang Betz |
0:c71c9af137dd | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wolfgang Betz |
0:c71c9af137dd | 35 | * |
Wolfgang Betz |
0:c71c9af137dd | 36 | ****************************************************************************** |
Arkadi | 11:4a99e73b88cc | 37 | */ |
Wolfgang Betz |
0:c71c9af137dd | 38 | |
Wolfgang Betz |
0:c71c9af137dd | 39 | /* Includes */ |
Wolfgang Betz |
0:c71c9af137dd | 40 | #include "mbed.h" |
Wolfgang Betz |
0:c71c9af137dd | 41 | #include "x_nucleo_iks01a1.h" |
Wolfgang Betz |
0:c71c9af137dd | 42 | |
Arkadi | 11:4a99e73b88cc | 43 | // define sample frequency |
Arkadi | 11:4a99e73b88cc | 44 | #define SAMPLES_DELAY 5000 |
Wolfgang Betz |
0:c71c9af137dd | 45 | /* Instantiate the expansion board */ |
Wolfgang Betz |
4:b1526d074d83 | 46 | static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15); |
Wolfgang Betz |
0:c71c9af137dd | 47 | |
Wolfgang Betz |
0:c71c9af137dd | 48 | /* Retrieve the composing elements of the expansion board */ |
Wolfgang Betz |
0:c71c9af137dd | 49 | static GyroSensor *gyroscope = mems_expansion_board->GetGyroscope(); |
Wolfgang Betz |
0:c71c9af137dd | 50 | static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer(); |
Arkadi | 11:4a99e73b88cc | 51 | |
Arkadi | 11:4a99e73b88cc | 52 | // sensor sample rate: x_nucleo_iks01a1.cpp ; lsm6ds0_class.cpp |
Wolfgang Betz |
0:c71c9af137dd | 53 | |
Wolfgang Betz |
0:c71c9af137dd | 54 | |
Arkadi | 11:4a99e73b88cc | 55 | // define uart |
Arkadi | 11:4a99e73b88cc | 56 | Serial pc(USBTX, USBRX); |
Wolfgang Betz |
0:c71c9af137dd | 57 | |
Arkadi | 11:4a99e73b88cc | 58 | // timer object |
Arkadi | 11:4a99e73b88cc | 59 | Timer timer; |
Wolfgang Betz |
0:c71c9af137dd | 60 | |
Arkadi | 11:4a99e73b88cc | 61 | // send data |
Arkadi | 11:4a99e73b88cc | 62 | bool flagData=0; |
Wolfgang Betz |
0:c71c9af137dd | 63 | |
Arkadi | 11:4a99e73b88cc | 64 | // time stamp |
Arkadi | 11:4a99e73b88cc | 65 | int timeStamp_us=0; |
Arkadi | 11:4a99e73b88cc | 66 | int sampleStamp=0; |
Wolfgang Betz |
0:c71c9af137dd | 67 | |
Wolfgang Betz |
0:c71c9af137dd | 68 | /* Simple main function */ |
Arkadi | 11:4a99e73b88cc | 69 | int main() |
Arkadi | 11:4a99e73b88cc | 70 | { |
Arkadi | 11:4a99e73b88cc | 71 | pc.baud(921600); |
Arkadi | 11:4a99e73b88cc | 72 | timer.start(); |
Arkadi | 11:4a99e73b88cc | 73 | timeStamp_us = timer.read_us(); |
Arkadi | 11:4a99e73b88cc | 74 | uint8_t id; |
Arkadi | 11:4a99e73b88cc | 75 | int32_t Acc_axes[3]; |
Arkadi | 11:4a99e73b88cc | 76 | int32_t Gyro_axes[3]; |
Wolfgang Betz |
0:c71c9af137dd | 77 | |
Arkadi | 11:4a99e73b88cc | 78 | pc.printf("\r\n--- Starting new run ---\r\n"); |
Arkadi | 11:4a99e73b88cc | 79 | |
Arkadi | 11:4a99e73b88cc | 80 | gyroscope->read_id(&id); |
Arkadi | 11:4a99e73b88cc | 81 | pc.printf("LSM6DS0 accelerometer & gyroscope = 0x%X\r\n", id); |
Arkadi | 11:4a99e73b88cc | 82 | |
Arkadi | 11:4a99e73b88cc | 83 | wait(0.5); |
Wolfgang Betz |
0:c71c9af137dd | 84 | |
Arkadi | 11:4a99e73b88cc | 85 | while(1) { |
Arkadi | 11:4a99e73b88cc | 86 | // get time stamp |
Arkadi | 11:4a99e73b88cc | 87 | timeStamp_us = timer.read_us(); |
Arkadi | 11:4a99e73b88cc | 88 | // sample delay |
Arkadi | 11:4a99e73b88cc | 89 | if ((timeStamp_us-sampleStamp)>SAMPLES_DELAY) { |
Arkadi | 11:4a99e73b88cc | 90 | sampleStamp=timeStamp_us; |
Arkadi | 11:4a99e73b88cc | 91 | // get raw data |
Arkadi | 11:4a99e73b88cc | 92 | accelerometer->get_x_axes(Acc_axes); |
Arkadi | 11:4a99e73b88cc | 93 | gyroscope->get_g_axes(Gyro_axes); |
Arkadi | 11:4a99e73b88cc | 94 | pc.printf("D:%7ld,%7ld,%7ld,%7ld,%7ld,%7ld,%7ld\r\n", sampleStamp, Acc_axes[0], Acc_axes[1], Acc_axes[2], Gyro_axes[0], Gyro_axes[1], Gyro_axes[2]); |
Arkadi | 11:4a99e73b88cc | 95 | //pc.printf("D:%7ld,%7ld,%7ld,%7ld\r\n", sampleStamp, Acc_axes[0], Acc_axes[1], Acc_axes[2]); |
Arkadi | 11:4a99e73b88cc | 96 | // stability delay to finish sending data |
Arkadi | 11:4a99e73b88cc | 97 | //wait_us(10); |
Arkadi | 11:4a99e73b88cc | 98 | }// end get & send samples |
Wolfgang Betz |
0:c71c9af137dd | 99 | |
Arkadi | 11:4a99e73b88cc | 100 | }// end loop |
Arkadi | 11:4a99e73b88cc | 101 | }// end main |