Closed tux-at-chello closed 1 year ago
An ESP32 has 3 hardware uarts and esphome doesn't support software serial on it. Previously, you could only use uart0 if you use the default pins (1 and 3), but that was fixed in the latest release, so if you upgrade esphome, it should work now.
Hello,
I did some testing today and found an error message on the serial debug port with the esphome version 2023.4.4 :
[15:44:26][I][app:029]: Running through setup()...
[15:44:26][C][uart.arduino_esp32:077]: Setting up UART...
[15:44:26][C][uart.arduino_esp32:077]: Setting up UART...
[15:44:26][C][uart.arduino_esp32:077]: Setting up UART...
[15:44:26][ 68][E][HardwareSerial.cpp:309] begin(): Serial number is invalid, please use numers from 0 to 2
After upgrading to version 2023.5.1 and recompiling the code the message changed into :
[I][app:029]: Running through setup()...
[C][uart.arduino_esp32:077]: Setting up UART...
[C][uart.arduino_esp32:077]: Setting up UART...
[C][uart.arduino_esp32:077]: Setting up UART...
[W][uart.arduino_esp32:104]: Maximum number of UART components created already.
[E][component:113]: Component uart was marked as failed.
Even after I changed the tx and rx pins to GPIO1 and GPIO3 ( the debug port ) for the third UARD definition. So software-serial is ( still ) not implemented in esphome version 2023.5.1 and we are limited to two ports?
Sorry for the mess: this issue is still open !
You have to disable the serial logging. There is no plan to add software serial to ESP32, there are 3 uarts available.
In the past we used an Arduino Mega with an ethernet shield an 3 comports to interface 3 PZEM004T V1.0 modules and an Arduino based self written program to transfer data from a 3 phase solar panel array into a crestron controller to generate some data and graphs about the production of this 40 panel solar array.
Now in the days of ESPHome and Home Assistant we decided to convert these measuring modules over to an WT32-ETH01 module, just for the reason of multiple serial ports and intergrated ethernet, making it a hard wired interface and avoiding WiFi traffic at a high load due to the frequent repeat of the measurements.
For this purpose I defined 3 serial ports on the WT32-ETH01, using the 'receive only' ports as the RX ports of the construction, leading up to the following layout.
Phase L1 : TX data on GPIO 17, RX data on GPIO05 Phase L2 : TX data on GPIO 13, RX data on GPIO35 Phase L3 : TX data on GPIO 15, RX data on GPIO36
Standard TX0 and RX0 are left free, to be able to program the unit via serial protocol in case the ethernet interface fails and 'OTE' ( over the Ethernet ) is not available.
For testing purposes I have 2 push buttons to ground on GPIO2 and GPIO4 to have some inputs to play around with ( and testing connectivity to ESPhome ) in further projects.
This gives me the following YAML file.
For testing I only have one PZEM004T V1.0 module available and this one is connected to GPIO17 and GPIO 5
What I see and measure is that if this module is configured at the 3rd defined uart, 'uart_bus_L3', is does not work properly, as when it is defined at 'uart_bus_L1' or 'uart_bus_L2' the module starts responding data immediately. You can see that I tested with the several com poorts using the '#' to enable or disable the different GPIO pins on the board.
I connected a TTL to USB serial converter on the RX data of the GPIO05 to see the response received from the PZEM004T module on the differend uart definitions and found the following:
If defined to the first or second uart defined, the module gets all the 4 required request out of the TX data and responds accordingly, making it a working module for ESPHome and reporting the 'voltage', 'current', 'power' and 'energy' telegrams as requested.
On the serial interface I receive in decimal the following data out of the PZEM004 module: 160 0 236 7 0 0 147 161 0 0 0 0 0 161 162 0 0 0 0 0 162 163 114 60 25 0 0 105
Where 160 ( 0xA0 ) is measured voltage and 163 ( 0xA03 ) is registered Wh of this module. ( yes these panels were active over there : 7.486.489 Wh ! and this ony one phase ...)
If defined to the third uart ( uart_bus_L3 ) the software only transmits the 'voltage' request to the PZEM004 module: this responds accordingly and reports the measured voltage. Due to the fact that not all 4 telegrams are answered, ESPHome does not send this single response to Home Automation, thereby declaring this interface 'not working'.
On the seial interface I receive in decimal the following data : 160 0 236 7 0 0 147 160 0 237 3 0 0 144 160 0 237 1 0 0 143 160 0 236 9 0 0 149
where '160' is 'answer voltage' ( Hex 0xA0 ) followed by the measured voltage of 236.7 Volt.
If I swap the uart sub definition of 'uart_bus_L2' and 'uart_bus_L3' making L3 the second uart definition on GPIO17 and GPIO05, this port is fully operational.
The 'esphome run PZEM.yaml' compiles without any error in any configuration and the log of the WT32-ETH01 at boot when connecting to HA show the GPIO lines as defined in the YAML file : that part works fine in all configurations.
We now assume after several days of testing and debugging that there is something going wrong in defining the 3rd uart on the software and therefore the PZEM software module for this serial port is not working properly.
esphome is upgraded to version 2023.4.4 last night and code is compiled to this version.
After changing the GPIO17 and GPIO05 to uart_bus_L1 is works directly:
Question : are we doing anything illegal to the WTH32-ETH01 or is anything else causing this problem ?
Kind regards from an enthousiastic group of 4 out of The Netherlands.