2019-06-20 08:13:47 +00:00
|
|
|
/* Temperature Sensor Example
|
2019-06-13 11:34:01 +00:00
|
|
|
|
|
|
|
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"
|
2019-06-20 08:13:47 +00:00
|
|
|
|
|
|
|
/* Note: ESP32 don't support temperature sensor */
|
2019-06-13 11:34:01 +00:00
|
|
|
|
2020-01-17 03:47:08 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2
|
2020-02-25 14:19:48 +00:00
|
|
|
#include "driver/temp_sensor.h"
|
2019-06-13 11:34:01 +00:00
|
|
|
|
2019-06-20 08:13:47 +00:00
|
|
|
static const char *TAG = "TempSensor";
|
2019-06-13 11:34:01 +00:00
|
|
|
|
|
|
|
void tempsensor_example(void *arg)
|
|
|
|
{
|
|
|
|
// Initialize touch pad peripheral, it will start a timer to run a filter
|
2019-06-20 08:13:47 +00:00
|
|
|
ESP_LOGI(TAG, "Initializing Temperature sensor");
|
|
|
|
float tsens_out;
|
|
|
|
temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT();
|
2019-06-13 11:34:01 +00:00
|
|
|
temp_sensor_get_config(&temp_sensor);
|
|
|
|
ESP_LOGI(TAG, "default dac %d, clk_div %d", temp_sensor.dac_offset, temp_sensor.clk_div);
|
2019-06-20 08:13:47 +00:00
|
|
|
temp_sensor.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~ 80℃, error < 1℃.
|
2019-06-13 11:34:01 +00:00
|
|
|
temp_sensor_set_config(temp_sensor);
|
|
|
|
temp_sensor_start();
|
2019-06-20 08:13:47 +00:00
|
|
|
ESP_LOGI(TAG, "Temperature sensor started");
|
|
|
|
while (1) {
|
2019-06-13 11:34:01 +00:00
|
|
|
vTaskDelay(1000 / portTICK_RATE_MS);
|
2019-06-20 08:13:47 +00:00
|
|
|
temp_sensor_read_celsius(&tsens_out);
|
|
|
|
ESP_LOGI(TAG, "Temperature out celsius %f°C", tsens_out);
|
2019-06-13 11:34:01 +00:00
|
|
|
}
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
|
2019-08-12 02:06:07 +00:00
|
|
|
void app_main(void)
|
2019-06-13 11:34:01 +00:00
|
|
|
{
|
|
|
|
xTaskCreate(tempsensor_example, "temp", 2048, NULL, 5, NULL);
|
|
|
|
}
|
|
|
|
|
2019-06-20 08:13:47 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32
|
|
|
|
|
2019-08-12 02:06:07 +00:00
|
|
|
void app_main(void)
|
2019-06-20 08:13:47 +00:00
|
|
|
{
|
|
|
|
printf("ESP32 don't support temperature sensor\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|