samples: esp32: temp: CPU die temperature sample
Add die temperature measure sample for ESP32 targets esp32s2_saola, esp32c3_devkitm. Signed-off-by: Marek Matej <marek.matej@espressif.com>
This commit is contained in:
parent
45d55205db
commit
ac0cbe3c4e
9 changed files with 126 additions and 0 deletions
8
samples/sensor/esp32_temp_sensor/CMakeLists.txt
Normal file
8
samples/sensor/esp32_temp_sensor/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(esp32_temp_sensor)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
31
samples/sensor/esp32_temp_sensor/README.rst
Normal file
31
samples/sensor/esp32_temp_sensor/README.rst
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
.. _esp32_temp_sensor:
|
||||||
|
|
||||||
|
ESP32 Temperature Sensor
|
||||||
|
########################
|
||||||
|
|
||||||
|
Overview
|
||||||
|
********
|
||||||
|
|
||||||
|
This sample periodically reads temperature from the ESP32-S2 and ESP32-C3
|
||||||
|
Internal Temperature Sensor and display the results.
|
||||||
|
|
||||||
|
Building and Running
|
||||||
|
********************
|
||||||
|
|
||||||
|
In order to run this sample, make sure to enable ``esp32_temp`` node in your
|
||||||
|
board DT file.
|
||||||
|
|
||||||
|
.. zephyr-app-commands::
|
||||||
|
:zephyr-app: samples/sensor/esp32_temp_sensor
|
||||||
|
:board: esp32s2_saola
|
||||||
|
:goals: build
|
||||||
|
:compact:
|
||||||
|
|
||||||
|
Sample Output
|
||||||
|
=============
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
Current temperature: 22.6 °C
|
||||||
|
Current temperature: 22.8 °C
|
||||||
|
Current temperature: 23.1 °C
|
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_NEWLIB_LIBC=y
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Application overlay for creating temperature sensor device instance
|
||||||
|
*/
|
||||||
|
|
||||||
|
&coretemp {
|
||||||
|
status = "okay";
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
CONFIG_NEWLIB_LIBC=y
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Application overlay for creating temperature sensor device instance
|
||||||
|
*/
|
||||||
|
|
||||||
|
&coretemp {
|
||||||
|
status = "okay";
|
||||||
|
};
|
3
samples/sensor/esp32_temp_sensor/prj.conf
Normal file
3
samples/sensor/esp32_temp_sensor/prj.conf
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
CONFIG_SENSOR=y
|
||||||
|
CONFIG_PRINTK=y
|
||||||
|
CONFIG_CBPRINTF_FP_SUPPORT=y
|
13
samples/sensor/esp32_temp_sensor/sample.yaml
Normal file
13
samples/sensor/esp32_temp_sensor/sample.yaml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
sample:
|
||||||
|
description: Usage of ESP32 temperature sensor
|
||||||
|
name: esp32_temp_sensor
|
||||||
|
tests:
|
||||||
|
sample.sensor.esp32_temp_sensor:
|
||||||
|
tags: sensors
|
||||||
|
tags: tests
|
||||||
|
filter: dt_compat_enabled("espressif,esp32-temp")
|
||||||
|
harness: console
|
||||||
|
harness_config:
|
||||||
|
type: one_line
|
||||||
|
regex:
|
||||||
|
- "Current temperature: [1-5][0-9].[0-9] °C"
|
47
samples/sensor/esp32_temp_sensor/src/main.c
Normal file
47
samples/sensor/esp32_temp_sensor/src/main.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/drivers/sensor.h>
|
||||||
|
#include <zephyr/sys/printk.h>
|
||||||
|
|
||||||
|
#if CONFIG_SOC_ESP32
|
||||||
|
#error "Temperature sensor is not supported on ESP32 soc"
|
||||||
|
#endif /* CONFIG_SOC_ESP32 */
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
const struct device *const dev = DEVICE_DT_GET_ONE(espressif_esp32_temp);
|
||||||
|
struct sensor_value val;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!device_is_ready(dev)) {
|
||||||
|
printk("Temperature sensor is not ready\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printk("ESP32 Die temperature sensor test\n");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
k_sleep(K_MSEC(300));
|
||||||
|
|
||||||
|
/* fetch sensor samples */
|
||||||
|
rc = sensor_sample_fetch(dev);
|
||||||
|
if (rc) {
|
||||||
|
printk("Failed to fetch sample (%d)\n", rc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP, &val);
|
||||||
|
if (rc) {
|
||||||
|
printk("Failed to get data (%d)\n", rc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printk("Current temperature: %.1f °C\n", sensor_value_to_double(&val));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue