[SOLVED] MCP23017 - Contact (Input) and Switch (Output)

No idea, it’s your hardware. Put a meter on your input pin, find out.

You did see that the binding Thing configuration has options?

As @rossko57 mentioned use a meter and see whats happening or simply add a 10k resistor as a pull-up or pull-down. Using a 10k resistor as either pull up or down wont damage the circuit and will be a quick way to test if you need it.

Some reference material if needed:

https://www.electronics-tutorials.ws/logic/pull-up-resistor.html

Hello together,

made a quick test with the metioned 10k resistor and it works :slight_smile: I also hat a quick view in the documetation and found out, that I misunderstand it. Thank a lot guys!

Now “only” question 2 is open. I made two test, one thing with

Type output_pin : output#A0 [default_state="HIGH"]

and one with

Type output_pin : output#A0 [default_state="LOW"]

The first one leads to a “LOW” (I realy mean LOW) and the second one to a “HIGH” (and again I mean HIGH). And nothing changes when I use the switch of BASIC UI (see describtion above). I would like to have a switch which gives a short “HIGH” signal to switch the connected relay.

Once again thank you for your help!

The default state is just that, what to set the output at start up. It will stay that way until you tell it to do something else.

What does your events.log show you? Does anything happen at your output pin, you haven’t made that clear.

If you want some time effect, you’ll have to provide that by other means once you have the output working.

Have you tried a rule in OH to make the switch change states when your output changes?

Just an FYI: If your familiar with Python have a look at [beta testers wanted!] Jython addon w/ helper libraries (requires OH 2.5.x)

Hey,

I just have the following rule in place:

rule "living_room_led contact"
when
    Item living_room_led_contact changed to OPEN
then
    if (living_room_led_switch.state == OFF) {
        living_room_led_switch.sendCommand(ON)
    }
    else {
        living_room_led_switch.sendCommand(OFF)
    }
end

This is the one from the example. Using the Hardware switch which is connected to the input pin leads to a change of the Status of the switch on the sitemap. What would be the command to change the output pin? I cannot find anything.

Thanks and regards
BrainPain

It’s the command that you are using.
living_room_led_switch.sendCommand(ON)
etc.
The command event will be visible in your events.log
It gets passed to any linked channel and on to the binding for action.

If that’s not working, you need to look closely at your Thing/channel configuration.
Not all bindings are very good at picking up Thing edits , so make sure you’ve restarted the binding package since the last changes you made.

That’s good, your input is working, your rule is working, the command is being issued, and openHAB’s autoupdate feature is setting your Switch Item’s state.
That doesn’t mean the binding is working properly.

Thanks a lot for the fast reply.

Right now I am really desperated. The inputs are still working perfectly. I even added a second MCP23017 and declared one for inputs only and the other for outputs only:

Thing mcp23017:mcp23017:input1 "MCP23017 Input 1" [address=20,bus=1] {
    //input-Pins
    Type input_pin : input#A0
    Type input_pin : input#A1
    Type input_pin : input#A2
    Type input_pin : input#A3
    Type input_pin : input#A4
    Type input_pin : input#A5
    Type input_pin : input#A6
    Type input_pin : input#A7

    Type input_pin : input#B0
    Type input_pin : input#B1
    Type input_pin : input#B2
    Type input_pin : input#B3
    Type input_pin : input#B4
    Type input_pin : input#B5
    Type input_pin : input#B6
    Type input_pin : input#B7
}

Thing mcp23017:mcp23017:output1 "MCP23017 Output 1" [address=24,bus=1] {
    //output-Pins
    Type output_pin : output#A0 [default_state="HIGH"]
    Type output_pin : output#A1 [default_state="HIGH"]
    Type output_pin : output#A2 [default_state="HIGH"]
    Type output_pin : output#A3 [default_state="HIGH"]
    Type output_pin : output#A4 [default_state="HIGH"]
    Type output_pin : output#A5 [default_state="HIGH"]
    Type output_pin : output#A6 [default_state="HIGH"]
    Type output_pin : output#A7 [default_state="HIGH"]

    Type output_pin : output#B0 [default_state="HIGH"]
    Type output_pin : output#B1 [default_state="HIGH"]
    Type output_pin : output#B2 [default_state="HIGH"]
    Type output_pin : output#B3 [default_state="HIGH"]
    Type output_pin : output#B4 [default_state="HIGH"]
    Type output_pin : output#B5 [default_state="HIGH"]
    Type output_pin : output#B6 [default_state="HIGH"]
    Type output_pin : output#B7 [default_state="HIGH"]
}

When I use the switch on the sitemap I just get the following output in event.log:

2020-03-15 06:25:47.764 [ome.event.ItemCommandEvent] - Item 'living_room_led_switch' received command OFF

2020-03-15 06:25:47.780 [nt.ItemStatePredictedEvent] - living_room_led_switch predicted to become OFF

2020-03-15 06:25:47.794 [vent.ItemStateChangedEvent] - living_room_led_switch changed from ON to OFF

But nothing happens. The Outputpin seems not to get the status “HIGH”. I do not belive that this has something to do with my set-up (the pin is just connected to an LED with resistor) as the LED ist on when the default_state is set to “LOW”.

I don’t know what the reason could be.

You’d better set DEBUG on the binding, and see what it is doing with your commands.

Tell us about what “does not work” about 2.5.x version of this binding?
Using 2.4 version might well give you problems in a 2.5 system, not the best thing to do, if you can help it.

You’ve not mentioned observing any of the dependencies in the binding docs e.g. installing wiringPi

Good evening,

I installed wiringPi mentioned in the docs. I will check the debugging mode in the next days. Thanks for the Tip!

I posted the error I had with the binding 2.5 here. I did not find any solution but would be happy, if you have a hint.

Best regards
BrainPain

Hello everybody,

I now tried to use “org.openhab.binding.mcp23017-2.5.3-SNAPSHOT.jar”. The good thing is that I do not have the same problem like I had with the version installed via Paper UI. The bad thing is, that I have the same problem like written above:

  • Inputs worked perfectly
  • Outputs don’t work

Now I set debugging on the binding like rossko57 said and get the following feedback when switching it on via Basic UI:

2020-03-16 11:22:56.837 [DEBUG] [017.internal.handler.Mcp23017Handler] - Received command: ON on channelGroup output on channel A0

2020-03-16 11:22:56.838 [DEBUG] [017.internal.handler.Mcp23017Handler] - Defined channel in group: output. Valid: true

==> /var/log/openhab2/events.log <==

2020-03-16 11:22:56.842 [ome.event.ItemCommandEvent] - Item 'living_room_led_switch' received command ON

==> /var/log/openhab2/openhab.log <==

2020-03-16 11:22:56.842 [DEBUG] [017.internal.handler.Mcp23017Handler] - Is channel A0 in supported channels: true

2020-03-16 11:22:56.847 [DEBUG] [ernal.handler.Mcp23017PinStateHolder] - Getting output pin for channel mcp23017:mcp23017:output1:output#A0

2020-03-16 11:22:56.850 [DEBUG] [017.internal.handler.Mcp23017Handler] - got output pin "A0" <GPIO A0> for channel mcp23017:mcp23017:output1:output#A0 and command ON [active_low=false, new_state=HIGH]

2020-03-16 11:22:56.867 [DEBUG] [017.internal.handler.Mcp23017Handler] - Received command: ON on channelGroup output on channel A0

2020-03-16 11:22:56.869 [DEBUG] [017.internal.handler.Mcp23017Handler] - Defined channel in group: output. Valid: true

2020-03-16 11:22:56.872 [DEBUG] [017.internal.handler.Mcp23017Handler] - Is channel A0 in supported channels: true

2020-03-16 11:22:56.874 [DEBUG] [ernal.handler.Mcp23017PinStateHolder] - Getting output pin for channel mcp23017:mcp23017:input1:output#A0

2020-03-16 11:22:56.879 [DEBUG] [017.internal.handler.Mcp23017Handler] - got output pin "A0" <GPIO A0> for channel mcp23017:mcp23017:input1:output#A0 and command ON [active_low=false, new_state=HIGH]

==> /var/log/openhab2/events.log <==

2020-03-16 11:22:56.884 [nt.ItemStatePredictedEvent] - living_room_led_switch predicted to become ON

And when I switch it off:

2020-03-16 11:27:32.300 [ome.event.ItemCommandEvent] - Item 'living_room_led_switch' received command OFF

==> /var/log/openhab2/openhab.log <==

2020-03-16 11:27:32.312 [DEBUG] [017.internal.handler.Mcp23017Handler] - Received command: OFF on channelGroup output on channel A0

2020-03-16 11:27:32.319 [DEBUG] [017.internal.handler.Mcp23017Handler] - Received command: OFF on channelGroup output on channel A0

2020-03-16 11:27:32.322 [DEBUG] [017.internal.handler.Mcp23017Handler] - Defined channel in group: output. Valid: true

==> /var/log/openhab2/events.log <==

2020-03-16 11:27:32.321 [nt.ItemStatePredictedEvent] - living_room_led_switch predicted to become OFF

==> /var/log/openhab2/openhab.log <==

2020-03-16 11:27:32.324 [DEBUG] [017.internal.handler.Mcp23017Handler] - Is channel A0 in supported channels: true

2020-03-16 11:27:32.327 [DEBUG] [ernal.handler.Mcp23017PinStateHolder] - Getting output pin for channel mcp23017:mcp23017:input1:output#A0

2020-03-16 11:27:32.330 [DEBUG] [017.internal.handler.Mcp23017Handler] - got output pin "A0" <GPIO A0> for channel mcp23017:mcp23017:input1:output#A0 and command OFF [active_low=false, new_state=LOW]

2020-03-16 11:27:32.320 [DEBUG] [017.internal.handler.Mcp23017Handler] - Defined channel in group: output. Valid: true

2020-03-16 11:27:32.340 [DEBUG] [017.internal.handler.Mcp23017Handler] - Is channel A0 in supported channels: true

2020-03-16 11:27:32.342 [DEBUG] [ernal.handler.Mcp23017PinStateHolder] - Getting output pin for channel mcp23017:mcp23017:output1:output#A0

2020-03-16 11:27:32.343 [DEBUG] [017.internal.handler.Mcp23017Handler] - got output pin "A0" <GPIO A0> for channel mcp23017:mcp23017:output1:output#A0 and command OFF [active_low=false, new_state=LOW]

==> /var/log/openhab2/events.log <==

2020-03-16 11:27:32.345 [vent.ItemStateChangedEvent] - living_room_led_switch changed from ON to OFF

I am a very beginner running out of ideas how to fix it and looking forward for you help!

Best regards
BrainPain

Have you some other utility running, that has reserved this pin or set it into read mode? You would expect a complaint about permissions or such if you had, though.

Thanks for the fast reply. No, this is the only binding I installed and I have no other programms etc. installed.

You’re supposed to have this wiring-Pi thing installed.

Have tried it’s command line gpio tool?

Yes, I tested if I can use it with the following command:

man gpio

I received a feedback. Do you need a specific output?

Does it work, can you control the pin with gpio that you cannot control from openAB?
I don’t need any output, I’ve no idea what to expect or how this binding works.

Do you know how to use gpio command tool and how to command a mcp23017-pin? I will try to do so this evening or tomorrow.

No idea

http://wiringpi.com/the-gpio-utility/

Another thought - confident you are looking at the correct pin? Your [default_state=“HIGH”] experiment should have confirmed that.

You are the best! I have checked the wireing a thousand times but you let me have a look at it again. I connected A7 instead of A0. Now it workes and I just have loop which is a problem of the rule. This should be a problem which I can solve by myself.

Sorry for bothering you the last days with such a stupid mistake. I will write a summary this evening.

Thanks again an best regards
BrainPain