samples: sensor: tmp116: Add sample for TMP116

Added sample demonstrating the TMP116 temperature sensor.

Signed-off-by: Ioannis Konstantelias <ikonstadel@gmail.com>
This commit is contained in:
Ioannis Konstantelias 2019-08-23 11:53:04 +03:00 committed by Maureen Helm
commit 656792d58f
6 changed files with 149 additions and 0 deletions

View file

@ -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})

View file

@ -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
...

View file

@ -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";
};
};

View file

@ -0,0 +1,4 @@
CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_TMP116=y

View file

@ -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

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2019 Centaur Analytics, Inc
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>
#include <sys/printk.h>
#include <sys/__assert.h>
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);
}
}