temp_sensor_main.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_log.h"
  7. #include "esp_check.h"
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. #include "driver/temperature_sensor.h"
  11. static const char *TAG = "example";
  12. void tempsensor_example(void)
  13. {
  14. // Initialize touch pad peripheral, it will start a timer to run a filter
  15. ESP_LOGI(TAG, "Initializing Temperature sensor");
  16. float tsens_out;
  17. temperature_sensor_config_t temp_sensor = TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(10, 50);
  18. temperature_sensor_handle_t temp_handle = NULL;
  19. ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor, &temp_handle));
  20. ESP_ERROR_CHECK(temperature_sensor_start(temp_handle));
  21. ESP_LOGI(TAG, "Temperature sensor started");
  22. int cnt = 20; //read value for 20 times
  23. while (cnt) {
  24. vTaskDelay(1000 / portTICK_PERIOD_MS);
  25. ESP_ERROR_CHECK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
  26. ESP_LOGI(TAG, "Temperature out celsius %.02f", tsens_out);
  27. cnt--;
  28. }
  29. }
  30. void app_main(void)
  31. {
  32. tempsensor_example();
  33. }