Update wren-c5-esphome.yaml
This commit is contained in:
@@ -1,13 +1,74 @@
|
|||||||
|
|
||||||
esphome:
|
esphome:
|
||||||
name: wren-c5
|
name: wren-c5
|
||||||
|
|
||||||
|
on_boot:
|
||||||
|
priority: 800
|
||||||
|
then:
|
||||||
|
|
||||||
|
- lambda: |-
|
||||||
|
|
||||||
|
uint8_t cfg[2] = {0x03,0x00};
|
||||||
|
id(bus_a).write(0x21,cfg,2);
|
||||||
|
|
||||||
|
uint8_t pol[2] = {0x02,0x00};
|
||||||
|
id(bus_a).write(0x21,pol,2);
|
||||||
|
|
||||||
|
uint8_t out[2] = {0x01,0x00};
|
||||||
|
id(bus_a).write(0x21,out,2);
|
||||||
|
|
||||||
|
ESP_LOGI(
|
||||||
|
"tca",
|
||||||
|
"TCA6408A initialized"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
- delay: 500ms
|
||||||
|
|
||||||
|
- if:
|
||||||
|
condition:
|
||||||
|
binary_sensor.is_on: sflag
|
||||||
|
then:
|
||||||
|
- logger.log:
|
||||||
|
"SFLAG ACTIVE AFTER BOOT"
|
||||||
|
- script.execute:
|
||||||
|
fault_handler
|
||||||
|
|
||||||
esp32:
|
esp32:
|
||||||
|
|
||||||
board: esp32-c5-devkitc-1
|
board: esp32-c5-devkitc-1
|
||||||
variant: esp32c5
|
variant: esp32c5
|
||||||
|
|
||||||
framework:
|
framework:
|
||||||
type: esp-idf
|
type: esp-idf
|
||||||
|
|
||||||
# WREN C5 Test
|
i2c:
|
||||||
|
|
||||||
|
id: bus_a
|
||||||
|
|
||||||
|
sda: GPIO2
|
||||||
|
scl: GPIO3
|
||||||
|
|
||||||
|
scan: true
|
||||||
|
|
||||||
|
globals:
|
||||||
|
|
||||||
|
- id: fault_active
|
||||||
|
type: bool
|
||||||
|
restore_value: no
|
||||||
|
initial_value: 'false'
|
||||||
|
|
||||||
|
- id: tca_state
|
||||||
|
type: uint8_t
|
||||||
|
restore_value: no
|
||||||
|
initial_value: '0'
|
||||||
|
|
||||||
|
switch:
|
||||||
|
|
||||||
|
- platform: gpio
|
||||||
|
id: rs485_enable
|
||||||
|
pin: GPIO23
|
||||||
|
restore_mode: ALWAYS_ON
|
||||||
|
|
||||||
output:
|
output:
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
@@ -16,18 +77,14 @@ output:
|
|||||||
|
|
||||||
light:
|
light:
|
||||||
- platform: binary
|
- platform: binary
|
||||||
output: blue_led
|
|
||||||
id: heartbeat
|
id: heartbeat
|
||||||
|
output: blue_led
|
||||||
interval:
|
|
||||||
- interval: 500ms
|
|
||||||
then:
|
|
||||||
- light.toggle: heartbeat
|
|
||||||
|
|
||||||
binary_sensor:
|
binary_sensor:
|
||||||
|
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
id: in_1a
|
id: in_1a
|
||||||
name: "IN 1A"
|
name: "Motor 1 Extend"
|
||||||
pin:
|
pin:
|
||||||
number: GPIO8
|
number: GPIO8
|
||||||
mode:
|
mode:
|
||||||
@@ -35,8 +92,9 @@ binary_sensor:
|
|||||||
pulldown: true
|
pulldown: true
|
||||||
|
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
|
||||||
id: in_1b
|
id: in_1b
|
||||||
name: "IN 1B"
|
name: "Motor 1 Retract"
|
||||||
pin:
|
pin:
|
||||||
number: GPIO9
|
number: GPIO9
|
||||||
mode:
|
mode:
|
||||||
@@ -45,7 +103,7 @@ binary_sensor:
|
|||||||
|
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
id: in_2a
|
id: in_2a
|
||||||
name: "IN 2A"
|
name: "Motor 2 Extend"
|
||||||
pin:
|
pin:
|
||||||
number: GPIO14
|
number: GPIO14
|
||||||
mode:
|
mode:
|
||||||
@@ -54,7 +112,7 @@ binary_sensor:
|
|||||||
|
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
id: in_2b
|
id: in_2b
|
||||||
name: "IN 2B"
|
name: "Motor 2 Retract"
|
||||||
pin:
|
pin:
|
||||||
number: GPIO13
|
number: GPIO13
|
||||||
mode:
|
mode:
|
||||||
@@ -70,6 +128,252 @@ binary_sensor:
|
|||||||
input: true
|
input: true
|
||||||
pulldown: true
|
pulldown: true
|
||||||
|
|
||||||
|
on_press:
|
||||||
|
then:
|
||||||
|
- logger.log:
|
||||||
|
"SFLAG INTERRUPT"
|
||||||
|
- script.execute:
|
||||||
|
fault_handler
|
||||||
|
|
||||||
|
- platform: gpio
|
||||||
|
id: en1
|
||||||
|
name: "EN1 Feedback"
|
||||||
|
pin:
|
||||||
|
number: GPIO5
|
||||||
|
mode:
|
||||||
|
input: true
|
||||||
|
|
||||||
|
- platform: gpio
|
||||||
|
id: en2
|
||||||
|
name: "EN2 Feedback"
|
||||||
|
pin:
|
||||||
|
number: GPIO6
|
||||||
|
mode:
|
||||||
|
input: true
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
|
||||||
|
- platform: adc
|
||||||
|
id: supply_voltage
|
||||||
|
pin: GPIO4
|
||||||
|
name: "Supply Voltage"
|
||||||
|
attenuation: auto
|
||||||
|
update_interval: 30s
|
||||||
|
|
||||||
|
filters:
|
||||||
|
- multiply: 44.4444
|
||||||
|
|
||||||
|
- platform: tmp102
|
||||||
|
name: "Board Temperature"
|
||||||
|
address: 0x4A
|
||||||
|
update_interval: 30s
|
||||||
|
|
||||||
|
- platform: wifi_signal
|
||||||
|
name: "WiFi RSSI"
|
||||||
|
update_interval: 60s
|
||||||
|
|
||||||
|
- platform: uptime
|
||||||
|
name: "Uptime"
|
||||||
|
|
||||||
|
script:
|
||||||
|
|
||||||
|
- id: fault_handler
|
||||||
|
mode: single
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
|
||||||
|
if(id(fault_active))
|
||||||
|
return;
|
||||||
|
|
||||||
|
id(fault_active)=true;
|
||||||
|
|
||||||
|
ESP_LOGE(
|
||||||
|
"FAULT - IMMEDIATE FAULT SHUTDOWN",
|
||||||
|
"MOTOR STOP - TCA OUTPUT LOW. POWER CYCLE TO RE-ENABLE WREN"
|
||||||
|
"HAVE A GREAT DAY!"
|
||||||
|
);
|
||||||
|
|
||||||
|
uint8_t off[2];
|
||||||
|
off[0]=0x01;
|
||||||
|
off[1]=0x00;
|
||||||
|
|
||||||
|
id(bus_a).write(0x21, off, 2);
|
||||||
|
id(bus_a).write(0x21, off, 2);
|
||||||
|
id(bus_a).write(0x21, off, 2);
|
||||||
|
|
||||||
|
- repeat:
|
||||||
|
count: 20
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
|
||||||
|
uint8_t led[2];
|
||||||
|
led[0]=0x01;
|
||||||
|
|
||||||
|
// TCA BIT7 ON
|
||||||
|
led[1]=0x80;
|
||||||
|
|
||||||
|
id(bus_a).write(
|
||||||
|
0x21,
|
||||||
|
led,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
- delay: 1000ms
|
||||||
|
- lambda: |-
|
||||||
|
|
||||||
|
uint8_t led[2];
|
||||||
|
led[0]=0x01;
|
||||||
|
|
||||||
|
// ALL OFF
|
||||||
|
led[1]=0x00;
|
||||||
|
|
||||||
|
id(bus_a).write(
|
||||||
|
0x21,
|
||||||
|
led,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
- delay: 100ms
|
||||||
|
|
||||||
|
# - lambda: |-
|
||||||
|
# ESP_LOGE(
|
||||||
|
# "FAULT",
|
||||||
|
# "RESTARTING"
|
||||||
|
# );
|
||||||
|
# esp_restart();
|
||||||
|
|
||||||
|
interval:
|
||||||
|
|
||||||
|
|
||||||
|
# heartbeat
|
||||||
|
|
||||||
|
- interval: 1s
|
||||||
|
then:
|
||||||
|
- light.turn_on: heartbeat
|
||||||
|
- delay: 750ms
|
||||||
|
- light.turn_off: heartbeat
|
||||||
|
|
||||||
|
|
||||||
|
# motor supervisor
|
||||||
|
|
||||||
|
- interval: 10ms
|
||||||
|
|
||||||
|
then:
|
||||||
|
|
||||||
|
- lambda: |-
|
||||||
|
|
||||||
|
//
|
||||||
|
// HARD SFLAG CHECK
|
||||||
|
//
|
||||||
|
|
||||||
|
if(id(sflag).state)
|
||||||
|
{
|
||||||
|
ESP_LOGE(
|
||||||
|
"FAULT",
|
||||||
|
"SFLAG HIGH"
|
||||||
|
);
|
||||||
|
|
||||||
|
id(fault_handler).execute();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(id(sflag).state)
|
||||||
|
{
|
||||||
|
id(fault_handler).execute();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// LATCHED FAULT
|
||||||
|
//
|
||||||
|
|
||||||
|
if(id(fault_active))
|
||||||
|
{
|
||||||
|
uint8_t off[2]={0x01,0x00};
|
||||||
|
|
||||||
|
id(bus_a).write(
|
||||||
|
0x21,
|
||||||
|
off,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// VOLTAGE CHECK
|
||||||
|
//
|
||||||
|
|
||||||
|
float v=id(supply_voltage).state;
|
||||||
|
|
||||||
|
if(v < 10.0f || v > 48.0f)
|
||||||
|
{
|
||||||
|
ESP_LOGE(
|
||||||
|
"FAULT",
|
||||||
|
"VOLTAGE %.1f",
|
||||||
|
v
|
||||||
|
);
|
||||||
|
id(fault_handler).execute();
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t output=0;
|
||||||
|
bool m1a=id(in_1a).state;
|
||||||
|
bool m1b=id(in_1b).state;
|
||||||
|
bool m2a=id(in_2a).state;
|
||||||
|
bool m2b=id(in_2b).state;
|
||||||
|
|
||||||
|
bool active =
|
||||||
|
m1a ||
|
||||||
|
m1b ||
|
||||||
|
m2a ||
|
||||||
|
m2b;
|
||||||
|
|
||||||
|
//
|
||||||
|
// BOTH ENABLES TOGETHER
|
||||||
|
//
|
||||||
|
|
||||||
|
if(active)
|
||||||
|
{
|
||||||
|
output |= (1<<0); // EN1
|
||||||
|
output |= (1<<3); // EN2
|
||||||
|
}
|
||||||
|
|
||||||
|
// MOTOR 1
|
||||||
|
if(m1a)
|
||||||
|
output |= (1<<1);
|
||||||
|
|
||||||
|
if(m1b)
|
||||||
|
output |= (1<<2);
|
||||||
|
|
||||||
|
|
||||||
|
// MOTOR 2
|
||||||
|
if(m2a)
|
||||||
|
output |= (1<<4);
|
||||||
|
|
||||||
|
if(m2b)
|
||||||
|
output |= (1<<5);
|
||||||
|
|
||||||
|
uint8_t buf[2];
|
||||||
|
buf[0]=0x01;
|
||||||
|
buf[1]=output;
|
||||||
|
|
||||||
|
id(bus_a).write(
|
||||||
|
0x21,
|
||||||
|
buf,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// ESP_LOGI(
|
||||||
|
// "motor",
|
||||||
|
// "OUT=0x%02X",
|
||||||
|
// output
|
||||||
|
// );
|
||||||
|
|
||||||
|
# #############################
|
||||||
|
|
||||||
# Enable Home Assistant API
|
# Enable Home Assistant API
|
||||||
api:
|
api:
|
||||||
encryption:
|
encryption:
|
||||||
|
|||||||
Reference in New Issue
Block a user