- 积分
- 926
- 金钱
- 731
- 威望
- 0
- 贡献
- 0
- HASS币
- 20
高级会员
- 积分
- 926
- 金钱
- 731
- HASS币
- 20
|
ESP32C3 接陶金驰串口屏,把编码器值通过串口发送给串口屏N0.val,串口屏需要发送字符格式加三个0xFF结束符,怎么把传感器的值转为字符串?
ESPHOME关键代码
sensor:
- platform: rotary_encoder
name: "Rotary Encoder"
pin_a: GPIO05
pin_b: GPIO08
publish_initial_value: True
min_value: 1
max_value: 100
id: Rotary1
on_value:
- uart.write: "n0.val="
- uart.write: !lambda |-
return {id(Rotary1).state};
- uart.write: [0xFF, 0XFF, 0xFF]
这个有在48-57串口屏会正确接收到1-9
[19:44:42][D][text_sensor:067]: 'harotray': Sending state '48'
[19:44:42][D][uart_debug:158]: >>> "n0.val=0\xFF\xFF\xFF"
[19:44:46][D][sensor:127]: 'Rotary Encoder': Sending state 49.00000 steps with 0 decimals of accuracy
[19:44:46][D][homeassistant.text_sensor:017]: 'sensor.rotary_encoder': Got state '49'
[19:44:46][D][text_sensor:067]: 'harotray': Sending state '49'
[19:44:46][D][uart_debug:158]: >>> "n0.val=1\xFF\xFF\xFF"
[19:44:46][D][sensor:127]: 'Rotary Encoder': Sending state 50.00000 steps with 0 decimals of accuracy
[19:44:46][D][homeassistant.text_sensor:017]: 'sensor.rotary_encoder': Got state '50'
[19:44:46][D][text_sensor:067]: 'harotray': Sending state '50'
[19:44:46][D][uart_debug:158]: >>> "n0.val=2\xFF\xFF\xFF"
[19:44:47][D][sensor:127]: 'Rotary Encoder': Sending state 51.00000 steps with 0 decimals of accuracy
[19:44:47][D][homeassistant.text_sensor:017]: 'sensor.rotary_encoder': Got state '51'
[19:44:47][D][text_sensor:067]: 'harotray': Sending state '51'
[19:44:47][D][uart_debug:158]: >>> "n0.val=3\xFF\xFF\xFF"
[19:44:47][D][sensor:127]: 'Rotary Encoder': Sending state 52.00000 steps with 0 decimals of accuracy
[19:44:47][D][homeassistant.text_sensor:017]: 'sensor.rotary_encoder': Got state '52'
[19:44:47][D][text_sensor:067]: 'harotray': Sending state '52'
[19:44:47][D][uart_debug:158]: >>> "n0.val=4\xFF\xFF\xFF"
用了- uart.write: !lambda |-
char str[20];
sprintf(str, "%lf", id(Rotary1).state);
return str
编译报错:'str' from 'char [20]' to 'std::vector<unsigned cha
|
|