I’m using an ESP32 board with two daisy chained SH74HC595 shift registers to control 16 relays. Relays are “modules” with active low, in other words low signal from the controller turns each relay on.
My problem is that during power-up the register sets outputs to low hence turning on the relays. They don’t just click, but stay on. The relays have restore_mode: ALWAYS_OFF set. Output enable pin (OE) has pull-up resistor and is controlled in the code. That works well when reset is triggered but on full power cycle the relays always turn on.
My idea was to use on_boot code:
esphome:
name: esp-something
on_boot:
priority: -100.0
then:
- switch.turn_off: pin_10 # test relay set HIGH
- delay: 10ms
- switch.turn_on: oe_pin # OE pin pulled LOW = active
- logger.log: "Switched on, boot"
But it doesn’t behave as expected - pin_10 stays low and the relay turns on. I know that the oe_pin gets activated because without that command relays would be uncontrollable. There is no entry in the log (not sure if it should be though).
Working, but not clean solution was to add switch for oe_pin in every relay-related command. Is there a better way to achieve high outputs on shift register after boot?
Relevant part of the code is:
sn74hc595:
- id: 'output_raz'
data_pin: 16 #SER
clock_pin: 17 #SRCLK
latch_pin: 18 #RCLK
sr_count: 2
switch:
- platform: gpio
name: "Switcher relay"
id: pin_10
pin:
sn74hc595: output_raz
number: 9
inverted: true
mode:
output: true
restore_mode: ALWAYS_OFF
- platform: gpio
name: "OE pin"
id: oe_pin
pin:
number: 19
inverted: true
mode:
output: true
restore_mode: ALWAYS_ON