diff --git a/tests/driver_jc42/Makefile b/tests/driver_jc42/Makefile new file mode 100644 index 000000000..4560f2025 --- /dev/null +++ b/tests/driver_jc42/Makefile @@ -0,0 +1,17 @@ +APPLICATION = driver_jc42 +include ../Makefile.tests_common + +USEMODULE += jc42 +USEMODULE += xtimer + +# set default device parameters in case they are undefined +TEST_I2C ?= 0 +TEST_I2C_ADDR ?= 0x18 +TEST_I2C_SPEED ?= I2C_SPEED_NORMAL + +# export parameters +CFLAGS += -DTEST_I2C=$(TEST_I2C) +CFLAGS += -DTEST_I2C_ADDR=$(TEST_I2C_ADDR) +CFLAGS += -DTEST_I2C_SPEED=$(TEST_I2C_SPEED) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_jc42/README.md b/tests/driver_jc42/README.md new file mode 100644 index 000000000..4b27efcb9 --- /dev/null +++ b/tests/driver_jc42/README.md @@ -0,0 +1,14 @@ +# JC42 Driver Test + +## Introduction +This test will test if the jc42 compatible temperature sensor is working. + +## Configuration +There are three parameters to configure: + +* `TEST_I2C` — I2C device to use. +* `TEST_I2C_ADDR` — The sensor address (usually 0x18). +* `TEST_I2C_SPEED` — The sensor address (usually I2C_SPEED_NORMAL). + +## Expected result +The sensor should continuously (every 1 sec) output the temperature. The precision should be two digits. diff --git a/tests/driver_jc42/main.c b/tests/driver_jc42/main.c new file mode 100644 index 000000000..7e5f477d1 --- /dev/null +++ b/tests/driver_jc42/main.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2017 Koen Zandberg + * + * 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 jc42 sensor driver + * + * @author Koen Zandberg + * + * @} + */ + +#ifndef TEST_I2C +#error "TEST_I2C not defined" +#endif + +#ifndef TEST_I2C_ADDR +#error "TEST_I2C_ADDR not defined" +#endif + +#ifndef TEST_I2C_SPEED +#error "TEST_I2C_SPEED not defined" +#endif + +#include + +#include "xtimer.h" + +#include "periph/i2c.h" + +#include "jc42.h" + +int main(void) +{ + jc42_t dev; + jc42_params_t params = { + .i2c = TEST_I2C, + .addr = TEST_I2C_ADDR, + .speed = TEST_I2C_SPEED, + }; + + puts("JC42 temperature sensor test application\n"); + + /* initialize the sensor */ + printf("Initializing sensor..."); + + if (jc42_init(&dev, ¶ms) == 0) { + puts("[OK]"); + } + else { + puts("[Failed]"); + return 1; + } + + /* read temperature every 1 seconds */ + int16_t temperature; + while (1) { + printf("Testing sensor communication..."); + if (jc42_get_temperature(&dev, &temperature) == 0) { + puts("[OK]"); + } + else { + puts("[Failed]"); + return 1; + } + /* display results */ + printf("temperature: %d.%02d C\n", temperature / 100, temperature % 100); + + /* sleep between measurements */ + xtimer_usleep(1000 * MS_IN_USEC); + } + + return 0; +}