Skip to content
Snippets Groups Projects
Commit 9a3c983d authored by Sebastian Meiling's avatar Sebastian Meiling
Browse files

drivers, lsm6dsl: update test, and add README

parent 6d252099
No related branches found
No related tags found
No related merge requests found
# About
This is a manual test application for the ST LSM6DSL sensor driver.
# Usage
After successful initialization, the sensor reads the accelerometer, gyroscope,
and temperature values every 500ms and prints them to the STDOUT. If device
initialization fails the tests exits with 1, otherwise it runs forever.
Note: reading sensor values may fail even on successful initialization.
/* /*
* Copyright (C) 2017 OTA keys S.A. * Copyright (C) 2017 OTA keys S.A.
* 2017 HAW Hamburg
* *
* This file is subject to the terms and conditions of the GNU Lesser * This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level * General Public License v2.1. See the file LICENSE in the top level
...@@ -7,11 +8,16 @@ ...@@ -7,11 +8,16 @@
*/ */
/** /**
* @ingroup tests
* @{
*
* @file * @file
* @brief Test application for the LSM6DSL accelerometer/gyroscope driver. * @brief Test application for the LSM6DSL accelerometer/gyroscope driver.
* *
* @author Vincent Dupont <vincent@otakeys.com> * @author Vincent Dupont <vincent@otakeys.com>
* @author Sebastian Meiling <s@mlng.net>
* *
* @}
*/ */
#include <stdio.h> #include <stdio.h>
...@@ -20,7 +26,7 @@ ...@@ -20,7 +26,7 @@
#include "lsm6dsl.h" #include "lsm6dsl.h"
#include "lsm6dsl_params.h" #include "lsm6dsl_params.h"
#define SLEEP (100 * 1000U) #define SLEEP (500UL * US_PER_MS)
int main(void) int main(void)
{ {
...@@ -29,42 +35,42 @@ int main(void) ...@@ -29,42 +35,42 @@ int main(void)
lsm6dsl_3d_data_t mag_value; lsm6dsl_3d_data_t mag_value;
lsm6dsl_3d_data_t acc_value; lsm6dsl_3d_data_t acc_value;
puts("LSM6DSL test application\n"); puts("LSM6DSL test application");
printf("Initializing LSM6DSL sensor at I2C_%i... ", lsm6dsl_params->i2c); printf("Initializing LSM6DSL sensor at I2C_%i... ", lsm6dsl_params->i2c);
if (lsm6dsl_init(&dev, lsm6dsl_params) == 0) { if (lsm6dsl_init(&dev, lsm6dsl_params) != LSM6DSL_OK) {
puts("[OK]\n"); puts("[ERROR]");
}
else {
puts("[Failed]");
return 1; return 1;
} }
puts("[SUCCESS]\n");
while (1) { while (1) {
if (lsm6dsl_read_acc(&dev, &acc_value) == 0) { if (lsm6dsl_read_acc(&dev, &acc_value) == LSM6DSL_OK) {
printf("Accelerometer x: %i y: %i z: %i\n", acc_value.x, printf("Accelerometer x: %i y: %i z: %i\n", acc_value.x,
acc_value.y, acc_value.y,
acc_value.z); acc_value.z);
} }
else { else {
puts("\nFailed reading accelerometer values\n"); puts("[ERROR] reading accelerometer!\n");
}
if (lsm6dsl_read_temp(&dev, &temp_value) == 0) {
printf("Temperature value: %i degrees\n", temp_value);
}
else {
puts("\nFailed reading value\n");
} }
if (lsm6dsl_read_gyro(&dev, &mag_value) == 0) { if (lsm6dsl_read_gyro(&dev, &mag_value) == LSM6DSL_OK) {
printf("Gyroscope x: %i y: %i z: %i\n", mag_value.x, printf("Gyroscope x: %i y: %i z: %i\n", mag_value.x,
mag_value.y, mag_value.y,
mag_value.z); mag_value.z);
} }
else { else {
puts("\nFailed reading Gyroscope values\n"); puts("[ERROR] reading gyroscope!\n");
}
if (lsm6dsl_read_temp(&dev, &temp_value) == LSM6DSL_OK) {
printf("Temperature [in °C x 100]: %i \n", temp_value);
}
else {
puts("[ERROR] reading temperature!\n");
} }
puts("");
xtimer_usleep(SLEEP); xtimer_usleep(SLEEP);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment