From 656792d58fb6bd5361e630f1b576e8fbf5d0a591 Mon Sep 17 00:00:00 2001 From: Ioannis Konstantelias Date: Fri, 23 Aug 2019 11:53:04 +0300 Subject: [PATCH] samples: sensor: tmp116: Add sample for TMP116 Added sample demonstrating the TMP116 temperature sensor. Signed-off-by: Ioannis Konstantelias --- samples/sensor/tmp116/CMakeLists.txt | 8 +++ samples/sensor/tmp116/README.rst | 62 +++++++++++++++++++++ samples/sensor/tmp116/nucleo_f401re.overlay | 15 +++++ samples/sensor/tmp116/prj.conf | 4 ++ samples/sensor/tmp116/sample.yaml | 18 ++++++ samples/sensor/tmp116/src/main.c | 42 ++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 samples/sensor/tmp116/CMakeLists.txt create mode 100644 samples/sensor/tmp116/README.rst create mode 100644 samples/sensor/tmp116/nucleo_f401re.overlay create mode 100644 samples/sensor/tmp116/prj.conf create mode 100644 samples/sensor/tmp116/sample.yaml create mode 100644 samples/sensor/tmp116/src/main.c diff --git a/samples/sensor/tmp116/CMakeLists.txt b/samples/sensor/tmp116/CMakeLists.txt new file mode 100644 index 00000000000..aaaff60961b --- /dev/null +++ b/samples/sensor/tmp116/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(tmp116) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/sensor/tmp116/README.rst b/samples/sensor/tmp116/README.rst new file mode 100644 index 00000000000..f940944e8b8 --- /dev/null +++ b/samples/sensor/tmp116/README.rst @@ -0,0 +1,62 @@ +.. _ti_tmp116_sample: + +TI_TMP116 Sample +################ + +Description +*********** + +This sample application periodically takes temperature readings using the ti_tmp116 +sensor driver. The result is written to the console. + +Requirements +************ + +This sample needs a TI TMP116 sensor connected to the target board's I2C +connector. + + +Wiring +****** + +This sample is tested with Nucleo STM32F401RE board. + +The sensor operates at 3.3V and uses I2C to communicate with the board. + +External Wires: + +* Breakout **GND** pin <--> Nucleo **GND** pin +* Breakout **VCC** pin <--> Nucleo **3V3** pin +* Breakout **SDA** pin <--> Nucleo **CN5-D14** pin +* Breakout **SCL** pin <--> Nucleo **CN5-D15** pin + +Building and Running +******************** + +In order to build the sample, connect the board to the computer with a USB cable and enter the +following commands: + +.. zephyr-app-commands:: + :zephyr-app: samples/sensor/tmp116 + :board: nucleo_f401re + :goals: build flash + :compact: + +Sample Output +************* +The output can be seen via a terminal emultator (e.g. minicom). Connect the board with a USB cable +to the computer and open /dev/ttyACM0 with the below serial settings: + +* Baudrate: 115200 +* Parity: None +* Data: 8 +* Stop bits: 1 + +The output should look like this: + +.. code-block:: console + + Device TMP116 - 0x200010a8 is ready + temp is 26.7031250 oC + temp is 26.7109375 oC + ... diff --git a/samples/sensor/tmp116/nucleo_f401re.overlay b/samples/sensor/tmp116/nucleo_f401re.overlay new file mode 100644 index 00000000000..3ba3e8d4843 --- /dev/null +++ b/samples/sensor/tmp116/nucleo_f401re.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2019 Centaur Analytics, Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c1 { + + ti_tmp116: ti_tmp116@4b { + compatible = "ti,tmp116"; + reg = <0x4B>; + label = "TMP116"; + }; + +}; diff --git a/samples/sensor/tmp116/prj.conf b/samples/sensor/tmp116/prj.conf new file mode 100644 index 00000000000..0555ec27e50 --- /dev/null +++ b/samples/sensor/tmp116/prj.conf @@ -0,0 +1,4 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_I2C=y +CONFIG_SENSOR=y +CONFIG_TMP116=y diff --git a/samples/sensor/tmp116/sample.yaml b/samples/sensor/tmp116/sample.yaml new file mode 100644 index 00000000000..269a104300f --- /dev/null +++ b/samples/sensor/tmp116/sample.yaml @@ -0,0 +1,18 @@ +sample: + name: TI TMP116 Sensor Sample +tests: + test_build: + harness: sensor + platform_whitelist: nucleo_f401re + tags: sensors + depends_on: i2c + sample.sensor.tmp116: + harness: console + platform_whitelist: nucleo_f401re + tags: sensors + depends_on: i2c + harness_config: + type: one_line + regex: + - "temp is (.*) oC" + fixture: fixture_i2c_tmp116 diff --git a/samples/sensor/tmp116/src/main.c b/samples/sensor/tmp116/src/main.c new file mode 100644 index 00000000000..227c74ae7d8 --- /dev/null +++ b/samples/sensor/tmp116/src/main.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 Centaur Analytics, Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +void main(void) +{ + struct device *dev; + struct sensor_value temp_value; + int ret; + + dev = device_get_binding(DT_INST_0_TI_TMP116_LABEL); + __ASSERT(dev != NULL, "Failed to get TMP116 device binding"); + + printk("Device %s - %p is ready\n", dev->config->name, dev); + + while (1) { + ret = sensor_sample_fetch(dev); + if (ret) { + printk("Failed to fetch measurements (%d)\n", ret); + return; + } + + ret = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, + &temp_value); + if (ret) { + printk("Failed to get measurements (%d)\n", ret); + return; + } + + printk("temp is %d.%d oC\n", temp_value.val1, temp_value.val2); + + k_sleep(1000); + } +}