ESP32 - HardwareSerial, change Rx pin periodically
Posted: Sat Jun 29, 2024 6:12 am
Hello,
I am in France. We have electricity counters with serial outputs for data.
I have 3 of those counters, for which I want to collect the data using an ESP32
My software works ok for those 3 counters, individually or by 2 (using uart1 and uart2), I am using the HardwareSerial library.
I initially wanted to also use UART0 to collect the 3rd counter, but it seems not so simple (maybe have to go through bootloader modification to be able to use UART0 for my purpose (and using other pins that the default 1 & 3).
Anyway, I decided to only use UART1 and UART2 as 1 of the counter needs to be monitored all the time, but for the 2 others, 1 is only required during the day, and the other during the night.
I only need the Rx Pin on those counters as I can only read data.
I have :
1) main counter : GPIO 16 - UART1 - all the time
2) photovoltaic counter : GPIO 26 - UART2 - day
3) water heater counter : GPIO 15 - UART2 - night
in my software, creating and configuring any of those inputs works, I can receive data
but when the SW switches counter (on UART2) : no more data from UART2.
init :
...
this->port = new HardwareSerial(UART_nbr);
this->port->begin(baudrate, TIC_PROTOCOL, RX_pin);
...
=> this works ok with any of my 3 inputs, and any of the 2 UART 1 or 2.
What my "changeInput" code looks like (only the relevant part - of course baudrate & RX_pin values are different)
...
this->port->end();
this->port->begin(baudrate, TIC_PROTOCOL, RX_pin);
...
After this "changeInput" is executed, no more data from the UART.
I also tried to add a delay(1000); between the "end" and consecutive begin, no more result.
I also tried for "changeInput"
...
delete this->port;
this->port = new HardwareSerial(UART_nbr);
this->port->begin(baudrate, TIC_PROTOCOL, RX_pin);
...
=> No more result.
Any idea of what I am doing wrong and how I should handle this ?
Btw, I am updating/debugging the ESP32 over wifi therefore not really needing the Serial of UART0 for that purpose.
Thanks for any help
I am in France. We have electricity counters with serial outputs for data.
I have 3 of those counters, for which I want to collect the data using an ESP32
My software works ok for those 3 counters, individually or by 2 (using uart1 and uart2), I am using the HardwareSerial library.
I initially wanted to also use UART0 to collect the 3rd counter, but it seems not so simple (maybe have to go through bootloader modification to be able to use UART0 for my purpose (and using other pins that the default 1 & 3).
Anyway, I decided to only use UART1 and UART2 as 1 of the counter needs to be monitored all the time, but for the 2 others, 1 is only required during the day, and the other during the night.
I only need the Rx Pin on those counters as I can only read data.
I have :
1) main counter : GPIO 16 - UART1 - all the time
2) photovoltaic counter : GPIO 26 - UART2 - day
3) water heater counter : GPIO 15 - UART2 - night
in my software, creating and configuring any of those inputs works, I can receive data
but when the SW switches counter (on UART2) : no more data from UART2.
init :
...
this->port = new HardwareSerial(UART_nbr);
this->port->begin(baudrate, TIC_PROTOCOL, RX_pin);
...
=> this works ok with any of my 3 inputs, and any of the 2 UART 1 or 2.
What my "changeInput" code looks like (only the relevant part - of course baudrate & RX_pin values are different)
...
this->port->end();
this->port->begin(baudrate, TIC_PROTOCOL, RX_pin);
...
After this "changeInput" is executed, no more data from the UART.
I also tried to add a delay(1000); between the "end" and consecutive begin, no more result.
I also tried for "changeInput"
...
delete this->port;
this->port = new HardwareSerial(UART_nbr);
this->port->begin(baudrate, TIC_PROTOCOL, RX_pin);
...
=> No more result.
Any idea of what I am doing wrong and how I should handle this ?
Btw, I am updating/debugging the ESP32 over wifi therefore not really needing the Serial of UART0 for that purpose.
Thanks for any help