Skip to content

esp32/modesp32: Add temperature method for S2,C3 chips. #11672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/library/esp32.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ Functions

Read the raw value of the internal temperature sensor, returning an integer.

Only available on ESP32.

.. function:: temperature()

Read the value of the internal temperature sensor in celsius, returning a float.

Available on ESP32-S2, S3 and C3.

.. Note::
The temperature sensor is designed primarily to measure the temperature changes inside
the chip. The temperature value depends on factors like microcontroller clock frequency
or I/O load. Generally, the chip’s internal temperature might be higher than the ambient temperature.

.. function:: hall_sensor()

Read the raw value of the internal Hall sensor, returning an integer.

.. function:: idf_heap_info(capabilities)

Returns information about the ESP-IDF heap memory regions. One of them contains
Expand Down
23 changes: 23 additions & 0 deletions ports/esp32/modesp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_raw_temperature_obj, esp32_raw_temperatur

#endif

#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3

#include "driver/temperature_sensor.h"

STATIC mp_obj_t esp32_temperature(void) {

temperature_sensor_handle_t temp_sensor = NULL;
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(0, 50);
temperature_sensor_install(&temp_sensor_config, &temp_sensor);
temperature_sensor_enable(temp_sensor);
float tsens_out;
temperature_sensor_get_celsius(temp_sensor, &tsens_out);
temperature_sensor_disable(temp_sensor);
temperature_sensor_uninstall(temp_sensor);

return mp_obj_new_float(tsens_out);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_temperature_obj, esp32_temperature);
#endif

STATIC mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) {
mp_int_t cap = mp_obj_get_int(cap_in);
multi_heap_info_t info;
Expand Down Expand Up @@ -203,6 +223,9 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = {
#if CONFIG_IDF_TARGET_ESP32
{ MP_ROM_QSTR(MP_QSTR_raw_temperature), MP_ROM_PTR(&esp32_raw_temperature_obj) },
#endif
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
{ MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&esp32_temperature_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_idf_heap_info), MP_ROM_PTR(&esp32_idf_heap_info_obj) },

{ MP_ROM_QSTR(MP_QSTR_NVS), MP_ROM_PTR(&esp32_nvs_type) },
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy