Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe only 2 UARTS are needed #38

Open
Geo-Ron opened this issue Sep 22, 2024 · 3 comments
Open

Maybe only 2 UARTS are needed #38

Geo-Ron opened this issue Sep 22, 2024 · 3 comments

Comments

@Geo-Ron
Copy link

Geo-Ron commented Sep 22, 2024

In your code in ESP32 Pellet Stove wit mods.yaml I noticed you have 2 UARTS defined.

  • One for reading the TX pin of the interconnect between display and main MCU
  • One for reading the RX ping of the interconnect.

Since the UART debugging can be done in BOTH directions (as specified in ESPHOME UARTS Debugging, I propose the following code(change) to combine 2 UART definitions into only one:

#
# define 2 hardware UARTS, 1 for TuyaMCU, other for MCU Display & temps monitoring
#
uart: 
#communication from TuyaMCU to tywe1s chip UART1
  - id: tywe1s_uart
    rx_pin: RX # Receives data from MCU, RX label on ESP32
    tx_pin: TX # Transmits data to MCU, TX label on ESP32
    baud_rate: 9600
#Display message decoding UART2
  - id: mcu_uart_comms
    tx_pin: GPIO16 #attach new wire to TX labled pin on DISPLAY board
    rx_pin: GPIO21 #attach new wire to RX labled pin on DISPLAY board
    baud_rate: 2400
    rx_buffer_size: 80
    debug:
      direction: BOTH #this is the MAIN change
      dummy_receiver: true ## maybe this can be returned to false???
      after:
        delimiter: [0xCC, 0x33]
      sequence:
        - lambda: |-
            UARTDebug::log_hex(direction, bytes, ' ');             
            //Still log the data     
            //Some packets have 5 bytes  
            //might have to make this 3 if delimitar bytes get removed....

            if (bytes.size()==5) {
                if(bytes[0]==0xAA && bytes[1]==0x00) {
                if(bytes[2]==0x20)
                  id(MCUrawString).publish_state("Welcome to use");    
                if(bytes[2]==0x6A)
                  id(MCUrawString).publish_state("Goodbye!");              
                if(bytes[2]==0x69)
                  id(MCUrawString).publish_state("Cleaning");
                if(bytes[2]==0x63)
                  id(MCUrawString).publish_state("Cleaning");
                if(bytes[2]==0x65)
                  id(MCUrawString).publish_state("Lighting");
                if(bytes[2]==0x66)
                  id(MCUrawString).publish_state("Stabilization");
                if(bytes[2]==0x62)
                  id(MCUrawString).publish_state("Switching OFF");
                //if(bytes[2]==0x??) 
                  //id(MCUrawString).publish_state("Cooling");                                 
              }              
            }
            //Some packets have 6 bytes
            if (bytes.size()==6) {
              if(bytes[1]==0x01 && bytes[2]==0x46 && bytes[3]==0x02) 
                id(MCUrawString).publish_state("Welcome to use"); 
                //AA:00:59:CC:33
              if(bytes[1]==0x01 && bytes[2]==0x46 && bytes[3]==0x02) 
                id(MCUrawString).publish_state("Switching off");                 
              if(bytes[1]==0x01 && bytes[2]==0x49 && bytes[3]==0x80) 
                id(MCUrawString).publish_state("Stabilization"); 
              if(bytes[1]==0x01 && bytes[2]==0x49 && bytes[3]==0x00) 
                id(MCUrawString).publish_state("Stabilization"); 
              if(bytes[1]==0x01 && bytes[2]==0x49 && bytes[3]==0x81) 
                id(MCUrawString).publish_state("ECO2"); 
              if(bytes[1]==0x01 && bytes[2]==0x48 && bytes[3]==0x80) 
                id(MCUrawString).publish_state("ECO1"); 
              if(bytes[1]==0x01 && bytes[2]==0x48 && bytes[3]==0xC0) 
                id(MCUrawString).publish_state("Idling - ECO2"); 
              if(bytes[1]==0x01 && bytes[2]==0x49 && bytes[3]==0x01) 
                id(MCUrawString).publish_state("Idling - ECO2"); 
              if(bytes[1]==0x01 && bytes[2]==0x48 && bytes[3]==0x83) 
                id(MCUrawString).publish_state("ECO1"); 
              if(bytes[1]==0x01 && bytes[2]==0x48 && bytes[3]==0xC3) 
                id(MCUrawString).publish_state("ECO2"); 
              if(bytes[1]==0x01 && bytes[2]==0x49 && bytes[3]==0x81) 
                id(MCUrawString).publish_state("Idling - ECO2");  
            }

            //from Display control board RX pin to MCU board RX pin UART3
            //gives us real time exhaust pipe temps in middle byte
            //the full string-> the 7th HEX has the value I want(B8): AA:05:4B:00:00:26:B8:26:CC:33

            if (bytes.size()==10) {               
              // works up to approx 275 then it goes wonky somehow needing -72 instead of -36
              //but who cares, we only need stable values to stoke the fire
              id(pipe_converted).publish_state(((bytes[6]) * 1.8) - 4.0);          
            }     
@jazzmonger
Copy link
Owner

Have at it! I was just happy I finally got everything working the way it was. I spent countless days with the devs getting this working. I'm sure there are many other ways to do it. If you can also get a better handle on decoding the screen messages, that will be a big improvement, especially after a recovery on reboot or power failure.

@Geo-Ron
Copy link
Author

Geo-Ron commented Sep 22, 2024

Have at it! I was just happy I finally got everything working the way it was. I spent countless days with the devs getting this working. I'm sure there are many other ways to do it. If you can also get a better handle on decoding the screen messages, that will be a big improvement, especially after a recovery on reboot or power failure.

Will do, if I get things wired up!

@Geo-Ron Geo-Ron closed this as completed Sep 23, 2024
@jazzmonger
Copy link
Owner

Btw, my Discord username is @jazzmonger
I lurk in HA, ESPHome & other channels
https://discord.gg/Tf3jatQa

@jazzmonger jazzmonger reopened this Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants