74HC595 et ESPHome pour piloter 8 relais

Bonjour,
Je teste un 74HC595 avec un ESP32 pour piloter une carte 8 relais.
j’ai contrôlé les branchements, j’alimente le 74HC en 3.3v, les relais seront alimenté en 5V par une autre alim plus tard.
je n’ais que la LED du relais 1 (sortie QA du HC74) qui fonctionne lorsque je bascule les switchs sur on, tous les autres sont inopérants. je ne comprends pas pourquoi ?
Mon code :

esphome:
  name: 74hc
  friendly_name: 74hc

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XY5c0KxpLaNk/aJ2jz6cJ1BxFOtr3BL05fOjsvpAkdM="

ota:
  password: "a0c3986ef7b8c30f0c5202a35a5b897a"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

web_server:
  port: 80
  version: 2
  local: true

sn74hc595:
  - id: 'sn74hc595_hub'
    data_pin: GPIO14
    clock_pin: GPIO12
    latch_pin: GPIO04 

# Individual outputs
switch:
  - platform: gpio
    name: "Zone 1"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 0
      number: 0
      inverted: true
      
  - platform: gpio
    name: "Zone 2"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 1
      number: 1
      inverted: true
      
  - platform: gpio
    name: "Zone 3"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 2
      number: 2
      inverted: true
      
  - platform: gpio
    name: "Zone 4"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 3
      number: 3
      inverted: true

  - platform: gpio
    name: "Zone 5"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 4
      number: 4
      inverted: true

image

OUPS ! la boulette, je viens de m’apercevoir, après une semaine à galérer, que j’avais mis le mauvais CI dans le support ! ça n’était pas un 74HC595 mais un CD4050 qui n’a rien à voir.
Donc ça fonctionne très bien.
je vais tester avec 4 x 74HC595 pour 32 relais…

1 « J'aime »

8 relais pour 4 volets roulants.

ça fonctionne :

Bonjour,

le sujet m’intéresse, peux tu donner ton schéma de câblage ainsi que ton code compet pour les 32 relais ?
Merci

Pour le moment, je fais des tests,
le schéma avec 2 x 74HC sur ce blog, avec 4 c’est le même câblage.

pour le code c’est provisoire il faudra que j’y travail.

esphome:
  name: esp32wroommini
  friendly_name: ESP32Wroommini

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "lbdv2sy9cjksKxDyG8AZ5T7sAr/fDprnikPsqzsZV2M="

ota:
  password: "317c00f8a06bee338556da93a0e6b9f4"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32Wroommini Fallback Hotspot"
    password: "rjRNRDE76VS3"

captive_portal:

web_server:
  port: 80
  version: 2
  local: true

text_sensor:
     
  - platform: wifi_info
    ip_address:
      name: ESP IP Address
    ssid:
      name: ESP Connected SSID
    bssid:
      name: ESP Connected BSSID
    mac_address:
      name: ESP Mac Wifi Address

number:
  - platform: template
    max_value: 30
    name: "Op duration"
    optimistic: true
    min_value: 5
    step: 1

# Example configuration entry

sn74hc595:
  - id: 'SORTIES'
    data_pin: GPIO25  #SER
    clock_pin: GPIO33 #SRCLK
    latch_pin: GPIO32 #RCLK
    sr_count: 4

# Individual outputs
switch:
  - platform: gpio
    id: "SORTIE0"
    pin:
      sn74hc595: SORTIES
      number: 0
      inverted: true
    interlock: &interlock_group0 [SORTIE0, SORTIE1]
    restore_mode: always off

  - platform: gpio
    id: "SORTIE1"
    pin:
      sn74hc595: SORTIES
      number: 1
      inverted: true
    interlock: *interlock_group0
    restore_mode: always off

  - platform: gpio
    id: "SORTIE2"
    pin:
      sn74hc595: SORTIES
      number: 2
      inverted: true
    interlock: &interlock_group1 [SORTIE2, SORTIE3]
    restore_mode: always off

  - platform: gpio
    id: "SORTIE3"
    pin:
      sn74hc595: SORTIES
      number: 3
      inverted: true
    interlock: *interlock_group1
    restore_mode: always off
    
  - platform: gpio
    id: "SORTIE4"
    pin:
      sn74hc595: SORTIES
      number: 4
      inverted: true
    interlock: &interlock_group2 [SORTIE4, SORTIE5]
    restore_mode: always off
    
  - platform: gpio
    id: "SORTIE5"
    pin:
      sn74hc595: SORTIES
      number: 5
      inverted: true
    interlock: *interlock_group2
    restore_mode: always off

  - platform: gpio
    id: "SORTIE6"
    pin:
      sn74hc595: SORTIES
      number: 6
      inverted: true
    interlock: &interlock_group3 [SORTIE6, SORTIE7]
    restore_mode: always off

  - platform: gpio
    id: "SORTIE7"
    pin:
      sn74hc595: SORTIES
      number: 7
      inverted: true
    interlock: *interlock_group3
    restore_mode: always off


# Cover
# HA frontend
cover:
  - platform: time_based
    device_class: shutter
    name: "Volet_1"
    id: Volet_1

    open_action:
      - switch.turn_on: SORTIE0
    open_duration: 
      seconds: 12
    close_action:
      - switch.turn_on: SORTIE1
    close_duration: 
      seconds: 12
    stop_action:
      - switch.turn_off: SORTIE0
      - switch.turn_off: SORTIE1

  - platform: time_based
    device_class: shutter
    name: "Volet_2"
    id: Volet_2

    open_action:
      - switch.turn_on: SORTIE2
    open_duration: 15s
    close_action:
      - switch.turn_on: SORTIE3
    close_duration: 15s
    stop_action:
      - switch.turn_off: SORTIE2
      - switch.turn_off: SORTIE3

  - platform: time_based
    device_class: shutter
    name: "Volet_3"
    id: Volet_3

    open_action:
      - switch.turn_on: SORTIE4
    open_duration: 35s
    close_action:
      - switch.turn_on: SORTIE5
    close_duration: 35s
    stop_action:
      - switch.turn_off: SORTIE4
      - switch.turn_off: SORTIE5 

  - platform: time_based
    device_class: shutter
    name: "Volet_4"
    id: Volet_4

    open_action:
      - switch.turn_on: SORTIE6
    open_duration: 15s
    close_action:
      - switch.turn_on: SORTIE7
    close_duration: 15s
    stop_action:
      - switch.turn_off: SORTIE6
      - switch.turn_off: SORTIE7

Intéressant, mais j’ai un peu de mal a savoir comment ça fonctionne.

Si je comprends bien 3 gpio pour du « codage » pour compter de 0b à 111b soit 8 décimal ce qui fait que tu commande 8 relais

Comment faire tu pour piloter à la fois le relais 3 et 5 par exemple ?

c’est le code qui gère le BUS, les 74HC595 sont en série
pour le relais 32 (0 à 31):

- platform: gpio
    id: "SORTIE31"
    pin:
      sn74hc595: SORTIES
      number: 31
      inverted: true

il y a des blogs Arduino la dessus, pas beaucoup avec ESPHome par contre :

le sn74hc595 est un convertisseur série/parallèle
tu as un « bus » avec les signaux latch et clock pour tous tes sn74hc595, tu rentre ton input série dans le premier, et ensuite tu chaine tes chips, la sortie du premier entre dans le second et ainsi de suite, avec un max de 8 sn74hc595
si tu as besoin de plus de 64 relais, il faut passer par un second jeu de sn74hc595 avec un second input série.

très bien expliqué là:

2 « J'aime »

Bonjour,

J’ai terminé une carte de 16 entrées et 16 sorties avec un Esp32 POE Ethernet (donc pas besoin d’alimentation) en utilisant 2 multiplexeurs 74HC595 pour les sorties et 2 multiplexeurs 74HC165 pour les entrées.

J’ai développé le circuit imprimé et j’ai testé la carte qui fonctionne super bien.
(attention, il faut alimenter les multiplexeurs en 3.3v)

Pour ceux que ça intéresse, le code et schéma:

substitutions:
  disp_name: esp32-poe-carte1

esphome:
  name: esp32-poe-carte1
  friendly_name: esp32-poe-carte1 

esp32:
  board: esp32-poe
  framework:
    type: arduino
##############################################
ota:
  password: "acb5275c4c844f25003ca3e16d8bdbc4"  
api:
  encryption:
    key: !secret enc_key_rostock  
logger: 
web_server: 
  local: true
  port: 80    
  auth:
    username: !secret web_server_username
    password: !secret web_server_password        
############################################
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12
#  manual_ip:
#    static_ip: 192.168.0.25
#    gateway: 192.168.0.254
#    subnet: 255.255.255.0
#########################################
# Information de la carte
text_sensor:
  - platform: ethernet_info
    ip_address:
      name: ${disp_name}  IP Address
########################################
# Bouton de redémarrage
button:
  - platform: restart
    id: reset
    name: ${disp_name} Reset      
########################################
sensor:
  - platform: uptime
    name: ${disp_name}  Allumé depuis (s)
    id: uptime_sec
#######################################
# Multiplexeur pour 16 sorties. Le sn74hc595 doit être en 3.3v
sn74hc595:
  - id: 'sn74hc595_hub'
    data_pin: GPIO16  #SER
    clock_pin: GPIO33 #SRCLK
    latch_pin: GPIO32 #RCLK
    sr_count: 2
######################################
# Les relais sont en 5v
switch:
  - platform: gpio
    name: "Relais-1" #"SN74HC595 Pin #0"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 0
      inverted: false
    restore_mode: always off 
  - platform: gpio
    name: "Relais-2" #"SN74HC595 Pin #1"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 1
      inverted: false
    restore_mode: always off  
  - platform: gpio
    name: "Relais-3" #"SN74HC595 Pin #2"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 2
      inverted: false
    restore_mode: always off 
  - platform: gpio
    name: "Relais-4" #"SN74HC595 Pin #3"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 3
      inverted: false  
    restore_mode: always off 
  - platform: gpio
    name: "Relais-5" #"SN74HC595 Pin #4"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 4
      inverted: false
    restore_mode: always off  
  - platform: gpio
    name: "Relais-6" #"SN74HC595 Pin #5"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 5
      inverted: false  
    restore_mode: always off 
  - platform: gpio
    name: "Relais-7" #"SN74HC595 Pin #6"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 6
      inverted: false  
    restore_mode: always off 
  - platform: gpio
    name: "Relais-8" #"SN74HC595 Pin #7"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 7
      inverted: false  
    restore_mode: always off  
  - platform: gpio
    name: "Relais-9" #"SN74HC595 Pin #8"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 8
      inverted: false  
    restore_mode: always off  
  - platform: gpio
    name: "Relais-10" #"SN74HC595 Pin #9"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 9
      inverted: false  
    restore_mode: always off  
  - platform: gpio
    name: "Relais-11" #"SN74HC595 Pin #10"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 10
      inverted: false  
    restore_mode: always off 
  - platform: gpio
    name: "Relais-12" #"SN74HC595 Pin #11"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 11
      inverted: false  
    restore_mode: always off
  - platform: gpio
    name: "Relais-13" #"SN74HC595 Pin #12"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 12
      inverted: false  
    restore_mode: always off  
  - platform: gpio
    name: "Relais-14" #"SN74HC595 Pin #13"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 13
      inverted: false  
    restore_mode: always off 
  - platform: gpio
    name: "Relais-15" #"SN74HC595 Pin #14"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 14
      inverted: false  
    restore_mode: always off 
  - platform: gpio
    name: "Relais-16" #"SN74HC595 Pin #15"
    icon: "mdi:electric-switch"
    pin:
      sn74hc595: sn74hc595_hub
      number: 15
      inverted: false  
    restore_mode: always off                            
####################################### 
# Multiplexeur pour 16 entrées. Le sn74hc164 doit être en 3.3v
# Les entrées sont avec une resistance de 10k en pull-up
sn74hc165:
  - id: 'sn74hc165_hub'
    clock_pin: GPIO02 #pin 2 du sn74hc165_hub
    data_pin: GPIO01 #pin 9 du sn74hc165_hub
    load_pin: GPIO03 #pin 1 du sn74hc165_hub
    clock_inhibit_pin: GPIO00 #pin 15 du sn74hc165_hub
    sr_count: 2
#-----------------------------------------
# Entrées
binary_sensor:
# Etat de connexion de l'esp32
  - platform: status
    name: ${disp_name} Status
#-----------------------------------------
# Declaration des entrees sur le sn74hc165
#-----------------------------------------
  - platform: gpio
    name: "In-1" #"SN74HC165 Pin #0"
    pin:
      sn74hc165: sn74hc165_hub
      number: 0
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-2" #"SN74HC165 Pin #1"
    pin:
      sn74hc165: sn74hc165_hub
      number: 1
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-3" #"SN74HC165 Pin #2"
    pin:
      sn74hc165: sn74hc165_hub
      number: 2
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-4" #"SN74HC165 Pin #3"
    pin:
      sn74hc165: sn74hc165_hub
      number: 3
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-5" #"SN74HC165 Pin #4"
    pin:
      sn74hc165: sn74hc165_hub
      number: 4
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-6" #"SN74HC165 Pin #5"
    pin:
      sn74hc165: sn74hc165_hub
      number: 5
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-7" #"SN74HC165 Pin #6"
    pin:
      sn74hc165: sn74hc165_hub
      number: 6
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-8" #"SN74HC165 Pin #7"
    pin:
      sn74hc165: sn74hc165_hub
      number: 7
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-9" #"SN74HC165 Pin #8"
    pin:
      sn74hc165: sn74hc165_hub
      number: 8
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-10" #"SN74HC165 Pin #9"
    pin:
      sn74hc165: sn74hc165_hub
      number: 9
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-11" #"SN74HC165 Pin #10"
    pin:
      sn74hc165: sn74hc165_hub
      number: 10
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-12" #"SN74HC165 Pin #11"
    pin:
      sn74hc165: sn74hc165_hub
      number: 11
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-13" #"SN74HC165 Pin #12"
    pin:
      sn74hc165: sn74hc165_hub
      number: 12
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-14" #"SN74HC165 Pin #13"
    pin:
      sn74hc165: sn74hc165_hub
      number: 13
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-15" #"SN74HC165 Pin #14"
    pin:
      sn74hc165: sn74hc165_hub
      number: 14
      inverted: true 
#-----------------------------------------
  - platform: gpio
    name: "In-16" #"SN74HC165 Pin #15"
    pin:
      sn74hc165: sn74hc165_hub
      number: 15
      inverted: true 
#####################################
1 « J'aime »