From 00cb786344faacd94fab831b8c120d90de65f1c2 Mon Sep 17 00:00:00 2001 From: Schorcht <gunar@schorcht.net> Date: Wed, 21 Nov 2018 09:07:20 +0100 Subject: [PATCH] tests: add SHT3X sensor driver test application --- tests/driver_sht3x/Makefile | 5 +++ tests/driver_sht3x/README.md | 13 ++++++++ tests/driver_sht3x/main.c | 62 ++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/driver_sht3x/Makefile create mode 100644 tests/driver_sht3x/README.md create mode 100644 tests/driver_sht3x/main.c diff --git a/tests/driver_sht3x/Makefile b/tests/driver_sht3x/Makefile new file mode 100644 index 0000000000..117bcc4080 --- /dev/null +++ b/tests/driver_sht3x/Makefile @@ -0,0 +1,5 @@ +include ../Makefile.tests_common + +USEMODULE += sht3x + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_sht3x/README.md b/tests/driver_sht3x/README.md new file mode 100644 index 0000000000..21f5b3b195 --- /dev/null +++ b/tests/driver_sht3x/README.md @@ -0,0 +1,13 @@ +# Sensirion SHT30/SHT31/SHT35 Humidity and Temperature Sensors + +## About +This is a manual test application for the SHT3x driver. + +## Usage +This test application will initialize the sensor with the following parameters: + +- Periodic Measurement with 2 measurements per second +- High Repeatability + +After initialization, the sensor reads the temperature and humidity every second +and prints them to the STDOUT. diff --git a/tests/driver_sht3x/main.c b/tests/driver_sht3x/main.c new file mode 100644 index 0000000000..b2655ad930 --- /dev/null +++ b/tests/driver_sht3x/main.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 Gunar Schorcht + * + * 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 + * @brief Test application for the Sensirion SHT30/SHT31/SHT35 device driver + * @author Gunar Schorcht <gunar@schorcht.net> + * @file + * @{ + * @} + */ + +#include <stdio.h> +#include <string.h> + +#include "xtimer.h" +#include "sht3x.h" +#include "sht3x_params.h" + +int main(void) +{ + sht3x_dev_t dev; + int res; + + puts("SHT3X test application\n"); + + printf("+------------Initializing------------+\n"); + + if ((res = sht3x_init(&dev, &sht3x_params[0])) != SHT3X_OK) { + puts("Initialization failed\n"); + return 1; + } + else { + puts("Initialization successful\n"); + } + + printf("\n+--------Starting Measurements--------+\n"); + + while (1) { + int16_t temp; + int16_t hum; + + if ((res = sht3x_read(&dev, &temp, &hum)) == SHT3X_OK) { + printf("Temperature [°C]: %d.%d\n" + "Relative Humidity [%%]: %d.%d\n" + "+-------------------------------------+\n", + temp / 100, temp % 100, + hum / 100, hum % 100); + } + else { + printf("Could not read data from sensor, error %d\n", res); + } + xtimer_usleep(1000000); + } + + return 0; +} -- GitLab