From 35d5b86470d3421cbadf94d9de8425d518f2c38e Mon Sep 17 00:00:00 2001 From: SuperChamp234 Date: Fri, 1 Sep 2023 23:02:07 +0530 Subject: [PATCH 1/7] Added basic idf.py v5 support --- src/i2cdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i2cdev.c b/src/i2cdev.c index b21047a..17c3e3d 100644 --- a/src/i2cdev.c +++ b/src/i2cdev.c @@ -197,7 +197,7 @@ static esp_err_t i2c_setup_port(const i2c_dev_t *dev) esp_err_t res; if (!cfg_equal(&dev->cfg, &states[dev->port].config)) { - ESP_LOGD(TAG, "Reconfiguring I2C driver on port %d", dev->port); + ESP_LOGD(TAG, "Reconfiguring I2C driver on port %d", (int)dev->port); i2c_config_t temp; memcpy(&temp, &dev->cfg, sizeof(i2c_config_t)); temp.mode = I2C_MODE_MASTER; @@ -222,7 +222,7 @@ static esp_err_t i2c_setup_port(const i2c_dev_t *dev) states[dev->port].installed = true; memcpy(&states[dev->port].config, &temp, sizeof(i2c_config_t)); - ESP_LOGD(TAG, "I2C driver successfully reconfigured on port %d", dev->port); + ESP_LOGD(TAG, "I2C driver successfully reconfigured on port %d", (int)dev->port); } #if HELPER_TARGET_IS_ESP32 int t; From f32b35a90a89acc6b699d3f6e4f2769b18db1626 Mon Sep 17 00:00:00 2001 From: Zain Date: Sat, 30 Dec 2023 12:30:34 +0530 Subject: [PATCH 2/7] Added basic ADC implementation. The ADC is is init and calibrated. ADC Read impl remaining. Completed ADC Read method implementation Changed ADC Bitwidth to 12, and removed extra config files while adding gitignore rules for them. Updated LSA example --- .gitignore | 3 + examples/lsa/main/main.c | 13 ++-- include/adc.h | 39 ++++------ include/lsa.h | 4 +- include/sra_board.h | 2 +- src/adc.c | 161 +++++++++++++++++++++++++++------------ src/lsa.c | 10 +-- 7 files changed, 142 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index fa7e64f..a085a41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ ### C ### +# SDK Config files +sdkconfig + # Build folder build/ diff --git a/examples/lsa/main/main.c b/examples/lsa/main/main.c index 9c9fdf5..861cc54 100644 --- a/examples/lsa/main/main.c +++ b/examples/lsa/main/main.c @@ -37,15 +37,13 @@ static const char* TAG = "LSA_READINGS"; void app_main(void) { // enable line sensor - ESP_ERROR_CHECK(enable_line_sensor()); - - //Union containing line sensor readings + adc_handle_t adc_handle; + ESP_ERROR_CHECK(enable_line_sensor(&adc_handle)); line_sensor_array line_sensor_readings; - - while(1) + while (1) { // get line sensor readings - line_sensor_readings = read_line_sensor(); + line_sensor_readings = read_line_sensor(adc_handle); for(int i = 0; i < 5; i++) { // constrain lsa readings between BLACK_MARGIN and WHITE_MARGIN @@ -58,6 +56,5 @@ void app_main(void) // log final lsa readings ESP_LOGI(TAG, "LSA_0: %d \t LSA_1: %d \t LSA_2: %d \t LSA_3: %d \t LSA_4: %d",line_sensor_readings.adc_reading[0], line_sensor_readings.adc_reading[1], line_sensor_readings.adc_reading[2], line_sensor_readings.adc_reading[3], line_sensor_readings.adc_reading[4]); - } -} +} \ No newline at end of file diff --git a/include/adc.h b/include/adc.h index d2f2a84..a4c2538 100644 --- a/include/adc.h +++ b/include/adc.h @@ -27,9 +27,11 @@ #include #include +#include -#include "driver/adc.h" -#include "esp_adc_cal.h" +#include "esp_adc/adc_oneshot.h" +#include "esp_adc/adc_cali.h" +#include "esp_adc/adc_cali_scheme.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -39,36 +41,25 @@ #include "esp_err.h" #include "pin_defs.h" -#define DEFAULT_VREF 1100 +#define ADC_ATTEN ADC_ATTEN_DB_11 -/** - * @brief Configure width and attenuation of ADC 1 - * - * @return esp_err_t - returns ESP_OK if 11dB attenuation and 12 bit width configured to ADC 1, else it returns ESP_ERR_INVALID_ARG. - **/ -esp_err_t config_adc1(); +//define a struct that holds the adc1 handle and calibration handles for five channels in an array +typedef struct +{ + adc_oneshot_unit_handle_t adc1_handle; + adc_cali_handle_t adc1_cali_handle[5]; + bool do_calib[5]; +} adc_obj_t; -/** - * @brief Characterize ADC 1 using either Vref or Two Point - * - * @return esp_err_t - **/ -esp_err_t characterize_adc1(); +typedef adc_obj_t* adc_handle_t; /** * @brief call function config_adc1() and characterize_adc1(). * * @return esp_err_t - returns ESP_OK if Configuration and Characterization of adc1 is successful, else it returns ESP_ERR_INVALID_ARG. **/ -esp_err_t enable_adc1(); +esp_err_t enable_adc1(adc_obj_t** adc_obj); -/** - * @brief Read raw adc value of given adc pin. - * - * @param adc_pin One of the GPIO pin to which LSA is connected (36/39/35/34) - * - * @return esp_err_t -returns raw reading of adc pin if lsa pin is passed to function, else it returns ESP_ERR_INVALID_ARG. - **/ -int read_adc(int adc_pin); +int read_adc(adc_handle_t adc_handle, int gpio); #endif diff --git a/include/lsa.h b/include/lsa.h index 47da841..fea468a 100644 --- a/include/lsa.h +++ b/include/lsa.h @@ -52,7 +52,7 @@ typedef union line_sensor_array * @return esp_err_t i.e it shows if adc is initialised successfully or not **/ -esp_err_t enable_line_sensor(); +esp_err_t enable_line_sensor(adc_handle_t *adc_handle); /** * @brief Get multisampled line sensor array readings @@ -62,6 +62,6 @@ esp_err_t enable_line_sensor(); * @return Returns a pointer to a struct that contains multisampled adc readings for all the pins specified in lsa_pins array **/ -line_sensor_array read_line_sensor(); +line_sensor_array read_line_sensor(adc_handle_t adc_handle); #endif diff --git a/include/sra_board.h b/include/sra_board.h index f055f25..8ca69f1 100644 --- a/include/sra_board.h +++ b/include/sra_board.h @@ -40,4 +40,4 @@ #include "oled.h" #endif -#endif \ No newline at end of file +#endif diff --git a/src/adc.c b/src/adc.c index f06d528..97f0101 100644 --- a/src/adc.c +++ b/src/adc.c @@ -24,82 +24,143 @@ #include "adc.h" -static const char *TAG_ADC = "adc"; +static const char *TAG = "adc"; +static const int adc_io[5] = {LSA_A0, LSA_A1, LSA_A2, LSA_A3, LSA_A4}; -esp_err_t config_adc1() +esp_err_t config_adc1(adc_obj_t *adc_obj) { - // Configure ADC to 12 bit width - CHECK(adc1_config_width(ADC_WIDTH_BIT_12)); - - // Configure ADC to 11dB attenuation - CHECK(adc1_config_channel_atten(ADC_CHANNEL_4, ADC_ATTEN_DB_11)); - CHECK(adc1_config_channel_atten(ADC_CHANNEL_7, ADC_ATTEN_DB_11)); - CHECK(adc1_config_channel_atten(ADC_CHANNEL_6, ADC_ATTEN_DB_11)); - CHECK(adc1_config_channel_atten(ADC_CHANNEL_3, ADC_ATTEN_DB_11)); - CHECK(adc1_config_channel_atten(ADC_CHANNEL_0, ADC_ATTEN_DB_11)); - - ESP_LOGI(TAG_ADC, "Configured ADC_1 to 12 Bit and 11dB attenuation"); + adc_oneshot_chan_cfg_t config = { + .bitwidth = ADC_BITWIDTH_12, + .atten = ADC_ATTEN, + }; + ESP_LOGI(TAG, "ADC1 handle address: %p", adc_obj->adc1_handle); + //assign channels to each io in adc_io + for (int i = 0; i < sizeof(adc_io) / sizeof(adc_io[0]); i++) + { + adc_channel_t channel; + adc_unit_t unit; + ESP_ERROR_CHECK(adc_oneshot_io_to_channel(adc_io[i], &unit, &channel)); + ESP_ERROR_CHECK(adc_oneshot_config_channel(adc_obj->adc1_handle, channel, &config)); + } return ESP_OK; } -esp_err_t characterize_adc1() +static bool adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle) { - esp_adc_cal_characteristics_t adc_chars; - esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, &adc_chars); + adc_cali_handle_t handle = NULL; + esp_err_t ret = ESP_FAIL; + bool calibrated = false; - if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) - { - ESP_LOGI(TAG_ADC, "eFuse Two Point: Supported"); - ESP_LOGI(TAG_ADC, "Characterized using Two Point Value"); +#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED + if (!calibrated) { + ESP_LOGI(TAG, "calibration scheme version is %s", "Curve Fitting"); + adc_cali_curve_fitting_config_t cali_config = { + .unit_id = unit, + .chan = channel, + .atten = atten, + .bitwidth = ADC_BITWIDTH_12, + }; + ret = adc_cali_create_scheme_curve_fitting(&cali_config, &handle); + if (ret == ESP_OK) { + calibrated = true; + } } - else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) - { - ESP_LOGI(TAG_ADC, "eFuse Vref: Supported"); - ESP_LOGI(TAG_ADC, "Characterized using eFuse Vref"); +#endif + +#if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED + if (!calibrated) { + ESP_LOGI(TAG, "calibration scheme version is %s", "Line Fitting"); + adc_cali_line_fitting_config_t cali_config = { + .unit_id = unit, + .atten = atten, + .bitwidth = ADC_BITWIDTH_12, + }; + ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle); + if (ret == ESP_OK) { + calibrated = true; + } } - else +#endif + + *out_handle = handle; + if (ret == ESP_OK) { + ESP_LOGI(TAG, "Calibration Success"); + } else if (ret == ESP_ERR_NOT_SUPPORTED || !calibrated) { + ESP_LOGW(TAG, "eFuse not burnt, skip software calibration"); + } else { + ESP_LOGE(TAG, "Invalid arg or no memory"); + } + + return calibrated; +} + +esp_err_t calib_init(adc_obj_t *adc_obj) +{ + for (int i = 0; i < sizeof(adc_io) / sizeof(adc_io[0]); i++) { - ESP_LOGI(TAG_ADC, "Characterized using Default Vref"); + adc_channel_t channel; + adc_unit_t unit; + ESP_ERROR_CHECK(adc_oneshot_io_to_channel(adc_io[i], &unit, &channel)); + adc_obj->do_calib[i] = adc_calibration_init(ADC_UNIT_1, channel, ADC_ATTEN, &adc_obj->adc1_cali_handle[i]); } return ESP_OK; } -esp_err_t enable_adc1() +esp_err_t enable_adc1(adc_obj_t** adc_obj) { - CHECK(config_adc1()); - CHECK(characterize_adc1()); - - ESP_LOGI(TAG_ADC, "Configured and Characterized adc 1"); + adc_obj_t *ret = NULL; + ret = calloc(1, sizeof(adc_obj_t)); + ESP_ERROR_CHECK(ret == NULL ? ESP_ERR_NO_MEM : ESP_OK); + adc_oneshot_unit_init_cfg_t init_config1 = { + .unit_id = ADC_UNIT_1, + }; + ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &ret->adc1_handle)); + ESP_LOGI(TAG, "Handle address: %p", ret->adc1_handle); + config_adc1(ret); + calib_init(ret); + //assign return value to adc_handle + *adc_obj = ret; return ESP_OK; } -int read_adc(int adc_pin) +int read_adc(adc_handle_t adc_handle, int gpio) { - if (adc_pin == LSA_A0) - { - return adc1_get_raw(ADC_CHANNEL_4); - } - else if (adc_pin == LSA_A1) - { - return adc1_get_raw(ADC_CHANNEL_7); - } - else if (adc_pin == LSA_A2) - { - return adc1_get_raw(ADC_CHANNEL_6); - } - else if (adc_pin == LSA_A3) + int adc_reading = 0; + int voltage = 0; + adc_channel_t channel; + adc_unit_t unit; + ESP_ERROR_CHECK(adc_oneshot_io_to_channel(gpio, &unit, &channel)); + ESP_ERROR_CHECK(adc_oneshot_read(adc_handle->adc1_handle, channel, &adc_reading)); + int arr_loc = 0; + switch (gpio) { - return adc1_get_raw(ADC_CHANNEL_3); + case LSA_A0: + arr_loc = 0; + break; + case LSA_A1: + arr_loc = 1; + break; + case LSA_A2: + arr_loc = 2; + break; + case LSA_A3: + arr_loc = 3; + break; + case LSA_A4: + arr_loc = 4; + break; + default: + break; } - else if (adc_pin == LSA_A4) + if (adc_handle->do_calib[arr_loc]) { - return adc1_get_raw(ADC_CHANNEL_0); + ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_handle->adc1_cali_handle[arr_loc], adc_reading, &voltage)); + return voltage; } else { - ESP_LOGE(TAG_ADC, "Invalid adc pin"); - return ESP_FAIL; + return adc_reading; } } diff --git a/src/lsa.c b/src/lsa.c index a0a84ed..d9fde05 100644 --- a/src/lsa.c +++ b/src/lsa.c @@ -26,13 +26,13 @@ static const int line_sensor_pins[5] = {LSA_A0, LSA_A1, LSA_A2, LSA_A3, LSA_A4}; -esp_err_t enable_line_sensor() +esp_err_t enable_line_sensor(adc_handle_t *adc_handle) { - esp_err_t err = enable_adc1(line_sensor_pins); - return err; + ESP_ERROR_CHECK(enable_adc1(adc_handle)); + return ESP_OK; } -line_sensor_array read_line_sensor() +line_sensor_array read_line_sensor(adc_handle_t adc_handle) { line_sensor_array line_sensor_readings; @@ -45,7 +45,7 @@ line_sensor_array read_line_sensor() { for (int j = 0; j < 5; j++) { - line_sensor_readings.adc_reading[j] = line_sensor_readings.adc_reading[j] + read_adc(line_sensor_pins[j]); + line_sensor_readings.adc_reading[j] = line_sensor_readings.adc_reading[j] + read_adc(adc_handle, line_sensor_pins[j]); } } From bac73bcf62e7a022e86f94c965106bda0f85b819 Mon Sep 17 00:00:00 2001 From: Zain Date: Mon, 29 Jan 2024 00:44:13 +0530 Subject: [PATCH 3/7] Changes requested in PR #89 --- include/adc.h | 21 ++++++++++++++++----- include/sra_board.h | 2 +- src/adc.c | 3 --- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/adc.h b/include/adc.h index a4c2538..622356a 100644 --- a/include/adc.h +++ b/include/adc.h @@ -27,7 +27,6 @@ #include #include -#include #include "esp_adc/adc_oneshot.h" #include "esp_adc/adc_cali.h" @@ -43,12 +42,17 @@ #define ADC_ATTEN ADC_ATTEN_DB_11 -//define a struct that holds the adc1 handle and calibration handles for five channels in an array + +/** + * @brief Structure representing an ADC object. + * + * This structure holds the handles and calibration data for an ADC. + */ typedef struct { - adc_oneshot_unit_handle_t adc1_handle; - adc_cali_handle_t adc1_cali_handle[5]; - bool do_calib[5]; + adc_oneshot_unit_handle_t adc1_handle; /**< Handle for ADC1 oneshot unit. */ + adc_cali_handle_t adc1_cali_handle[5]; /**< Array of calibration handles for ADC1. */ + bool do_calib[5]; /**< Array indicating whether calibration should be performed for each channel. */ } adc_obj_t; typedef adc_obj_t* adc_handle_t; @@ -60,6 +64,13 @@ typedef adc_obj_t* adc_handle_t; **/ esp_err_t enable_adc1(adc_obj_t** adc_obj); +/** + * @brief Reads the adc value from the GPIO(channel) specified. + * + * @param adc_handle_t adc_handle - pointer to adc object. + * @param int gpio - gpio pin number of the channel to be read. + * @return int - returns the adc value read from the channel. + **/ int read_adc(adc_handle_t adc_handle, int gpio); #endif diff --git a/include/sra_board.h b/include/sra_board.h index 8ca69f1..f055f25 100644 --- a/include/sra_board.h +++ b/include/sra_board.h @@ -40,4 +40,4 @@ #include "oled.h" #endif -#endif +#endif \ No newline at end of file diff --git a/src/adc.c b/src/adc.c index 97f0101..00c3df6 100644 --- a/src/adc.c +++ b/src/adc.c @@ -33,7 +33,6 @@ esp_err_t config_adc1(adc_obj_t *adc_obj) .bitwidth = ADC_BITWIDTH_12, .atten = ADC_ATTEN, }; - ESP_LOGI(TAG, "ADC1 handle address: %p", adc_obj->adc1_handle); //assign channels to each io in adc_io for (int i = 0; i < sizeof(adc_io) / sizeof(adc_io[0]); i++) { @@ -116,10 +115,8 @@ esp_err_t enable_adc1(adc_obj_t** adc_obj) .unit_id = ADC_UNIT_1, }; ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &ret->adc1_handle)); - ESP_LOGI(TAG, "Handle address: %p", ret->adc1_handle); config_adc1(ret); calib_init(ret); - //assign return value to adc_handle *adc_obj = ret; return ESP_OK; From ee78f8761d2b0fbf9cbd9012646c3820b19a594f Mon Sep 17 00:00:00 2001 From: Zain Date: Mon, 29 Jan 2024 00:44:43 +0530 Subject: [PATCH 4/7] Update ADC attenuation value to ADC_ATTEN_DB_12, as per ESP-IDF 5.1.2 --- include/adc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/adc.h b/include/adc.h index 622356a..756ae7f 100644 --- a/include/adc.h +++ b/include/adc.h @@ -40,7 +40,7 @@ #include "esp_err.h" #include "pin_defs.h" -#define ADC_ATTEN ADC_ATTEN_DB_11 +#define ADC_ATTEN ADC_ATTEN_DB_12 /** From d0f41cc8181cf94e8ccbfa1818e36722d290a416 Mon Sep 17 00:00:00 2001 From: Zain Date: Tue, 30 Jan 2024 15:10:11 +0530 Subject: [PATCH 5/7] Updated ADC Attenuation --- include/adc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/adc.h b/include/adc.h index 756ae7f..622356a 100644 --- a/include/adc.h +++ b/include/adc.h @@ -40,7 +40,7 @@ #include "esp_err.h" #include "pin_defs.h" -#define ADC_ATTEN ADC_ATTEN_DB_12 +#define ADC_ATTEN ADC_ATTEN_DB_11 /** From b2422637238ccb614793563f0ca9c76ff22485fa Mon Sep 17 00:00:00 2001 From: Zain Date: Thu, 1 Feb 2024 16:05:15 +0530 Subject: [PATCH 6/7] Update ADC bitwidth length and fix I2C driver reconfiguration --- include/adc.h | 4 ++-- src/adc.c | 8 ++++---- src/i2cdev.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/adc.h b/include/adc.h index 622356a..1777739 100644 --- a/include/adc.h +++ b/include/adc.h @@ -41,7 +41,7 @@ #include "pin_defs.h" #define ADC_ATTEN ADC_ATTEN_DB_11 - +#define ADC_BITWIDTH_LEN ADC_BITWIDTH_12 /** * @brief Structure representing an ADC object. @@ -55,7 +55,7 @@ typedef struct bool do_calib[5]; /**< Array indicating whether calibration should be performed for each channel. */ } adc_obj_t; -typedef adc_obj_t* adc_handle_t; +typedef adc_obj_t *adc_handle_t; /** * @brief call function config_adc1() and characterize_adc1(). diff --git a/src/adc.c b/src/adc.c index 00c3df6..fbd4417 100644 --- a/src/adc.c +++ b/src/adc.c @@ -30,10 +30,10 @@ static const int adc_io[5] = {LSA_A0, LSA_A1, LSA_A2, LSA_A3, LSA_A4}; esp_err_t config_adc1(adc_obj_t *adc_obj) { adc_oneshot_chan_cfg_t config = { - .bitwidth = ADC_BITWIDTH_12, + .bitwidth = ADC_BITWIDTH_LEN, .atten = ADC_ATTEN, }; - //assign channels to each io in adc_io + // Assign channels to each io in adc_io for (int i = 0; i < sizeof(adc_io) / sizeof(adc_io[0]); i++) { adc_channel_t channel; @@ -58,7 +58,7 @@ static bool adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_att .unit_id = unit, .chan = channel, .atten = atten, - .bitwidth = ADC_BITWIDTH_12, + .bitwidth = ADC_BITWIDTH_LEN, }; ret = adc_cali_create_scheme_curve_fitting(&cali_config, &handle); if (ret == ESP_OK) { @@ -73,7 +73,7 @@ static bool adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_att adc_cali_line_fitting_config_t cali_config = { .unit_id = unit, .atten = atten, - .bitwidth = ADC_BITWIDTH_12, + .bitwidth = ADC_BITWIDTH_LEN, }; ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle); if (ret == ESP_OK) { diff --git a/src/i2cdev.c b/src/i2cdev.c index 17c3e3d..196ec50 100644 --- a/src/i2cdev.c +++ b/src/i2cdev.c @@ -197,7 +197,7 @@ static esp_err_t i2c_setup_port(const i2c_dev_t *dev) esp_err_t res; if (!cfg_equal(&dev->cfg, &states[dev->port].config)) { - ESP_LOGD(TAG, "Reconfiguring I2C driver on port %d", (int)dev->port); + ESP_LOGD(TAG, "Reconfiguring I2C driver on port %d", dev->port); i2c_config_t temp; memcpy(&temp, &dev->cfg, sizeof(i2c_config_t)); temp.mode = I2C_MODE_MASTER; From 5dccd425ee9738dac993e51ce15bcca0d75ffafe Mon Sep 17 00:00:00 2001 From: Zain Date: Thu, 1 Feb 2024 16:06:50 +0530 Subject: [PATCH 7/7] Fix I2C driver configuration logging --- src/i2cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i2cdev.c b/src/i2cdev.c index 196ec50..b21047a 100644 --- a/src/i2cdev.c +++ b/src/i2cdev.c @@ -222,7 +222,7 @@ static esp_err_t i2c_setup_port(const i2c_dev_t *dev) states[dev->port].installed = true; memcpy(&states[dev->port].config, &temp, sizeof(i2c_config_t)); - ESP_LOGD(TAG, "I2C driver successfully reconfigured on port %d", (int)dev->port); + ESP_LOGD(TAG, "I2C driver successfully reconfigured on port %d", dev->port); } #if HELPER_TARGET_IS_ESP32 int t;