main.ino 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. #include "TinyGPSPlus.h"
  2. #include "DHT.h"
  3. #include <Wire.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Adafruit_SSD1306.h>
  6. #include "FS.h"
  7. #include "SD.h"
  8. #include "SPI.h"
  9. #include "Arduino.h"
  10. #include "math.h"
  11. #include "WiFi.h"
  12. #include "WebServer.h"
  13. /*
  14. Uncomment and set up if you want to use custom pins for the SPI communication
  15. #define REASSIGN_PINS
  16. int sck = -1;
  17. int miso = -1;
  18. int mosi = -1;
  19. int cs = -1;
  20. */
  21. // Inicia I2C en pines default ESP32 (21 SDA, 22 SCL)
  22. #define SCREEN_WIDTH 128 // Ancho píxeles
  23. #define SCREEN_HEIGHT 64 // Alto píxeles
  24. #define OLED_RESET -1 // Reset pin (no usado)
  25. // Pines para UART2 (Serial2)
  26. #define RX_PIN 16 // RX del ESP32 conectado a TX del GPS
  27. #define TX_PIN 17 // TX del ESP32 conectado a RX del GPS
  28. #define GPS_BAUD 115200
  29. #define DHTPIN 4 // Digital pin connected to the DHT sensor
  30. #define DHTTYPE DHT22
  31. #define BUTTON_PIN 27 // pin para pulsador
  32. //definicion de tiempos de pulsacion
  33. #define PULASCION_LARGA_MS 2000
  34. #define DURACION_WATCHDOG_MS 10000
  35. #define MEASUREMENT_INTERVAL_S 1 //separación entre mediciones (s)
  36. #define DEG2RAD (M_PI/180.0)
  37. // Objeto TinyGPS++
  38. TinyGPSPlus gps;
  39. HardwareSerial gpsSerial(2); // Usar UART2
  40. DHT dht(DHTPIN, DHTTYPE);
  41. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  42. //valores de los sensores
  43. struct SensorData {
  44. double latitude = 0.0;
  45. double longitude = 0.0;
  46. float altura = 0.0;
  47. String tiempo = "";
  48. float velocidad = 0.0;
  49. float temperature = 0.0;
  50. float humidity = 0.0;
  51. float pressure = 0.0;
  52. };
  53. SensorData latestData;
  54. SensorData datosAntiguos;
  55. SemaphoreHandle_t dataMutex; // Mutex para proteger el acceso a latestData
  56. SemaphoreHandle_t buttonSemaphore; // Semáforo para la tarea del botón
  57. WebServer server(80);
  58. bool wifiActivado = false;
  59. unsigned long wifiLastActivity = 0;
  60. const unsigned long WIFI_TIMEOUT_MS = 300000; // 5 minutos
  61. const char* apSSID = "ESP32_GPS_Logger";
  62. const char* apPassword = "12345678";
  63. bool grabando = false; //inicia apagado
  64. bool finalizado = true; //indica que no hay ninguna grabacion ni iniciada ni pausada
  65. TaskHandle_t medicionesHandle = NULL; //para suspend/resume
  66. int pantallaEstado_grab = -1; //maquina de estados cuando se graba ruta
  67. int pantallaEstado_menu = -1; //maquina de estados cuando no se esta grabando ruta
  68. float distancia_total = 0.0;
  69. volatile unsigned long ignore_isr_until = 0; //para debounce
  70. char filename[13] = "/panchas.gpx";
  71. void OLED_print(const String& line1, const String& line2) {
  72. display.clearDisplay();
  73. display.setTextSize(2);
  74. display.setTextColor(SSD1306_WHITE);
  75. display.setCursor(0, 0);
  76. display.println(line1);
  77. display.println(line2);
  78. display.display();
  79. }
  80. void DHT_test() {
  81. dht.begin();
  82. float h = dht.readHumidity();
  83. float t = dht.readTemperature();
  84. if (isnan(h) || isnan(t)) {
  85. Serial.println("Failed to read from DHT sensor!");
  86. OLED_print("DHT22", "Error");
  87. delay(5000);
  88. DHT_test(); // Reintentar
  89. }
  90. else OLED_print("DHT22", "Correcto");
  91. }
  92. void OLED_test() { //pantallazo a blanco y luego iniciando
  93. // Inicia I2C en pines default ESP32 (21 SDA, 22 SCL)
  94. Wire.begin();
  95. if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Dirección común: 0x3C
  96. Serial.println(F("Error: OLED no encontrado!"));
  97. for (;;); // Para siempre
  98. }
  99. display.clearDisplay();
  100. display.fillScreen(SSD1306_WHITE); // Pantalla blanca
  101. delay(500);
  102. display.display();
  103. display.clearDisplay();
  104. display.setTextSize(2); // Tamaño texto
  105. display.setTextColor(SSD1306_WHITE);
  106. display.setCursor(0, 0); // Posición
  107. display.println("Iniciando...");
  108. display.display(); // Muestra
  109. delay(1000);
  110. }
  111. void SD_test(){
  112. if (!SD.begin()) {
  113. OLED_print("SD Card", "Error\nInserte");
  114. while (!SD.begin());
  115. OLED_print("SD Card", "Insertada");
  116. } else {
  117. OLED_print("SD Card", "Correcto");
  118. }
  119. uint8_t cardType = SD.cardType();
  120. if (cardType == CARD_NONE) {
  121. OLED_print("SD Card", "No detectada");
  122. while (cardType == CARD_NONE) {
  123. delay(1000);
  124. cardType = SD.cardType();
  125. }
  126. OLED_print("SD Card", "Detectada");
  127. }
  128. uint8_t cardSize = SD.cardSize() / (1024 * 1024);
  129. }
  130. void GPS_test_wait() {
  131. // Iniciar Serial2 para GPS
  132. bool fixObtained = false;
  133. gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RX_PIN, TX_PIN);
  134. while (!fixObtained) {
  135. while (gpsSerial.available() > 0) {
  136. if (gps.encode(gpsSerial.read())) { // Procesa si hay sentencia NMEA completa
  137. if (gps.location.isValid() && gps.date.isValid() && gps.time.isValid()) {
  138. fixObtained = true;
  139. break;
  140. }
  141. }
  142. }
  143. delay(300);
  144. OLED_print("GPS", "Esperando");
  145. delay(300);
  146. OLED_print("GPS", "Esperando .");
  147. delay(300);
  148. OLED_print("GPS", "Esperando ..");
  149. delay(300);
  150. OLED_print("GPS", "Esperando ...");
  151. }
  152. OLED_print("GPS", "Encontrado");
  153. }
  154. float calcular_delta_dist(float lat1, float long1, float lat2, float long2){
  155. float R = 6371.0; // Radio de la Tierra en km
  156. float delta_lat = (lat2 - lat1) * DEG2RAD;
  157. float delta_long = (long2 - long1) * DEG2RAD;
  158. lat1 = lat1 * DEG2RAD;
  159. lat2 = lat2 * DEG2RAD;
  160. float a = sin(delta_lat/2)*sin(delta_lat/2)+cos(lat1)*cos(lat2)*sin(delta_long/2)*sin(delta_long/2);
  161. float c = 2 * atan2(sqrt(a),sqrt(1-a));
  162. return R * c; //En km
  163. }
  164. void task_mediciones(void *pvParameters) {
  165. TickType_t xLastWakeTime = xTaskGetTickCount();
  166. while(1) {
  167. // se leen los valores antes de utilizar el semaphore
  168. while (gpsSerial.available() > 0) {
  169. gps.encode(gpsSerial.read());
  170. }
  171. float new_latitude = gps.location.lat();
  172. float new_longitude = gps.location.lng();
  173. float new_altitude = gps.altitude.meters();
  174. String new_fecha = String(gps.date.year())+"-"+String(gps.date.month())+"-"+
  175. String(gps.date.day())+"T"+String(gps.time.hour())+":"+
  176. String(gps.time.minute())+":"+String(gps.time.second())+"."+
  177. String(gps.time.centisecond());
  178. float new_speed = gps.speed.kmph();
  179. float new_temp = dht.readTemperature();
  180. float new_hum = dht.readHumidity();
  181. float new_press = 0.0; // Placeholder, no hay sensor de presión
  182. if (gps.location.isValid() && datosAntiguos.latitude != 0.0) {
  183. distancia_total += calcular_delta_dist(datosAntiguos.latitude, datosAntiguos.longitude, new_latitude, new_longitude);
  184. }
  185. if (xSemaphoreTake(dataMutex, portMAX_DELAY) == pdTRUE) {
  186. latestData.latitude = new_latitude;
  187. latestData.longitude = new_longitude;
  188. latestData.altura = new_altitude;
  189. latestData.tiempo = new_fecha;
  190. latestData.velocidad = new_speed;
  191. latestData.temperature = new_temp;
  192. latestData.humidity = new_hum;
  193. latestData.pressure = new_press;
  194. datosAntiguos = latestData;
  195. xSemaphoreGive(dataMutex);
  196. }
  197. File file = SD.open(filename, FILE_APPEND);
  198. if (file) {
  199. //Crear la string para escribir en el archivo
  200. file.print(F("\t\t\t<trkpt lat=\""));
  201. file.print(datosAntiguos.latitude, 6);
  202. file.print(F("\" lon=\""));
  203. file.print(datosAntiguos.longitude, 6);
  204. file.println(F("\">"));
  205. file.print(F("\t\t\t\t<ele>"));
  206. file.print(datosAntiguos.altura);
  207. file.println(F("</ele>"));
  208. file.print(F("\t\t\t\t<time>"));
  209. file.print(datosAntiguos.tiempo);
  210. file.println(F("</time>"));
  211. file.print(F("\t\t\t\t<speed>"));
  212. file.print(datosAntiguos.velocidad);
  213. file.println(F("</speed>"));
  214. file.println(F("\t\t\t\t<extensions>"));
  215. file.println(F("\t\t\t\t\t<gpxtpx:TrackPointExtension>"));
  216. file.print(F("\t\t\t\t\t\t<gpxtpx:atemp>"));
  217. file.print(datosAntiguos.temperature);
  218. file.println(F("</gpxtpx:atemp>"));
  219. file.println(F("\t\t\t\t\t</gpxtpx:TrackPointExtension>"));
  220. file.print(F("\t\t\t\t\t<custom:humidity>"));
  221. file.print(datosAntiguos.humidity);
  222. file.println(F("</custom:humidity>"));
  223. file.print(F("\t\t\t\t\t<custom:pressure>"));
  224. file.print(datosAntiguos.pressure);
  225. file.println(F("</custom:pressure>"));
  226. file.println(F("\t\t\t\t</extensions>"));
  227. file.println(F("\t\t\t</trkpt>"));
  228. file.close();
  229. }
  230. vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(MEASUREMENT_INTERVAL_S*1000)); // Espera x*1000 milisegundos
  231. }
  232. }
  233. void crear_archivo(){
  234. distancia_total = 0.0;
  235. int num = 1;
  236. sprintf(filename, "/data%03d.gpx", num);
  237. while (SD.exists(filename)) {
  238. num++;
  239. sprintf(filename, "/data%03d.gpx", num);
  240. }
  241. File file = SD.open(filename, FILE_WRITE);
  242. if (file) {
  243. file.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  244. "<gpx creator=\"ESP32 GPS LOGGER\" version=\"1.1\"\n"
  245. "\txmlns=\"http://www.topografix.com/GPX/1/1\"\n"
  246. "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
  247. "\txmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v2\"\n"
  248. "\txmlns:gpxdata=\"http://www.cluetrust.com/XML/GPXDATA/1/0\"\n"
  249. "\txsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
  250. "\t<metadata>\n"
  251. "\t\t<name>Ruta grabada con ESP32 GPS Logger</name>\n"
  252. "\t\t<time>");
  253. file.print(String(gps.date.year()) + "-" + String(gps.date.month()) + "-" +
  254. String(gps.date.day()) + "T" + String(gps.time.hour()) + ":" +
  255. String(gps.time.minute()) + ":" + String(gps.time.second()) +
  256. "." + String(gps.time.centisecond()));
  257. file.println("</time>\n\t</metadata>\n"
  258. "\t<trk>\n"
  259. "\t\t<name>Rutita</name>\n"
  260. "\t\t<type>hiking</type>\n"
  261. "\t\t<trkseg>");
  262. file.close();
  263. } else {
  264. OLED_print("Error","creando archivo");
  265. delay(2000);
  266. }
  267. }
  268. void cerrar_archivo() {
  269. File file = SD.open(filename, FILE_APPEND);
  270. if (file){
  271. file.print("\t\t</trkseg>\n\t</trk>\n</gpx>");
  272. file.close();
  273. }
  274. //int num = 1;
  275. //sprintf(filename, "/data%03d.gpx", num);
  276. //while (SD.exists(filename)) {
  277. // num++;
  278. // sprintf(filename, "/data%03d.gpx", num);
  279. //}
  280. }
  281. void activarWiFi(){
  282. OLED_print("WiFi","Activando...");
  283. WiFi.mode(WIFI_AP);
  284. WiFi.softAP(apSSID, apPassword);
  285. IPAddress IP = WiFi.softAPIP();
  286. OLED_print("WiFi Activo", IP.toString());
  287. delay(2000);
  288. server.on("/", HTTP_GET, []() {
  289. wifiLastActivity = millis();
  290. String html = "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>ESP32 GPS Logger</title>";
  291. html += "<style>body{font-family:Arial;text-align:center;margin:50px;}";
  292. html += "h1{color:#333;} a.button{background:#4CAF50;color:white;padding:20px 40px;";
  293. html += "text-decoration:none;font-size:24px;border-radius:12px;display:inline-block;margin:20px;}</style></head>";
  294. html += "<body><h1>GPS Logger</h1><p>Archivo listo para descargar:</p>";
  295. String nombreArchivo = String(filename).substring(1); // Ej. "data001.gpx"
  296. html += "<a href='/download' class='button' download='" + nombreArchivo + "'>Descargar " + nombreArchivo + "</a>";
  297. html += "<hr><p>IP: " + WiFi.softAPIP().toString() + "</p>";
  298. html += "<p>Se apagar&aacute; en 5 min sin uso.</p></body></html>";
  299. server.send(200, "text/html", html);
  300. });
  301. server.on("/download",HTTP_GET, []() {
  302. wifiLastActivity = millis();
  303. if (!SD.exists(filename)) {
  304. server.send(404, "text/plain", "Archivo no encontrado");
  305. return;
  306. }
  307. File file = SD.open(filename, FILE_READ);
  308. if (!file) {
  309. server.send(404, "text/plain", "Error al abrir el archivo");
  310. return;
  311. }
  312. String nombreArchivo = String(filename).substring(1); // Ej. "data001.gpx"
  313. server.sendHeader("Content-Disposition", "attachment; filename=\"" + nombreArchivo + "\"");
  314. server.streamFile(file, "application/gpx+xml");
  315. file.close();
  316. });
  317. server.begin();
  318. wifiActivado = true;
  319. wifiLastActivity = millis();
  320. }
  321. void desactivarWiFi(){
  322. server.stop();
  323. WiFi.softAPdisconnect(true);
  324. WiFi.mode(WIFI_OFF);
  325. wifiActivado = false;
  326. OLED_print("WiFi","Apagado");
  327. }
  328. void IRAM_ATTR isr_button() {
  329. unsigned long now = millis();
  330. if (now < ignore_isr_until) {
  331. return; // Ignorar interrupción si está dentro del período de debounce
  332. }
  333. static unsigned long lastInterrupt = 0;
  334. if ((now - lastInterrupt) > 300 ){ // debounce de 300 ms
  335. BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  336. xSemaphoreGiveFromISR(buttonSemaphore, &xHigherPriorityTaskWoken);
  337. lastInterrupt = now;
  338. if (xHigherPriorityTaskWoken) {
  339. portYIELD_FROM_ISR();
  340. }
  341. }
  342. }
  343. void drawProgressBar(int x, int y, int w, int h, unsigned long progress, unsigned long total) {
  344. display.drawRect(x, y, w, h, SSD1306_WHITE); // Dibuja el borde
  345. int filledWidth = (progress * w) / total;
  346. display.fillRect(x + 1, y + 1, filledWidth - 2, h - 2, SSD1306_WHITE); // Dibuja la barra llena
  347. display.display();
  348. }
  349. void task_ui(void *pvParameters){
  350. unsigned long pressTime = 0;
  351. unsigned long lastActivity = millis();
  352. bool pantallaOn = true; //comprobar el estado inicial, no se cual sera
  353. bool processingButton = false;
  354. while(1){
  355. if (xSemaphoreTake(buttonSemaphore, pdMS_TO_TICKS(200)) == pdTRUE){ //button pressed
  356. if (processingButton) continue; //evita reentradas
  357. processingButton = true;
  358. pressTime = millis();
  359. lastActivity = millis(); //reset watchdog
  360. if (!pantallaOn){
  361. display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  362. pantallaOn = true;
  363. }
  364. bool timed_out = false;
  365. unsigned long checkTime = millis();
  366. while (digitalRead(BUTTON_PIN) == LOW){
  367. vTaskDelay(pdMS_TO_TICKS(10));
  368. checkTime = millis();
  369. if ((checkTime - pressTime) > DURACION_WATCHDOG_MS){ //10s timeout para evitar bloqueos
  370. timed_out = true;
  371. break;
  372. }
  373. drawProgressBar(0, SCREEN_HEIGHT - 10, SCREEN_WIDTH, 8, checkTime - pressTime, PULASCION_LARGA_MS);
  374. }
  375. ignore_isr_until = millis() + 500; //ignorar nuevas interrupciones durante 500 ms
  376. unsigned long duration = checkTime - pressTime;
  377. if (timed_out){
  378. OLED_print("Apagando","pantalla");
  379. display.ssd1306_command(SSD1306_DISPLAYOFF); //se apaga la
  380. pantallaOn = false;
  381. } else {
  382. if (grabando){
  383. if (duration >= PULASCION_LARGA_MS){
  384. grabando = false;
  385. vTaskSuspend(medicionesHandle);
  386. OLED_print("Ruta","pausada");
  387. } else {
  388. pantallaEstado_grab = (pantallaEstado_grab + 1) % 5; //cicla entre 0-4
  389. SensorData currentData;
  390. if(xSemaphoreTake(dataMutex, portMAX_DELAY) == pdTRUE){
  391. currentData = latestData;
  392. xSemaphoreGive(dataMutex);
  393. }
  394. switch (pantallaEstado_grab){
  395. case 0:
  396. OLED_print("Posicion",String(currentData.longitude) + "," + String(currentData.latitude));
  397. break;
  398. case 1:
  399. OLED_print("Distancia",String(distancia_total)+"km");
  400. break;
  401. case 2:
  402. OLED_print("Altitud",String(gps.altitude.meters(), 1)+"m");
  403. break;
  404. case 3:
  405. OLED_print("Temp/Hum",String(currentData.temperature,1)+"C/"+String(currentData.humidity,1)+"%");
  406. break;
  407. case 4:
  408. OLED_print("Velocidad",String(gps.speed.kmph())+"km/h");
  409. break;
  410. }
  411. }
  412. } else {
  413. if (duration >= PULASCION_LARGA_MS){
  414. switch (pantallaEstado_menu){
  415. case 0:
  416. //activar la ruta y crear el archivo
  417. crear_archivo();
  418. vTaskResume(medicionesHandle);
  419. OLED_print("Ruta","iniciada");
  420. finalizado = false;
  421. grabando = true;
  422. break;
  423. case 1:
  424. //cerrar el archivo y cambiar el valor de 'filename'
  425. cerrar_archivo();
  426. finalizado = true;
  427. break;
  428. case 2:
  429. //implementacion wifi
  430. if(!wifiActivado){
  431. activarWiFi();
  432. } else {
  433. desactivarWiFi();
  434. }
  435. break;
  436. }
  437. } else {
  438. pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
  439. int previous_state = -1;
  440. while (pantallaEstado_menu != previous_state) {
  441. previous_state = pantallaEstado_menu;
  442. switch (pantallaEstado_menu) {
  443. case 0:
  444. if (!finalizado) OLED_print("Reanudar","ruta");
  445. else OLED_print("Iniciar","ruta");
  446. break;
  447. case 1:
  448. if (SD.exists(filename) && !finalizado) {
  449. OLED_print("Finalizar","ruta");
  450. break;
  451. } else {
  452. pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
  453. }
  454. break;
  455. case 2:
  456. if (finalizado) {
  457. OLED_print("Conexion","WiFi");
  458. break;
  459. } else {
  460. pantallaEstado_menu = (pantallaEstado_menu + 1) % 3;
  461. }
  462. break;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. lastActivity = millis(); //reset watchdog
  469. processingButton = false;
  470. vTaskDelay(pdMS_TO_TICKS(100)); //pequeño delay para no busy waiting
  471. }
  472. //check watchdog fuera del boton
  473. if (pantallaOn && ((millis() - lastActivity) > DURACION_WATCHDOG_MS)){
  474. display.ssd1306_command(SSD1306_DISPLAYOFF); //se apaga la pantalla
  475. pantallaOn = false;
  476. }
  477. //check wifi timeout
  478. if (wifiActivado){
  479. server.handleClient();
  480. if (WiFi.softAPgetStationNum() > 0){
  481. wifiLastActivity = millis(); //reset si hay clientes conectados
  482. }
  483. if ((millis() - wifiLastActivity) > WIFI_TIMEOUT_MS){
  484. desactivarWiFi();
  485. }
  486. }
  487. }
  488. }
  489. void setup() {
  490. pinMode(BUTTON_PIN, INPUT_PULLUP);
  491. attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), isr_button, FALLING);
  492. buttonSemaphore = xSemaphoreCreateBinary();
  493. dataMutex = xSemaphoreCreateMutex();
  494. // OLED check
  495. OLED_test();
  496. delay(1000);
  497. // DHT check
  498. DHT_test();
  499. delay(1000);
  500. // SD Card check
  501. SD_test();
  502. delay(1000);
  503. // GPS check
  504. GPS_test_wait();
  505. delay(2000);
  506. // Crear tarea para mediciones
  507. xTaskCreatePinnedToCore(
  508. task_mediciones, // Función de la tarea
  509. "Mediciones", // Nombre de la tarea
  510. 8192, // Tamaño del stack
  511. NULL, // Parámetro de la tarea
  512. 10, // Prioridad de la tarea
  513. &medicionesHandle, // Handle de la tarea
  514. 0 // Núcleo donde se ejecuta
  515. );
  516. xTaskCreatePinnedToCore(
  517. task_ui, // Función de la tarea
  518. "UI", // Nombre de la tarea
  519. 8192, // Tamaño del stack
  520. NULL, // Parámetro de la tarea
  521. 5, // Prioridad de la tarea
  522. NULL, // Handle de la tarea
  523. 1 // Núcleo donde se ejecuta
  524. );
  525. vTaskSuspend(medicionesHandle); //inicia suspendida
  526. }
  527. void loop() {
  528. vTaskDelay(pdMS_TO_TICKS(1000)); // Espera 1 segundo
  529. }