diff --git a/tests/driver_srf04/Makefile b/tests/driver_srf04/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..4cb9b5b8f55cb3b3fa19b61bc60cd03c5012f8b9 --- /dev/null +++ b/tests/driver_srf04/Makefile @@ -0,0 +1,9 @@ +include ../Makefile.tests_common + +BOARD ?= nrf52dk + +RIOTBASE ?= $(CURDIR)/../.. + +USEMODULE += srf04 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_srf04/README.md b/tests/driver_srf04/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d3a39eb5a36d4480167f76bd6efae55dde9b3dfa --- /dev/null +++ b/tests/driver_srf04/README.md @@ -0,0 +1,17 @@ +tests/driver_srf04 +================ +This example shows the usage of an srf04 module. +The application uses a timer and two gpio pins. +The module is an ultrasonic range finder with a small protocol [1]: +- trigger pin is raised high for 10 us by calling trigger function +- after a sample period of 50 ms the value can be read out + +[1] www.robot-electronics.co.uk/htm/srf04tech.htm + +Usage +===== + +Build, flash and start the application: + + export BOARD=your_board + make flash term diff --git a/tests/driver_srf04/main.c b/tests/driver_srf04/main.c new file mode 100644 index 0000000000000000000000000000000000000000..1fcb615db152a18bcb2a5103984a5b017cdd2ae9 --- /dev/null +++ b/tests/driver_srf04/main.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2018 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 for srf04 ultra sonic range finder driver + * + * @author Semjon Kerner <semjon.kerner@fu-berlin.de> + * + * @} + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "srf04_params.h" +#include "srf04.h" + +int main(void) +{ + puts("SRF04 range finder example"); + + srf04_t dev; + if (srf04_init(&dev, &srf04_params[0]) != SRF04_OK) { + puts("Error: initializing"); + return 1; + } + + while (1) { + int distance = srf04_get_distance(&dev); + if (distance < SRF04_OK) { + puts("Error: no valid data available"); + } else { + printf("D: %d mm\n", distance); + } + } + + return 0; +}