mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests: Add test for MPU-9150 9-Axis motion sensor driver
This commit is contained in:
parent
ae4616c5d8
commit
bb6f7926fc
35
tests/driver_mpu9150/Makefile
Normal file
35
tests/driver_mpu9150/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
APPLICATION = driver_mpu9150
|
||||
include ../Makefile.tests_common
|
||||
|
||||
FEATURES_REQUIRED = periph_i2c
|
||||
|
||||
# Define default mappings for some boards:
|
||||
ifneq (,$(filter msbiot,$(BOARD)))
|
||||
export TEST_I2C ?= MPU9150_I2C
|
||||
export TEST_HW_ADDR ?= MPU9150_HW_ADDR
|
||||
export TEST_COMP_ADDR ?= MPU9150_COMP_ADDR
|
||||
endif
|
||||
|
||||
USEMODULE += mpu9150
|
||||
USEMODULE += vtimer
|
||||
|
||||
ifneq (,$(TEST_I2C))
|
||||
CFLAGS += -DTEST_I2C=$(TEST_I2C)
|
||||
else
|
||||
# set random default
|
||||
CFLAGS += -DTEST_I2C=I2C_0
|
||||
endif
|
||||
ifneq (,$(TEST_HW_ADDR))
|
||||
CFLAGS += -DTEST_HW_ADDR=$(TEST_HW_ADDR)
|
||||
else
|
||||
# set random default
|
||||
CFLAGS += -DTEST_HW_ADDR=MPU9150_HW_ADDR_HEX_68
|
||||
endif
|
||||
ifneq (,$(TEST_COMP_ADDR))
|
||||
CFLAGS += -DTEST_COMP_ADDR=$(TEST_COMP_ADDR)
|
||||
else
|
||||
# set random default
|
||||
CFLAGS += -DTEST_COMP_ADDR=MPU9150_COMP_ADDR_HEX_0C
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
13
tests/driver_mpu9150/README.md
Normal file
13
tests/driver_mpu9150/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# About
|
||||
This is a test application for the MPU-9150 Nine-Axis Driver.
|
||||
|
||||
# Usage
|
||||
The application will initialize the MPU-9150 motion sensor with the following parameters:
|
||||
- Accelerometer: ON
|
||||
- Gyroscope: ON
|
||||
- Magnetometer: ON
|
||||
- Sampling Rate: 200Hz
|
||||
- Compass Sampling Rate: 100Hz
|
||||
|
||||
After initialization, the application reads accel, gyro, compass and temperature values
|
||||
every second and prints them to the STDOUT.
|
106
tests/driver_mpu9150/main.c
Normal file
106
tests/driver_mpu9150/main.c
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freie Universität Berlin
|
||||
*
|
||||
* 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
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Test application for the MPU-9150 Nine-Axis driver
|
||||
*
|
||||
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef TEST_I2C
|
||||
#error "TEST_I2C not defined"
|
||||
#endif
|
||||
#ifndef TEST_HW_ADDR
|
||||
#error "TEST_HW_ADDR not defined"
|
||||
#endif
|
||||
#ifndef TEST_COMP_ADDR
|
||||
#error "TEST_COMP_ADDR not defined"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mpu9150.h"
|
||||
#include "vtimer.h"
|
||||
#include "board.h"
|
||||
|
||||
#define SLEEP (1000 * 1000u)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mpu9150_t dev;
|
||||
mpu9150_results_t measurement;
|
||||
int32_t temperature;
|
||||
int result;
|
||||
|
||||
puts("MPU-9150 test application\n");
|
||||
|
||||
vtimer_init();
|
||||
|
||||
printf("+------------Initializing------------+\n");
|
||||
result = mpu9150_init(&dev, TEST_I2C, TEST_HW_ADDR, TEST_COMP_ADDR);
|
||||
|
||||
if (result == -1) {
|
||||
puts("[Error] The given i2c is not enabled");
|
||||
return 1;
|
||||
}
|
||||
else if (result == -2) {
|
||||
puts("[Error] The compass did not answer correctly on the given address");
|
||||
return 1;
|
||||
}
|
||||
|
||||
mpu9150_set_sample_rate(&dev, 200);
|
||||
if (dev.conf.sample_rate != 200) {
|
||||
puts("[Error] The sample rate was not set correctly");
|
||||
return 1;
|
||||
}
|
||||
mpu9150_set_compass_sample_rate(&dev, 100);
|
||||
if (dev.conf.compass_sample_rate != 100) {
|
||||
puts("[Error] The compass sample rate was not set correctly");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Initialization successful\n\n");
|
||||
printf("+------------Configuration------------+\n");
|
||||
printf("Sample rate: %"PRIu16" Hz\n", dev.conf.sample_rate);
|
||||
printf("Compass sample rate: %"PRIu8" Hz\n", dev.conf.compass_sample_rate);
|
||||
printf("Gyro full-scale range: 2000 DPS\n");
|
||||
printf("Accel full-scale range: 2 G\n");
|
||||
printf("Compass X axis factory adjustment: %"PRIu8"\n", dev.conf.compass_x_adj);
|
||||
printf("Compass Y axis factory adjustment: %"PRIu8"\n", dev.conf.compass_y_adj);
|
||||
printf("Compass Z axis factory adjustment: %"PRIu8"\n", dev.conf.compass_z_adj);
|
||||
|
||||
printf("\n+--------Starting Measurements--------+\n");
|
||||
while (1) {
|
||||
/* Get accel data in milli g */
|
||||
mpu9150_read_accel(&dev, &measurement);
|
||||
printf("Accel data [milli g] - X: %d Y: %d Z: %d\n",
|
||||
measurement.x_axis, measurement.y_axis, measurement.z_axis);
|
||||
/* Get gyro data in dps */
|
||||
mpu9150_read_gyro(&dev, &measurement);
|
||||
printf("Gyro data [dps] - X: %d Y: %d Z: %d\n",
|
||||
measurement.x_axis, measurement.y_axis, measurement.z_axis);
|
||||
/* Get compass data in mikro Tesla */
|
||||
mpu9150_read_compass(&dev, &measurement);
|
||||
printf("Compass data [mikro T] - X: %d Y: %d Z: %d\n",
|
||||
measurement.x_axis, measurement.y_axis, measurement.z_axis);
|
||||
/* Get temperature in milli degrees celsius */
|
||||
mpu9150_read_temperature(&dev, &temperature);
|
||||
printf("Temperature [milli deg] : %ld\n", temperature);
|
||||
printf("\n+-------------------------------------+\n");
|
||||
|
||||
vtimer_usleep(SLEEP);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user