UART Switch Help

Thanks,

Just tried that using both formats but with square brackets and same thing, not working :frowning:

I would connect the working arduino to a usb serial adapter an monitor with a pc what I get there. Then connect to the esp and do the same. You’ll quickly learn if you have software or hardware issues.

Have done that, the only difference is I don’t see line break from Arduino but when I send manually with keyboard I see it

If it is line break, you have a few options:
0x0A is LF
0x0D is CR

you can try

  • 0x0A, 0x0D
  • 0x0D, 0x0A
  • 0x0A
  • 0x0D,

however I think you did not answer my question, have you connected the ESP to a serial adapter and see if you get the command from the ESP when you trigger the action?

The right syntax is as @nickrout posted, don’t bother with the '0x80 ... ' syntax, that’s for strings

Can you share a picture with the hardware wirings?

+1 on this for doing a lot of serial control since ages, it depends of equipments controled so always better to try the 4 possibilities :wink:

I have indeed ruled out the hardware, see this screenshot

The first commands are from Arduino IDE, the tv responds, the long line is from ESPHome.

It’s typing out \r rather than entering a return.

It should just be CR, as the manual specifies it. But I have tried the others too…

It is impossible to give much advice without knowing exactly which yaml file you are using. You say you have tried lots of things, but I do not think you have shown us the file that corresponds to that test!

I’ll add, in the example you have given, you have only specified a tx_pin, not an rx_pin. Maybe the TV is balking at not being able to send data? (probably not!)

Pfff my eyes!!
Those ascii codes 0x80, 0x79 … are prefixed with 0x which means they are hexadecimal numbers.
Now if you want a P then and O the right numbers are 80, 79 etc. Decimal form. Check out an ascii table

I don’t know why it does not work in string form

I have tried all the formats mentioned in the post…

The tv doesn’t need to send data back, the test worked fine using a PC with only tx

So I can try using just the numbers without the 0x? This is the stuff I don’t know so I’ll try this !

I don’t know how to format the data…

You produced a specific output but we don’t know what produced that output. Hard to help.

@glmnet is right though (of course!). Either use hex, in which case P is 0x50, or decimal in which case P is 80 (no 0x in front.)

Carriage return is 0x0D hex, 13 decimal. See https://en.wikipedia.org/wiki/UTF-8#Codepage_layout

If you use hex, the format is documented in the esphome docs, and in my post above.

If you want to tell us that something does, or doesn’t, work please post the yaml file you are feeding to esphome. Please also tell us what esp device you are using.

Thank you all for your help!

Its finally working,

this is the code im running now:

esphome:
  name: sharptv
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: 'x'
  password: 'x'

api:

# Enable logging
logger:

ota:

mqtt:
  broker: 172.16.0.60
  username: rs232
  password: x

uart:
  baud_rate: 38400
  tx_pin: D4

switch:
  - platform: uart
    name: "Power On"
    data: [0x50, 0x4F, 0x57, 0x52, 0x20, 0x20, 0x20, 0x31, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/state
          payload: "ON"

  - platform: uart
    name: "Power Off"
    data: [0x50, 0x4F, 0x57, 0x52, 0x20, 0x20, 0x20, 0x30, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/state
          payload: "OFF"

  - platform: uart
    name: "HDMI 1"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x30, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "HDMI1"

  - platform: uart
    name: "HDMI 2"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x33, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "HDMI2"

  - platform: uart
    name: "HDMI 3"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x38, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "HDMI3"

I think it not working before might have had something to do with garbage left in the serial buffer?

after hooking up between TV and USB TTL a few times, I noticed it would respond after sending a few commands, i think it cleared out the leftover and then input the command again cleanly (sorry I dont know how to word it)

but thanks its working well now !

Now I just have to figure out how to send the value of an input number to the TV to adjust the volume…

Pleased you got it going.

There doesn’t seem to be an option for audio volume, which is a little odd, there is otherwise a good variety of controllable stuff on that TV - kudos to Sharp.

Are you actually listening on the TV or an external amp? May be asier to control the amp.

Also you may be able to control volume on the device which is plugged into the TV to provide your media. That is a bit vague isn’t it? An example: I use kodi for watching all my media. Even if I cannot control the TV volume, I can adjust the volume at the input level by controlling Kodi.

Oh man I swear there was a command for volume, ill check my other docs…

I listen through an external amp but it’s not controllable, it’s a date a2670 I think?

The thing playing is kinda possible but only for the android tv, there’s still the switch and side HDMI port I would love to control volume over just in case :thinking:

https://github.com/esphome/issues/issues/484

Opened an issue for ths string not sending the LF and CR

Have you been able to figure out how to make it RECEIVE information via serial?

Also, what was the outcome of the issue on github? Supposed to wrap data in double quotes? Not sure I understood that…