From 071b8dfa98a9c15f3bb287ea750d15c2199f4e82 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Thu, 20 Sep 2018 13:01:35 +0200 Subject: [PATCH] tests/srf04: test application for srf04 driver --- tests/driver_srf04/Makefile | 9 +++++++ tests/driver_srf04/README.md | 17 +++++++++++++ tests/driver_srf04/main.c | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/driver_srf04/Makefile create mode 100644 tests/driver_srf04/README.md create mode 100644 tests/driver_srf04/main.c diff --git a/tests/driver_srf04/Makefile b/tests/driver_srf04/Makefile new file mode 100644 index 0000000000..4cb9b5b8f5 --- /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 0000000000..d3a39eb5a3 --- /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 0000000000..1fcb615db1 --- /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 + * + * @} + */ + +#include +#include +#include + +#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; +}