MCP23017 Ausgänge mit Taster steuern

Begonnen von wowatsch, 14 Mai 2018, 12:40:04

Vorheriges Thema - Nächstes Thema

wowatsch

Guten Tag,
ich versuche gerade anhand eines Tasters und einem I2C Chip (MCP23017) einen Ausgang zu schalten.
Mit einem Normalen Schalter habe ich das schon hinbekommen. Ich möchte das der Ausgang bei einmal kurz gedrückten Taster an bleibt.
Hier noch meine Config:
define icchip I2C_MCP23017 0x20
attr icchip IODev i2cbus
attr icchip Interrupt A0,A1,A2,A3,A4,A5,A6,A7
attr icchip InterruptOut connected_active-low
attr icchip OnStartup B0=on,B1=on,B2=on,B3=on,B4=on,B5=on,B6=on,B7=on
attr icchip OutputPorts B0,B1,B2,B3,B4,B5,B6,B7
attr icchip Pullup A0,A1,A2,A3,A4,A5,A6,A7
attr icchip event-on-change-reading state,PortA0,PortA1,PortA2,PortA3,PortA4,PortA5,PortA6,PortA7
attr icchip invert_input A0,A1,A2,A3,A4,A5,A6,A7
attr icchip room Raum1
define outputB0 readingsProxy icchip:PortB0
attr outputB0 devStateIcon on:off:off off:on:on
attr outputB0 room Raum1
attr outputB0 setFn {($CMD eq "on")?"PortB0 off":"PortB0 on"}
attr outputB0 setList on off
define inputA0 readingsProxy icchip:PortA0
attr inputA0 room Raum1
attr inputA0 valueFn {($VALUE eq "on")?"on":"off"}
define InterruptPin1 RPI_GPIO 4
attr InterruptPin1 active_low yes
attr InterruptPin1 direction input
attr InterruptPin1 interrupt both
attr InterruptPin1 poll_interval 5
attr InterruptPin1 pud_resistor up
attr InterruptPin1 restoreOnStartup last
attr InterruptPin1 room Raum1
attr InterruptPin1 userReadings get_int {fhem ("get icchip")}
define n_Taste1 notify inputA0 set outputB0 $EVENT
attr n_Taste1 room Raum1

LuckyDay


wowatsch

2018-05-14 13:10:20 readingsProxy inputA0 on
2018-05-14 13:10:20 I2C_MCP23017 icchip PortA0: on
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Pinlevel: high
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 on
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Dblclick: off
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Pinlevel: low
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 off
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Longpress: off
2018-05-14 13:10:20 readingsProxy inputA0 off
2018-05-14 13:10:20 I2C_MCP23017 icchip PortA0: off
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Dblclick: on
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Pinlevel: high
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 on
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Dblclick: off
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Pinlevel: low
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 off
2018-05-14 13:10:20 RPI_GPIO InterruptPin1 Longpress: off

Frank_Huber

Hi,

Taster am GPIO, Relais am MCP23017: (Nur Toggle)
defmod Licht_HSA DOIF ([GPIO_IN_07:"^on$"] and [?OUT_1:PortA3] eq "off") (set OUT_1 PortA3 on)\
DOELSEIF ([GPIO_IN_07:"^on$"] and [?OUT_1:PortA3] eq "on") (set OUT_1 PortA3 off)
attr Licht_HSA cmdState on|off
attr Licht_HSA cmdpause 2:2
attr Licht_HSA devStateIcon on:on:cmd_2 initialize|initialized|off:off:cmd_1
attr Licht_HSA do always


Taster am GPIO, Relais am MCP23017: (Zeitsteuerung 3min und Toggle)
defmod Licht_Flur_KG DOIF ([GPIO_IN_04:"^on$"] and [?OUT_1:PortA0] eq "off") (set OUT_1 PortA0 on) (set OUT_1 PortA0 off)\
DOELSEIF ([GPIO_IN_04:"^on$"] and [?OUT_1:PortA0] eq "on") (set OUT_1 PortA0 off)\
DOELSEIF ([GPIO_IN_04:"^Longpress:.on$"]) (set OUT_1 PortA0 on)
attr Licht_Flur_KG cmdState on,off|off|on
attr Licht_Flur_KG cmdpause 2:2:2
attr Licht_Flur_KG devStateIcon on:on:cmd_2 initialize|initialized|off:off:cmd_3
attr Licht_Flur_KG do always
attr Licht_Flur_KG wait 0,180:0:0

wowatsch

Super Danke!
Das funktioniert jetzt auch. Nur kann ich nicht schnell hinternander schalten. Denn nach einmal schalten muss ich paar sec. warten um wieder schalten zu können. Ist das so gewollt? oder kann ich das anpassen?

Frank_Huber

Ist gewollt zum entprellen.

Hier steckts drin: (2 Sek)
attr Licht_HSA cmdpause 2:2
attr Licht_Flur_KG cmdpause 2:2:2

wowatsch

Hallo nochmal,
Der Taster funktioniert jetzt. Aber ohne Probleme wäre das ja zu eifacht. Ich verwende 16 relais die sich über 5v schalten lassen. Jetzt kann ich am Anfang vielleicht zweimal schaltenund dann lässt sich das relai icht mehr schalten. Fhem lässt sich zwar noch bedienen aber das relai reagiert dann nicht mehr. Wenn ich nur FHEM neustarte funktiert es kurz wieder.

Frank_Huber

Also ich habe zuhause ca 90 Relais über MCP23017 im Einsatz.
Für Rollos und Licht und alles was zentral gesteuert wird.
Das ganze läuft seit mehr als 1,5 Jahren zuverlässig und stabil.

poste mal ein list von den Komponenten (GPIO_IN, DOIF und MCP23017 device) im Fehlerfall.
Wichtig dass du die Lists im Fehlerfall machst, sonst kann man nicht sehen wo es klemmt!

wowatsch

GPIO_IN

Internals:
   DEF        4
   EXCEPT_FD  10
   GPIO_Basedir /sys/class/gpio
   GPIO_Nr    4
   NAME       InterruptPin1
   NR         28
   STATE      off
   TYPE       RPI_GPIO
   WiringPi_gpio /usr/local/bin/gpio
   READINGS:
     2018-05-14 11:47:08   Counter         49
     2018-05-17 16:49:37   Dblclick        off
     2018-05-17 16:49:37   Longpress       off
     2018-05-17 16:49:37   Pinlevel        low
     2018-05-17 16:49:37   state           off
   fhem:
     interfaces switch
Attributes:
   active_low yes
   direction  input
   interrupt  both
   poll_interval 5
   pud_resistor up
   restoreOnStartup last
   room       Raum1
   userReadings get_int {fhem ("get icchip")}




DOIF

Internals:
   DEF        ([inputA0:"^on$"] and [?icchip:PortB4] eq "off") (set icchip PortB4 on) DOELSEIF ([inputA0:"^on$"] and [?icchip:PortB4] eq "on") (set icchip PortB4 off)
   MODEL      FHEM
   NAME       Licht_HSA
   NR         31
   NTFY_ORDER 50-Licht_HSA
   STATE      off
   TYPE       DOIF
   READINGS:
     2018-05-17 16:49:37   Device          inputA0
     2018-05-17 16:49:37   cmd             2
     2018-05-17 16:49:37   cmd_event       set_cmd_2
     2018-05-17 16:49:37   cmd_nr          2
     2018-05-17 16:49:37   e_inputA0_events off
     2018-05-17 16:04:41   mode            enabled
     2018-05-17 16:49:37   state           off
   Regex:
   condition:
     0          EventDoIf('inputA0',$hash,'^on$',1) and ReadingValDoIf($hash,'icchip','PortB4') eq "off"
     1          EventDoIf('inputA0',$hash,'^on$',1) and ReadingValDoIf($hash,'icchip','PortB4') eq "on"
   devices:
     0           inputA0
     1           inputA0
     all         inputA0
   do:
     0:
       0          set icchip PortB4 on
     1:
       0          set icchip PortB4 off
     2:
   helper:
     DOIF_Readings_events
     DOIF_eventas
     event      off
     globalinit 1
     last_timer 0
     sleeptimer -1
     timerdev   inputA0
     timerevent on
     triggerDev inputA0
     timerevents:
       on
     timereventsState:
       on
     triggerEvents:
       off
     triggerEventsState:
       off
   internals:
   itimer:
   perlblock:
   readings:
   trigger:
     all         inputA0
   uiState:
Attributes:
   cmdState   on|off
   cmdpause   2:2
   devStateIcon on:off:cmd_2 initialize|initialized|off:on:cmd_1
   do         always
   room       Raum1


MCP23017

Internals:
   CHANGED   
   DEF        0x20
   I2C_Address 32
   IODev      i2cbus
   NAME       icchip
   NR         25
   STATE      Ok
   TYPE       I2C_MCP23017
   i2cbus_SENDSTAT Ok
   READINGS:
     2018-05-17 16:51:06   PortA0          on
     2018-05-17 16:51:06   PortA1          on
     2018-05-17 16:51:06   PortA2          off
     2018-05-17 16:51:06   PortA3          off
     2018-05-17 16:49:37   PortA4          on
     2018-05-17 16:51:06   PortA5          off
     2018-05-17 16:51:06   PortA6          off
     2018-05-17 16:51:06   PortA7          off
     2018-05-17 16:49:03   PortB0          on
     2018-05-17 16:49:03   PortB1          on
     2018-05-17 16:49:03   PortB2          on
     2018-05-17 16:49:03   PortB3          on
     2018-05-17 16:51:06   PortB4          off
     2018-05-17 16:49:03   PortB5          on
     2018-05-17 16:49:03   PortB6          on
     2018-05-17 16:49:03   PortB7          on
     2018-05-17 16:51:06   state           Ok
Attributes:
   IODev      i2cbus
   Interrupt  A0,A1,A2,A3,A4,A5,A6,A7
   InterruptOut connected_active-low
   OnStartup  B0=on,B1=on,B2=on,B3=on,B4=on,B5=on,B6=on,B7=on
   OutputPorts B0,B1,B2,B3,B4,B5,B6,B7
   Pullup     A0,A1,A2,A3,A4,A5,A6,A7
   event-on-change-reading state,PortA0,PortA1,PortA2,PortA3,PortA4,PortA5,PortA6,PortA7
   invert_input A0,A1,A2,A3,A4,A5,A6,A7
   room       Raum1

Frank_Huber

Lists bitte immer in Code-Tags. dann ists besser lesbar.
Du nutzt die Eingänge vom 23017. da musst imho noch irgendwie den Interrupt verdrahten. da kenn ich mich aber nicht aus.

Dein DOIF reagiert nicht auf den Interrupt PIN. der muss triggern denke ich.

wowatsch

Das ist ja alles richtig verdrahtet. Es funktioniert nur ohne die 230v zu belasten. Das heißt wenn an den Relais dann ein 230v Verbraucher angeschlossen ist dann fängt es an zu spinnen. Ich dachte nur dur,, vielleicht hätte jemand schon mal ein ähnliches Problem.

wowatsch

Kann es vielleicht an der Verbindung zwischen Relai Board und MCP23017 liegen? Habe was gefunden: https://www.raspberrypi.org/forums/viewtopic.php?t=36225
Habe mehrmals von solchen Problemen gelesen. Kann vielleicht jemand sagen ob das daran liegt? https://www.raspberrypi.org/forums/download/file.php?id=2702

Frank_Huber

Zitat von: wowatsch am 18 Mai 2018, 08:16:02
Das ist ja alles richtig verdrahtet. Es funktioniert nur ohne die 230v zu belasten. Das heißt wenn an den Relais dann ein 230v Verbraucher angeschlossen ist dann fängt es an zu spinnen. Ich dachte nur dur,, vielleicht hätte jemand schon mal ein ähnliches Problem.
Diese Info ist neu. Das Problem hat folglich mit FHEM nichts direkt zu tun.
Dein Problem ist eher auf der elektrischen Seite.

Wie lang sind deine Kabel zu den Tasten?
Sind die Kabel geschirmt und der Schirm geerdet?
Was für Verbraucher schaltest du?

Gesendet von meinem S60 mit Tapatalk