temp sensor

This commit is contained in:
2025-06-24 01:29:42 -04:00
parent 24778f0b73
commit a0fc7f5754

View File

@@ -0,0 +1,28 @@
#include "driver/temperature_sensor.h"
#include "esp_log.h"
#include "esp_err.h"
static temperature_sensor_handle_t temp_sensor;
const char *TAGt = "ESP-NOW_Transmitter";
/*
EXP32-C3 Chip built-in temprature sensor
Read & display the temperature value
*/
static void temp_sensor_task (void *arg) {
while (true) {
ESP_LOGI(TAGt, "Reading sensor temperature");
float tsens_value;
ESP_ERROR_CHECK(temperature_sensor_get_celsius(temp_sensor, &tsens_value));
ESP_LOGW(TAGt, "Temperature value %.02f ℃", tsens_value);
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
static void chip_sensor_init () {
temp_sensor = NULL;
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
ESP_LOGI(TAGt, "Enable temperature sensor");
ESP_ERROR_CHECK(temperature_sensor_enable(temp_sensor));
}