Skip to content

Commit

Permalink
add test app for mma8652 accelerometer driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jfischer-no committed Jan 8, 2015
1 parent ae10cc8 commit 4099e89
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/driver_mma8652/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
APPLICATION = driver_mma8652
include ../Makefile.tests_common

FEATURES_REQUIRED = periph_i2c

USEMODULE += mma8652
USEMODULE += vtimer

ifneq (,$(TEST_MMA8652_I2C))
CFLAGS += -DTEST_MMA8652_I2C=$(TEST_MMA8652_I2C)
else
CFLAGS += -DTEST_MMA8652_I2C=I2C_0
endif
ifneq (,$(TEST_MMA8652_ADDR))
CFLAGS += -DTEST_MMA8652_ADDR=$(TEST_MMA8652_ADDR)
else
CFLAGS += -DTEST_MMA8652_ADDR=0x1D
endif

ifneq (,$(TEST_MMA8652_USER_OFFSET_X))
CFLAGS += -DTEST_MMA8652_USER_OFFSET_X=$(TEST_MMA8652_USER_OFFSET_X)
else
CFLAGS += -DTEST_MMA8652_USER_OFFSET_X=0
endif
ifneq (,$(TEST_MMA8652_USER_OFFSET_Y))
CFLAGS += -DTEST_MMA8652_USER_OFFSET_Y=$(TEST_MMA8652_USER_OFFSET_Y)
else
CFLAGS += -DTEST_MMA8652_USER_OFFSET_Y=0
endif
ifneq (,$(TEST_MMA8652_USER_OFFSET_Z))
CFLAGS += -DTEST_MMA8652_USER_OFFSET_Z=$(TEST_MMA8652_USER_OFFSET_Z)
else
CFLAGS += -DTEST_MMA8652_USER_OFFSET_Z=0
endif

include $(RIOTBASE)/Makefile.include
10 changes: 10 additions & 0 deletions tests/driver_mma8652/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# About
This is a manual test application for the MMA8652 accelerometer driver.

# Usage
This test application will initialize the MMA8652 sensor with the following parameters:
- full scale parameter set to +/-2 g
- 6.25 Hz output data-rate

After initialization, the sensor reads the x-, y-, z-axis values every 1 s
and prints them to STDOUT.
75 changes: 75 additions & 0 deletions tests/driver_mma8652/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014 PHYTEC Messtechnik GmbH
*
* 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 MMA8652 accelerometer driver.
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Johann Fischer <j.fischer@phytec.de>
*
* @}
*/

#ifndef TEST_MMA8652_I2C
#error "TEST_MMA8652_I2C not defined"
#endif
#ifndef TEST_MMA8652_ADDR
#error "TEST_MMA8652_ADDR not defined"
#endif

#include <stdio.h>

#include "vtimer.h"
#include "mma8652.h"

#define SLEEP (1000 * 1000U)

int main(void)
{
mma8652_t dev;
int16_t x, y, z;
uint8_t status;

puts("MMA8652 accelerometer driver test application\n");
printf("Initializing MMA8652 accelerometer at I2C_%i... ", TEST_MMA8652_I2C);

if (mma8652_init(&dev, TEST_MMA8652_I2C, TEST_MMA8652_ADDR,
MMA8652_DATARATE_DEFAULT,
MMA8652_FS_RANGE_DEFAULT) == 0) {
puts("[OK]\n");
}
else {
puts("[Failed]");
return -1;
}

if (mma8652_set_user_offset(&dev, TEST_MMA8652_USER_OFFSET_X,
TEST_MMA8652_USER_OFFSET_Y,
TEST_MMA8652_USER_OFFSET_Z)) {
puts("Set user offset correction failed.");
return -1;
}

if (mma8652_set_active(&dev)) {
puts("Measurement start failed.");
return -1;
}

while (1) {
mma8652_read(&dev, &x, &y, &z, &status);
printf("Acceleration, raw: X: %d Y: %d Z: %d S: %2x\n", x, y, z, status);
vtimer_usleep(SLEEP);
}

return 0;
}

0 comments on commit 4099e89

Please sign in to comment.