test
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of HelloWorld_IKS01A2 by
Revision 18:fde3070d9f93, committed 2018-07-24
- Comitter:
- uqureshi
- Date:
- Tue Jul 24 17:23:44 2018 +0000
- Parent:
- 17:175f561f1a71
- Commit message:
- save
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 175f561f1a71 -r fde3070d9f93 main.cpp --- a/main.cpp Wed Sep 27 15:48:21 2017 +0000 +++ b/main.cpp Tue Jul 24 17:23:44 2018 +0000 @@ -43,14 +43,14 @@ /* Instantiate the expansion board */ static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); -/* Retrieve the composing elements of the expansion board */ -static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer; -static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; -static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; +/* Retrieve the LSM6DSL Object */ static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; -static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; -/* Helper function for printing floats & doubles */ +/*Initialize Serial port object*/ +Serial pc(USBTX, USBRX); +Timer t; + +/* Helper function for printing floats & doubles. Not using at the moment! */ static char *print_double(char* str, double v, int decimalDigits=2) { int i = 1; @@ -89,56 +89,31 @@ /* Simple main function */ int main() { uint8_t id; - float value1, value2; - char buffer1[32], buffer2[32]; - int32_t axes[3]; + //float value1, value2; + //char buffer1[32], buffer2[32]; + int32_t a_axes[3]; + int32_t g_axes[3]; - /* Enable all sensors */ - hum_temp->enable(); - press_temp->enable(); - magnetometer->enable(); - accelerometer->enable(); + /* Set port speed*/ + pc.baud(115200); + + /* Enable gyro and accel sensors */ acc_gyro->enable_x(); acc_gyro->enable_g(); - printf("\r\n--- Starting new run ---\r\n"); + pc.printf("\r\n--- Starting new run ---\r\n"); - hum_temp->read_id(&id); - printf("HTS221 humidity & temperature = 0x%X\r\n", id); - press_temp->read_id(&id); - printf("LPS22HB pressure & temperature = 0x%X\r\n", id); - magnetometer->read_id(&id); - printf("LSM303AGR magnetometer = 0x%X\r\n", id); - accelerometer->read_id(&id); - printf("LSM303AGR accelerometer = 0x%X\r\n", id); acc_gyro->read_id(&id); - printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); + pc.printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);\ + + t.start(); while(1) { - printf("\r\n"); - - hum_temp->get_temperature(&value1); - hum_temp->get_humidity(&value2); - printf("HTS221: [temp] %7s C, [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2)); - press_temp->get_temperature(&value1); - press_temp->get_pressure(&value2); - printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2)); - - printf("---\r\n"); - - magnetometer->get_m_axes(axes); - printf("LSM303AGR [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + acc_gyro->get_x_axes(a_axes); + acc_gyro->get_g_axes(g_axes); + pc.printf("mg ,mdps: %d %6ld, %6ld, %6ld, %6ld, %6ld, %6ld,\r\n", t.read_ms(), a_axes[0], a_axes[1], a_axes[2],g_axes[0], g_axes[1], g_axes[2]); - accelerometer->get_x_axes(axes); - printf("LSM303AGR [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - acc_gyro->get_x_axes(axes); - printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - acc_gyro->get_g_axes(axes); - printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); - - wait(1.5); + //wait_ms(10); } }