drivers, lsm6dsl: update test, and add README

This commit is contained in:
smlng 2017-07-03 17:21:24 +02:00
parent 6d25209967
commit 9a3c983d1c
2 changed files with 33 additions and 17 deletions

View File

@ -0,0 +1,10 @@
# 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.

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 OTA keys S.A.
* 2017 HAW Hamburg
*
* 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
@ -7,11 +8,16 @@
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Test application for the LSM6DSL accelerometer/gyroscope driver.
*
* @author Vincent Dupont <vincent@otakeys.com>
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
#include <stdio.h>
@ -20,7 +26,7 @@
#include "lsm6dsl.h"
#include "lsm6dsl_params.h"
#define SLEEP (100 * 1000U)
#define SLEEP (500UL * US_PER_MS)
int main(void)
{
@ -29,42 +35,42 @@ int main(void)
lsm6dsl_3d_data_t mag_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);
if (lsm6dsl_init(&dev, lsm6dsl_params) == 0) {
puts("[OK]\n");
}
else {
puts("[Failed]");
if (lsm6dsl_init(&dev, lsm6dsl_params) != LSM6DSL_OK) {
puts("[ERROR]");
return 1;
}
puts("[SUCCESS]\n");
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,
acc_value.y,
acc_value.z);
}
else {
puts("\nFailed reading accelerometer values\n");
}
if (lsm6dsl_read_temp(&dev, &temp_value) == 0) {
printf("Temperature value: %i degrees\n", temp_value);
}
else {
puts("\nFailed reading value\n");
puts("[ERROR] reading accelerometer!\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,
mag_value.y,
mag_value.z);
}
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);
}