Dear community!
I hope you're doing all well.
I'm programming an ESP32 using the Arduino Ide. For some reason, the code on which I'm working now does not speak over the serial port (the serial monitor of the ide doesn't show never anything), but when I use the standard analog.read example, the serial communication works perfectly. I'm posting both codes below.
Do anybody see any difference that may cause this?
To be precise, I'm using the <Ticker.h> lib in my code and put it also into the analog.read example to use the timer interrupt function, to see if perhaps it was the problem.
Perhaps I will have to do the same by trying to use the "uRTCLib.h" to see if the problem is there...
As you can see in the analog.read example, the problem does not appear to lie in the usage of Serial.println or Serial.printf.
I double checked the things I think are obvious: correct baud rate on PC and ESP32, that the device is properly connected, etc.
Thank you very much!!!
Code that works:
#include <Ticker.h>
Ticker timer;
void setup() {
Serial.begin(115200);
analogReadResolution(12); //set the resolution to 12 bits (0-4095)
timer.attach(5, ejecutarSubrutina); // 300 segundos = 5 minutos
}
void loop() {
}
void ejecutarSubrutina() {
Serial.println("Ejecutando subrutina cada 5 seg");
int analogValue = analogRead(2);
int analogVolts = analogReadMilliVolts(2);
// print out the values you read:
Serial.printf("ADC analog value = %d\n", analogValue);
Serial.printf("ADC millivolts value = %d\n", analogVolts);
delay(100); // delay in between reads for clear read from serial
}
The code that don't want to write anything over the serial:
#include "uRTCLib.h"
#include <Ticker.h>
Ticker timer;
uRTCLib rtc;
//rtc.set(0, 42, 16, 6, 2, 5, 15);
// RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year), rtc.refresh();*/
const byte luz_Activo = 2; // Aquí es donde se definden los números de salida o entrada de cada cosa.
const byte luz_Error = 15;
const byte luz_Vacaciones = 1;
const byte selector_Actividad = 1;
const byte bomba_carga = 4;
const byte soplador = 5;
const byte valvula_difusor = 18;
const byte valvula_descarga_clarificado = 19;
const byte valvula_descarga_lodos = 21;
const byte valvula_4 = 22;
bool FlagCargaR1, FlagDecantacionR1, FlagEvacuacionR1, FlagOxigenacionR1, FlagAnoxiaR1, FlagCargaR2, FlagDecantacionR2, FlagEvacuacionR2, FlagOxigenacionR2, FlagAnoxiaR2;
bool Programa; // true: modo activo. false: modo vacaciones.
int paso,contador_ejecutar_secuencia=0,temp,hora_actual,minuto_actual;
void estado_general();
void ejecutar_secuencia();
void setup() {
Serial.begin(115200);
pinMode(luz_Activo,OUTPUT);
pinMode(luz_Error,OUTPUT);
pinMode(luz_Vacaciones,OUTPUT);
pinMode(selector_Actividad,INPUT);
pinMode(bomba_carga,OUTPUT);
pinMode(soplador,OUTPUT);
pinMode(valvula_difusor,OUTPUT);
pinMode(valvula_descarga_clarificado,OUTPUT);
pinMode(valvula_descarga_lodos,OUTPUT);
pinMode(valvula_4,OUTPUT);
Serial.printf("Inicio ------------------------------- %d\n");
timer.attach(5, estado_general); // 5 segundos
}
void loop() {
}
void estado_general() {
/*temp=paso;
hora_actual = rtc.hour();
minuto_actual = rtc.minute();
paso=(hora_actual*60)+minuto_actual; // Se calcula lo que va del día en minutos.
if(paso>=5) paso=(paso/5)+1;
else paso=1;
if(paso!=temp) ejecutar_secuencia();*/
digitalWrite(luz_Activo, HIGH);
delay(100);
digitalWrite(luz_Activo, LOW);
contador_ejecutar_secuencia = contador_ejecutar_secuencia + 1;
if(contador_ejecutar_secuencia > 10) { // Cada 10 veces 5 segundos, ejecutar secuencia.
contador_ejecutar_secuencia = 0;
ejecutar_secuencia();
}
}
void ejecutar_secuencia() {
paso=paso+1;
Serial.printf("ES Paso: %d\n", paso);
//Serial.printf(", Time: ");
etc....