diff --git a/tests/driver_si114x/Makefile b/tests/driver_si114x/Makefile new file mode 100644 index 0000000000..2392aab53e --- /dev/null +++ b/tests/driver_si114x/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +# This test should also work with Si1146 and Si1147 variants. +USEMODULE += si1145 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_si114x/README.md b/tests/driver_si114x/README.md new file mode 100644 index 0000000000..9647ae8646 --- /dev/null +++ b/tests/driver_si114x/README.md @@ -0,0 +1,12 @@ +### Test application for Si114X sensors family + +#### Introduction + +The Si114X (Si1145, Si1146 and Si1147) sensors are UV, light and proximity sensors. +More information in the [datasheet](https://www.silabs.com/Support%20Documents%2FTechnicalDocs%2FSi1145-46-47.pdf). + +#### Expected results + +After initialization, the sensor continuously (every 2 secs) displays the +IR light, the visible light, the UV index, the proximity and the value of the +response register. diff --git a/tests/driver_si114x/main.c b/tests/driver_si114x/main.c new file mode 100644 index 0000000000..57dfdf47f8 --- /dev/null +++ b/tests/driver_si114x/main.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016-2018 Inria + * + * 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 Si114x UV, IR, visible and proximity + * sensor. + * + * @author Alexandre Abadie + * Bas Stottelaar + * + * @} + */ + +#include +#include + +#include "si114x.h" +#include "si114x_params.h" +#include "xtimer.h" +#include "board.h" + +static si114x_t dev; + +int main(void) +{ + puts("Si1145 test application\n" + "+------------Initializing------------+\n"); + + int result = si114x_init(&dev, &si114x_params[0]); + if (result == -SI114X_ERR_I2C) { + puts("[Error] The given i2c is not enabled"); + return -1; + } + else if (result == -SI114X_ERR_NODEV) { + puts("[Error] The sensor did not answer correctly on the " + "given address"); + return 1; + } + + puts("Initialization successful\n" + "+--------Starting Measurements--------+\n"); + + while (1) { + printf("UV index: %" PRIu16 "\n" + "IR light [lx]: %" PRIu16 "\n" + "Visible light [lx]: %" PRIu16 "\n" + "Distance [cnt]: %" PRIu16 "\n" + "Response: 0x%02x\n" + "\n+-------------------------------------+\n", + si114x_read_uv(&dev), + si114x_read_ir(&dev), + si114x_read_visible(&dev), + si114x_read_distance(&dev), + si114x_read_response(&dev)); + + /* 2 seconds delay between measures */ + xtimer_sleep(2); + } + + return 0; +}