From 9554492db1fe5091f52ffcb1bd2ccdcfd42534f5 Mon Sep 17 00:00:00 2001 From: RudideC Date: Fri, 13 Mar 2026 13:03:07 +0100 Subject: [PATCH 1/2] esto fuciona --- .../BREDA-main/BREDA/Almacenamiento.ino | 16 +++++++++--- BREDA-main/BREDA-main/BREDA/BREDA.ino | 2 +- BREDA-main/BREDA-main/BREDA/Config.h | 6 +++-- BREDA-main/BREDA-main/BREDA/Funciones.ino | 26 +++++++++---------- BREDA-main/BREDA-main/BREDA/Termopares.ino | 23 +++++++++++----- BREDA-main/BREDA-main/BREDA/Transductor.ino | 5 ++-- BREDA-main/Esp_relay/ordenador/ordenador.ino | 2 +- BREDA-main/Esp_relay/relay/relay.ino | 22 +++++++++++----- 8 files changed, 67 insertions(+), 35 deletions(-) diff --git a/BREDA-main/BREDA-main/BREDA/Almacenamiento.ino b/BREDA-main/BREDA-main/BREDA/Almacenamiento.ino index c5c1753..578e796 100644 --- a/BREDA-main/BREDA-main/BREDA/Almacenamiento.ino +++ b/BREDA-main/BREDA-main/BREDA/Almacenamiento.ino @@ -44,6 +44,7 @@ void SD_file_open() file_select_name(); String newName = String(file_number) + file_data_name; + String newName2 = String(file_number) + file_pressure_name; Serial.println("Abriendo archivo..."); if (!file_data.open(newName.c_str(), O_RDWR | O_CREAT)) @@ -72,6 +73,8 @@ void SD_file_open() RB_data.begin(&file_data); Serial.println("RingBuf iniciado"); // ... + + // el archivo de presión no lo necesitamos, en cualquier caso sería lo mismo que el de datos normales pero con sus propias variables #endif } @@ -110,10 +113,10 @@ void SD_file_data_update() // Cell data RB_data.print(", "); - RB_data.print(thrust, 5); + RB_data.print(thrust, DEC); // DEC == 10, base decimal // Transducer data (Average) - RB_data.print(", "); + /* if (transducer_counter > 0) { RB_data.print(transducer_avg / transducer_counter, 5); @@ -121,7 +124,12 @@ void SD_file_data_update() else { RB_data.print(0.0, 5); - } + }*/ + + // Transducer data (NO Average) + RB_data.print(", "); + RB_data.print(pressure, DEC); // la función print con ints determina base, no decimales + transducer_avg = 0; transducer_counter = 0; @@ -131,7 +139,7 @@ void SD_file_data_update() RB_data.print(tempADC[i]); } - for (int i = 0; i < 14; ++i) + for (int i = 0; i < 9; ++i) { RB_data.print(", "); RB_data.print(tempTP[i]); diff --git a/BREDA-main/BREDA-main/BREDA/BREDA.ino b/BREDA-main/BREDA-main/BREDA/BREDA.ino index aaac12a..0a9cb4e 100644 --- a/BREDA-main/BREDA-main/BREDA/BREDA.ino +++ b/BREDA-main/BREDA-main/BREDA/BREDA.ino @@ -129,7 +129,7 @@ void setup() ADC_config(ADC1, false); ADC_config(ADC2, false); - ADC_config(ADC3, false); + ADC_config(ADC3, true); ADC_config(ADC4, true); performance_started(); diff --git a/BREDA-main/BREDA-main/BREDA/Config.h b/BREDA-main/BREDA-main/BREDA/Config.h index 7337dcf..b235fbb 100644 --- a/BREDA-main/BREDA-main/BREDA/Config.h +++ b/BREDA-main/BREDA-main/BREDA/Config.h @@ -128,10 +128,11 @@ const float TP_const = ((vref / int24max) * 1000000) / 4; // constante para esca volatile float tempTP[14] = {0}; // array que almacena las temperaturas de los termopares volatile int32_t tempTP_raw[14] = {0}; // array que almacena las temperaturas de los termopares volatile float tempADC[4] = {0}; // array que almacena las temperaturas de los ADC -volatile float thrust = 0; // almacena el valor del empuje +volatile int32_t thrust = 0; // almacena el valor del empuje +volatile int32_t prev_thrust = 1; // almacena el valor del empuje anterior // File -String general_file_header = "Time, Thrust, Pressure, ADC1_Temp, ADC2_Temp, ADC3_Temp, ADC4_Temp, TP_1, TP_2, TP_3, TP_4, TP_5, TP_6, TP_7, TP_8, TP_9, TP_10, TP_11, TP_12, TP_13, TP_14"; +String general_file_header = "Time, Thrust, Pressure, ADC1_Temp, ADC2_Temp, ADC3_Temp, ADC4_Temp, TP_1, TP_2, TP_3, TP_4, TP_5, TP_6, TP_7, TP_8, TP_9"; String pressure_file_header = "Time, Chamber_Pressure, Raw_Transducer"; uint8_t file_number = 0; @@ -158,6 +159,7 @@ volatile uint32_t transducer_counter_offset = 0; volatile uint32_t transducer_freq = 0; volatile int16_t transducer_raw = 0; +volatile int16_t pressure = 0; volatile float transducer_avg = 0; volatile float transducer_pressure = 0; diff --git a/BREDA-main/BREDA-main/BREDA/Funciones.ino b/BREDA-main/BREDA-main/BREDA/Funciones.ino index 1e2eb4d..9ad34d9 100644 --- a/BREDA-main/BREDA-main/BREDA/Funciones.ino +++ b/BREDA-main/BREDA-main/BREDA/Funciones.ino @@ -37,25 +37,25 @@ void send_sensor_data() // Timestamp en milisegundos (4 bytes - uint32_t) uint32_t timestamp = millis(); - memcpy(&buffer[idx], ×tamp, 4); - idx += 4; + memcpy(&buffer[idx], ×tamp, sizeof(timestamp)); + idx += sizeof(timestamp); - // Thrust/Empuje (2 bytes - multiplicar × 100 para 2 decimales) - int16_t thrust_int = (int16_t)(thrust * 100.0f); - memcpy(&buffer[idx], &thrust_int, 2); - idx += 2; + // Thrust/Empuje (4 bytes - multiplicar × 100 para 2 decimales) + int32_t thrust_int = (int32_t)(thrust * 100.0f); + memcpy(&buffer[idx], &thrust_int, sizeof(thrust_int)); + idx += sizeof(thrust_int); - // 10 Temperaturas de termopares (20 bytes - multiplicar × 100) - for (int i = 0; i < 10; i++) + // 9 Temperaturas de termopares (18 bytes - multiplicar × 100) + for (int i = 0; i < 9; i++) { int16_t temp_int = (int16_t)(tempTP[i] * 100.0f); - memcpy(&buffer[idx], &temp_int, 2); - idx += 2; + memcpy(&buffer[idx], &temp_int, sizeof(temp_int)); + idx += sizeof(temp_int); } - // Transductor raw (2 bytes - dato crudo del ADC) - memcpy(&buffer[idx], &transducer_raw, 2); - idx += 2; + // Transductor presión (2 bytes - dato crudo del ADC) + memcpy(&buffer[idx], &pressure, sizeof(pressure)); + idx += sizeof(pressure); interrupts(); diff --git a/BREDA-main/BREDA-main/BREDA/Termopares.ino b/BREDA-main/BREDA-main/BREDA/Termopares.ino index 9f8c530..28a947b 100644 --- a/BREDA-main/BREDA-main/BREDA/Termopares.ino +++ b/BREDA-main/BREDA-main/BREDA/Termopares.ino @@ -38,18 +38,18 @@ float TP_polynom(int32_t raw) { // ADC Configuration //------------------------------------------------- -void ADC_config(MCP3564& adc, bool ID_ADC4) { +void ADC_config(MCP3564& adc, bool especial) { uint8_t conf[1]; // Configuro el registro 1 (Pag 92 de la data sheet) - if (ID_ADC4) - conf[0] = B00011000; // ADC4 tiene menos Oversampling porque no tiene tanta velocidad de reloj + if (especial) + conf[0] = B00011100; // ADC4 tiene menos Oversampling porque no tiene tanta velocidad de reloj else conf[0] = B00100000; adc.writeReg(conf, MCP3564_ADR_CONFIG1); // Configuro el registro 2 (Pag 93 de la data sheet) - conf[0] = B10011001; + conf[0] = B10011011; adc.writeReg(conf, MCP3564_ADR_CONFIG2); // Configuro el registro 3 (Pag 94 de la data sheet) @@ -62,7 +62,7 @@ void ADC_config(MCP3564& adc, bool ID_ADC4) { // Configuro el registro del modo SCAN (Pag 97 de la data sheet) uint16_t channelMask = 0; - if (ID_ADC4) + if (especial) channelMask = B00011011 << 8; // ADC4 no tiene el CH4-CH5 activado else channelMask = B00011111 << 8; @@ -118,7 +118,7 @@ void ADC2_IRQ() { // declara la funcion de lectura del IRQ tempTP_raw[chID + 4] = temp; tempTP[chID + 4] = TP_polynom(temp) + tempADC[0]; } -} +} void ADC3_IRQ() { // declara la funcion de lectura del IRQ @@ -130,6 +130,15 @@ void ADC3_IRQ() { // declara la funcion de lectura del IRQ if (chID == 4) // temperatura interna tempADC[2] = internalTemp_const * vref * temp - 269.13; // guarda la temperatura del ADC1 en la posición primera del array + else if (chID == 1) { // celula de carga + temp = ((temp + 320.85) / 218.10) * 9.81; + if (prev_thrust != 0) { + thrust = int32_t((temp + prev_thrust) / 2); + }else { + thrust = temp; + } + prev_thrust = temp; + } else { tempTP_raw[chID + 8] = temp; @@ -147,8 +156,10 @@ void ADC4_IRQ() { // declara la funcion de lectura del IRQ if (chID == 4) // temperatura interna tempADC[3] = internalTemp_const * vref * temp - 269.13; // guarda la temperatura del ADC1 en la posición primera del array + /* else if (chID == 3) // celula de carga thrust = temp; + */ else { tempTP_raw[chID + 12] = temp; diff --git a/BREDA-main/BREDA-main/BREDA/Transductor.ino b/BREDA-main/BREDA-main/BREDA/Transductor.ino index a2833ed..885cb04 100644 --- a/BREDA-main/BREDA-main/BREDA/Transductor.ino +++ b/BREDA-main/BREDA-main/BREDA/Transductor.ino @@ -45,8 +45,9 @@ void transducer_measure() ++transducer_counter_offset; } - transducer_pressure = (transducer_raw - transducer_offset) * transducer_const; - + //transducer_pressure = (transducer_raw - transducer_offset) * transducer_const; + pressure = transducer_raw; + transducer_avg += transducer_pressure; ++transducer_counter; ++transducer_freq; diff --git a/BREDA-main/Esp_relay/ordenador/ordenador.ino b/BREDA-main/Esp_relay/ordenador/ordenador.ino index 24edead..a1eb140 100644 --- a/BREDA-main/Esp_relay/ordenador/ordenador.ino +++ b/BREDA-main/Esp_relay/ordenador/ordenador.ino @@ -6,7 +6,7 @@ #define ERROR_PIN 13 #define BUFFER_SIZE 30 -uint8_t relayMAC[] = {0x08, 0xD1, 0xF9, 0xCE, 0x16, 0x14}; // 08:d1:f9:ce:16:14 +uint8_t relayMAC[] = {0xD4, 0xE9, 0xF4, 0xF9, 0x32, 0x18}; // d4:e9:f4:f9:32:18 typedef struct { uint8_t sync1; diff --git a/BREDA-main/Esp_relay/relay/relay.ino b/BREDA-main/Esp_relay/relay/relay.ino index 89cb1f5..166e3ba 100644 --- a/BREDA-main/Esp_relay/relay/relay.ino +++ b/BREDA-main/Esp_relay/relay/relay.ino @@ -1,13 +1,14 @@ #include #include #include -#include +#include #define ERROR_PIN 13 #define PIN_IGNICION 33 #define COMANDO_IGNICION 0x04 +#define IGNICION_DURACION_MS 5000 -uint8_t ordenadorMAC[] = {0x94, 0xE6, 0x86, 0x44, 0x9E, 0xC4}; +uint8_t ordenadorMAC[] = {0xD4, 0xE9, 0xF4, 0xFA, 0xA2, 0xF4}; typedef struct { uint8_t sync1; @@ -20,8 +21,10 @@ typedef struct { } PacketComando; PacketData paquete; -volatile bool paquete_listo = false; -volatile bool enviar_ahora = false; +volatile bool paquete_listo = false; +volatile bool enviar_ahora = false; +volatile bool ignicion_activa = false; +unsigned long ignicion_tiempo = 0; void IRAM_ATTR timer_callback(void* arg) { enviar_ahora = true; @@ -41,6 +44,8 @@ void onDataRecv(const esp_now_recv_info *recv_info, const uint8_t *incomingData, if (cmd.comando == COMANDO_IGNICION) { digitalWrite(PIN_IGNICION, HIGH); + ignicion_activa = true; + ignicion_tiempo = millis(); } else { Serial.write(cmd.comando); } @@ -79,10 +84,15 @@ void setup() { }; esp_timer_handle_t timer_handle; esp_timer_create(&timer_args, &timer_handle); - esp_timer_start_periodic(timer_handle, 12500); + esp_timer_start_periodic(timer_handle, 12500); } void loop() { + if (ignicion_activa && (millis() - ignicion_tiempo >= IGNICION_DURACION_MS)) { + digitalWrite(PIN_IGNICION, LOW); + ignicion_activa = false; + } + if (Serial.available() >= 2) { uint8_t byte1 = Serial.read(); @@ -116,7 +126,7 @@ void loop() { paquete.sync1 = 0xFE; paquete.sync2 = 0xFB; - paquete_listo = true; + paquete_listo = true; } if (enviar_ahora) { From 92f6c9b3d5f2104ea4d2a415f603db233548a64f Mon Sep 17 00:00:00 2001 From: RudideC Date: Fri, 27 Mar 2026 12:49:08 +0100 Subject: [PATCH 2/2] led 2 + cambios sd --- BREDA-main/BREDA-main/BREDA/BREDA.ino | 14 ++++++++++++-- BREDA-main/BREDA-main/BREDA/Config.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/BREDA-main/BREDA-main/BREDA/BREDA.ino b/BREDA-main/BREDA-main/BREDA/BREDA.ino index 0a9cb4e..677c00c 100644 --- a/BREDA-main/BREDA-main/BREDA/BREDA.ino +++ b/BREDA-main/BREDA-main/BREDA/BREDA.ino @@ -143,19 +143,24 @@ void loop() if (RB_data.bytesUsed() >= 512 && !file_data.isBusy()) { RB_data.writeOut(512); + flush_counter++; } #if TRANSDUCER == 1 if (RB_pressure.bytesUsed() >= 512 && !file_pressure.isBusy()) { RB_pressure.writeOut(512); + flush_counter++; } #endif - if (++flush_counter >= 5000) + if (flush_counter >= 100) { flush_counter = 0; file_data.flush(); + digitalWrite(PIN_LED_RED, HIGH); + LED2_status = true; + LED2_millis = millis(); #if TRANSDUCER == 1 file_pressure.flush(); #endif @@ -186,10 +191,15 @@ void loop() } // Turns on and off the led each second - if (millis() > LED_time + LED_timer) + if (millis() > (LED_time + LED_timer)) { LED_time = millis(); LED_status = !LED_status; digitalWrite(PIN_LED_GREEN, LED_status); } + if ((millis() > (LED2_millis + LED_timer)) && LED2_status) + { + LED2_status = false; + digitalWrite(PIN_LED_RED, LOW); + } } diff --git a/BREDA-main/BREDA-main/BREDA/Config.h b/BREDA-main/BREDA-main/BREDA/Config.h index b235fbb..db8e2e2 100644 --- a/BREDA-main/BREDA-main/BREDA/Config.h +++ b/BREDA-main/BREDA-main/BREDA/Config.h @@ -90,6 +90,8 @@ uint32_t serial_timer = 1000; uint32_t transducer_timer = 200; uint32_t transducer_timerOffset = 0; uint32_t LED_timer = 500; +unsigned long LED2_millis; +bool LED2_status = false; // Performance bool performance_status = false;