logo elektroda
logo elektroda
X
logo elektroda

ESP32 communication with PZEM-004T V3.0 via UART0 or UART1 - Guru Meditation Error

globalinfo 3156 16
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19389549
    globalinfo
    Level 13  
    Hello,
    I am trying to communicate via ESP32 with PZEM-004T V3.0 via UART0 or UART1 and I fail to download the data and a reset occurs
    Quote:
    Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
    .
    I connect via UART2 without a problem.
    Below is the code I send to the ESP32.
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 19390006
    khoam
    Level 42  
    Serial, i.e. Serial0 may not "work" because it is also connected to the USB bridge on the ESP32 board and is used for monitoring in the above code.
    What specific ESP32 board do you have and which GPIO do you use when using Serial1?
  • #3 19390167
    globalinfo
    Level 13  
    khoam wrote:
    Serial, i.e. Serial0 may not "work" because it is also connected to the USB bridge on the board with the ESP32 and in the above code is used for monitoring.
    Which ESP32 board specifically do you have and which GPIO do you use when using Serial1?
    .
    ESP-WROM-32
    ESP32 communication with PZEM-004T V3.0 via UART0 or UART1 - Guru Meditation Error
    Serial1 is pins 9 -TX1 and 10-RX1

    Is it possible to change the pins in this program?
    I tried changing the pins to 23 and 22 - the LEDs blink, so some communication is there, but it doesn't display the results.
    Code: C / C++
    Log in, to see the code
    .
    Quote:
    Error reading voltage
    Error reading current
    Error reading power
    Error reading energy
    Error reading frequency
    Error reading power factor
  • #4 19390364
    khoam
    Level 42  
    Generally this can be done, but unfortunately in the PZEM004Tv30 library the HardwareSerial.begin() function is called with the default pin values for the selected Serial - in the case of Serial1 these are 9/10. GPIO 9 and 10 are connected in the ESP32 to the internal flash memory, so Serial1 without changing the default pins for it will not work.

    Added after 11 [minutes]: .

    globalinfo wrote:
    I tried changing the pins to 23 and 22 - the LEDs blink, so some communication is there, but it doesn't display the results.
    .
    You can still try it this way:
    Code: C / C++
    Log in, to see the code
    The Serial2.end() command should "clear" the previous pin assignments that the constructor makes:
    Code: C / C++
    Log in, to see the code
    .
    The same for Serial1 can be done.
  • #5 19390381
    globalinfo
    Level 13  
    On the UATR2 it works fine with one PZEM004T.
    How can data be read over this port with 2 PZEM004Ts on ESP32

    Added after 8 [minutes]: .

    khoam wrote:
    Generally this can be done, but unfortunately in the PZEM004Tv30 library the HardwareSerial.begin() function is called with default pin values for the selected Serial - in the case of Serial1 these are 9/10. GPIO 9 and 10 are connected to internal flash memory in the ESP32, so Serial1 without changing the default pins for it will not work.

    Added after 11 [minutes]: .

    globalinfo wrote:
    I tried changing the pins to 23 and 22 - the LEDs blink, so some communication is there, but it doesn't display results.
    .
    You can still try this way:
    Code: C / C++
    Log in, to see the code
    The Serial2.end() command should "clear" the previous pin assignments that the constructor makes:
    Code: C / C++
    Log in, to see the code
    .
    The same for Serial1 can be done.

    Code: C / C++
    Log in, to see the code
    .
    The effect is the same:
    Quote:
    Error reading voltage
    Error reading current
    Error reading power
    Error reading energy
    Error reading frequency
    Error reading power factor

    I don't know what to do next.
    How do I insert
    Code: C / C++
    Log in, to see the code
    .
    it works.
    Quote:
    Voltage: 238.10V
    Current: 0.07A
    Power: 0.90W
    Energy: 0.029kWh
    Frequency: 50.0Hz
    PF: 0.05
    .

    Added after 8 [hours] 36 [minutes]: .

    Is it possible that via UATR2 it is possible to read data from two PZEM004T V3 on ESP32.
    I can see that this is the only way since the data is read correctly .
    Can someone suggest because I have run out of ideas. :( .
  • ADVERTISEMENT
  • #6 19390576
    xury
    Automation specialist
    Tasmota does this so it can be done. I myself have connected three PZEM's to one ESP. You can take a look at the Tasmota or Espeasa code.
  • ADVERTISEMENT
  • #7 19390734
    globalinfo
    Level 13  
    xury wrote:
    Tasmota does this so it is possible. I myself have connected three PZEM's to one ESP. You can take a look at the Tasmota or Espeasa code.

    I'm not familiar with this, I'm a beginner and working in the Arduino IDE.
  • Helpful post
    #8 19390835
    khoam
    Level 42  
    globalinfo wrote:
    Is it possible to read data from two PZEM004T V3 on ESP32 via UATR2.
    .
    No. You need two UARTs. One UART for one PZEM monitor.
    I suggest you carry out an experiment. Attached is a package with modified PZEM004Tv30.cpp and PZEM004Tv30.h files. You need to swap them with the original ones from the PZEM004Tv30 library.
    Then the initialisation of the constructors can look for example like this:
    Code: C / C++
    Log in, to see the code
    Monitor pzem1 is handled by pins 22 and 23 (RX1 and TX1)
    The monitor pzem2 is supported by pins 16 and 17 (default RX2 and TX2).
    End()/begin() "tricks" are no longer needed.
  • #9 19391220
    globalinfo
    Level 13  
    khoam wrote:
    globalinfo wrote:
    Is it possible that via UATR2 you can read data from two PZEM004T V3 on ESP32.
    .
    No. You need two UARTs. One UART for one PZEM monitor.
    I suggest you carry out an experiment. Attached is a package with modified PZEM004Tv30.cpp and PZEM004Tv30.h files. You need to swap them with the original ones from the PZEM004Tv30 library.
    Then the initialisation of the constructors can look for example like this:
    Code: C / C++
    Log in, to see the code
    Monitor pzem1 is handled by pins 22 and 23 (RX1 and TX1)
    The monitor pzem2 is supported by pins 16 and 17 (default RX2 and TX2).
    No more "tricks" with end()/begin() are needed.


    Thank you very much it works flawlessly. :please: :please: :please: :spoko: .
    Now I still need to embrace the 3.5" TFT
    Code: C / C++
    Log in, to see the code

    and a power regulator with a '0' transition + four relays and a thermometer - maybe I won't run out of pins :shocked!:
    ESP32 communication with PZEM-004T V3.0 via UART0 or UART1 - Guru Meditation Error

    ESP32 communication with PZEM-004T V3.0 via UART0 or UART1 - Guru Meditation Error
  • #10 19391359
    khoam
    Level 42  
    globalinfo wrote:
    Now I still need to embrace the TFT 3.5"
    .
    What library are you using? What display is it specifically?
  • #11 19391467
    globalinfo
    Level 13  
    khoam wrote:
    What library are you using? what specific display is it?
    .

    TFT_eSPI library - 3.5 inch 320*480 serial SPI TFT display with LCD optical module - IC driver ILI9341 for MCU
    ESP32 communication with PZEM-004T V3.0 via UART0 or UART1 - Guru Meditation Error .
    The display works without problem, but when I add a reading from PZEM it resets for me.
    I have changed the TFT_CS to different pins but the effect is the same.
  • #12 19391825
    khoam
    Level 42  
    globalinfo wrote:
    The display works without a problem, but when I add a reading from PZEM it resets.
    .
    There must be a conflict in pin selection between TFT (SPI) and Serial. Which User_Setup for TFT are you using (the one indicated in User_Setup_Select.h)?
    The SPI pins on the ESP32 can be mapped to virtually any pins.
  • ADVERTISEMENT
  • #13 19392034
    globalinfo
    Level 13  
    khoam wrote:
    globalinfo wrote:
    Which User_Setup for TFT are you using (the one indicated in User_Setup_Select.h)?
    The SPI pins on the ESP32 can be mapped to virtually any pins.
    .

    In User_Setup I made the changes it was working with before I added PZEM :

    Code: C / C++
    Log in, to see the code
    .
    For PZEM I set:

    Code: C / C++
    Log in, to see the code
    .
  • #14 19392072
    khoam
    Level 42  
    MOSI is on pin 23, CS is on pin 17.
    TX1 is on pin 23, TX2 is on pin 17 unless you used different pins than what is shown in post #9.
  • #15 19392076
    globalinfo
    Level 13  
    khoam wrote:
    MOSI is on pin 23. CS is on pin 17.
    TX1 is on pin 23, TX2 is on pin 17 unless you used different pins than what is shown in post #9.
    .
    Code: C / C++
    Log in, to see the code
    .
  • #16 19392095
    khoam
    Level 42  
    I'm assuming you change the pin for CS to something other than 17. Try commenting out the pzem1 declaration first, then just pzem2 and see what happens.

    Added after 19 [minutes]: .

    globalinfo wrote:
    Display works without problem, but when I add a reading from the PZEM it resets for me.

    Is the display or ESP resetting? Install the Exception Stack Trace Decoder plugin into the Arduino IDE - then it will be clear where in the code the problem is. Link
  • #17 19395818
    globalinfo
    Level 13  
    khoam wrote:
    Display or ESP resets?
    .
    ESP resets.
    Strange thing I agonised over it and let it go for a day.
    Today the CS I plugged in on the 14th and it works.
    I don't know what to think about it -(maybe something wasn't making contact).

Topic summary

The discussion revolves around the challenges faced when attempting to communicate between an ESP32 and a PZEM-004T V3.0 using UART0 or UART1, resulting in resets and failures to retrieve data. The user successfully communicates via UART2 but encounters issues with UART1 due to default pin assignments (GPIO 9 and 10) being connected to the internal flash memory. Suggestions include changing pin assignments and using the Serial.end() and Serial.begin() methods to reset configurations. A solution was proposed involving modified library files to allow multiple PZEM devices to be connected simultaneously. The user later reported success after adjusting the chip select (CS) pin for a TFT display, which had previously caused resets when combined with the PZEM readings.
Summary generated by the language model.
ADVERTISEMENT