mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-31 21:14:37 +00:00
temp_sensor: add calibration for esp32c3
This commit is contained in:
6
examples/peripherals/temp_sensor/CMakeLists.txt
Normal file
6
examples/peripherals/temp_sensor/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(temp_sensor)
|
||||
30
examples/peripherals/temp_sensor/README.md
Normal file
30
examples/peripherals/temp_sensor/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
| Supported Targets | ESP32-S2 |
|
||||
| ----------------- | -------- |
|
||||
|
||||
# ESP32-S2 Temperature Sensor Example
|
||||
|
||||
The ESP32-S2 has a built-in temperature sensor. The temperature sensor module contains an 8-bit Sigma-Delta ADC and a temperature offset DAC.
|
||||
|
||||
The conversion relationship is the first two columns of the table below. Among them, `offset = 0`(default) is the main measurement option, and other values are extended measurement options.
|
||||
|
||||
| DAC level | offset | measure range(℃) | measure error(℃) |
|
||||
| :-------: | :----: | :--------------: | :--------------: |
|
||||
| 0 | -2 | 50 ~ 125 | < 3 |
|
||||
| 1 | -1 | 20 ~ 100 | < 2 |
|
||||
| 2 | 0 | -10 ~ 80 | < 1 |
|
||||
| 3 | 1 | -30 ~ 50 | < 2 |
|
||||
| 4 | 2 | -40 ~ 20 | < 3 |
|
||||
|
||||
* Log output :
|
||||
|
||||
```
|
||||
I (243) TempSensor: Initializing Temperature sensor
|
||||
I (243) TempSensor: default dac 2, clk_div 6
|
||||
I (243) TempSensor: Config temperature range [-10°C ~ 80°C], error < 1°C
|
||||
I (253) TempSensor: Temperature sensor started
|
||||
I (1253) TempSensor: Temperature out celsius 27.287399°C
|
||||
I (2253) TempSensor: Temperature out celsius 26.848801°C
|
||||
I (3253) TempSensor: Temperature out celsius 26.848801°C
|
||||
I (4253) TempSensor: Temperature out celsius 27.287399°C
|
||||
I (5253) TempSensor: Temperature out celsius 27.287399°C
|
||||
```
|
||||
2
examples/peripherals/temp_sensor/main/CMakeLists.txt
Normal file
2
examples/peripherals/temp_sensor/main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "temp_sensor_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
4
examples/peripherals/temp_sensor/main/component.mk
Normal file
4
examples/peripherals/temp_sensor/main/component.mk
Normal file
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
54
examples/peripherals/temp_sensor/main/temp_sensor_main.c
Normal file
54
examples/peripherals/temp_sensor/main/temp_sensor_main.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* Temperature Sensor Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
/* Note: ESP32 don't support temperature sensor */
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
|
||||
#include "driver/temp_sensor.h"
|
||||
|
||||
static const char *TAG = "TempSensor";
|
||||
|
||||
void tempsensor_example(void *arg)
|
||||
{
|
||||
// Initialize touch pad peripheral, it will start a timer to run a filter
|
||||
ESP_LOGI(TAG, "Initializing Temperature sensor");
|
||||
float tsens_out;
|
||||
temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT();
|
||||
temp_sensor_get_config(&temp_sensor);
|
||||
ESP_LOGI(TAG, "default dac %d, clk_div %d", temp_sensor.dac_offset, temp_sensor.clk_div);
|
||||
temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃.
|
||||
temp_sensor_set_config(temp_sensor);
|
||||
temp_sensor_start();
|
||||
ESP_LOGI(TAG, "Temperature sensor started");
|
||||
while (1) {
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
temp_sensor_read_celsius(&tsens_out);
|
||||
ESP_LOGI(TAG, "Temperature out celsius %f°C", tsens_out);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
xTaskCreate(tempsensor_example, "temp", 2048, NULL, 5, NULL);
|
||||
}
|
||||
|
||||
#elif CONFIG_IDF_TARGET_ESP32
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
printf("ESP32 don't support temperature sensor\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user