Pi4B, OH3 and MCP23017

Hello
Pi4B, OH3 and MCP23017…cant switch pins
Log shows:
2021-02-12 15:22:00.978 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing ‘mcp23017:mcp23017:MCP23017’ changed from ONLINE to OFFLINE (CONFIGURATION_ERROR): Tried to access not available I2C bus: null

2021-02-12 15:22:00.983 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing ‘mcp23017:mcp23017:MCP23017’ changed from OFFLINE (CONFIGURATION_ERROR): Tried to access not available I2C bus: null to ONLINE

But i2C bus is working can access it with i2cset and its possible to switch LEDs which are connected to the 23017.

https://pi4j.com/1.3/install.html

.) Pi4J_1.3 is installed
.) “unofficial” version of wiringPi 2.6 for raspberryPi4B should be installed.
apt list wiringpi… shows —> wiringpi/testing, 2.50 armhf (installiert) ???
.) gpio command line tool is available
.) user “openhab” und “openhabian” where added to groups “i2c” and “gpio”.

NOTE: As of v1.3, Pi4J requires Java 8 JRE/JDK
Installed is 11
Maybe thats the problem ?

Any ideas ?

Thank you…

Looks relevant -

Thank you will try it with MQTTany.

Hi all,

could anybody provide an example on thing, item, rule part. I am not an expert and would like to convert from OH2.5 to OH3… so I cannot wait to get the MCP23017 Binding issue (Pi4j) fixed. Appreciate your help!
Many Thanks…!

Have solved it with MQTTany, works perfect.

Can you provide configuration example for MCP23017 ?
So it would be mqttany.yml file

https://crazyivan359.github.io/mqttany/start.html

is following this instructions enough to make it work with OH?

What should enter here?

/etc/systemd/system/mqttany.service

and add the username and group that MQTTany should run as:

User=
Group=

Hello,

i get the following results:

Pin in mqttany / MCP23017 pin / Chip Pinname Port

00		21		GPA0
01		22		GPA1
02		23		GPA2
03		24		GPA3
04		25		GPA4
05		26		GPA5
06		27		GPA6
07		28		GPA7

08		1		GPB0
09		2		GPB1
10		3		GPB2
11		4		GPB3
12		5		GPB4
13		6		GPB5
14		7		GPB6
15		8		GPB7

This means:
Pin value 00 in mqttany switches Pin21 - GPA0 of the MCP23017

With this configfile…

mqtt
  host: '.........'
  root topic: 'roottopic'
i2c:
  polling interval: 60
  mcp23017-1:
    device: 'mcp23017'
    bus: 1
    address: 0x20
    mcp230xx:

      pin-a0:
        pin: 00
        direction: 'output'
        initial state: OFF

      pin-a1:
        pin: 01
        direction: 'output'
        initial state: OFF

…and this OH3 command topic… roottopic/mcp23017-1/pin-a0/set
Or test it with
mosquitto_pub -d -t roottopic/mcp23017-1/pin-a0/set -m “ON” …switch GPA0 to ON.
mosquitto_pub -d -t roottopic/mcp23017-1/pin-a0/set -m “OFF” …switch GPA0 to OFF.

mosquitto_pub -d -t roottopic/mcp23017-1/pin-a1/set -m “ON” …switch GPA1 to ON.

Cant upload here .yml File. Where should i send it ?

Peter

1 Like

It’s almost working :slight_smile:

So mqttany starts correctly, I can see topic elements in MQTT Explorer, even access output pins from OpenHub and they change for a moment but after polling interval pin-a0 which was set by hand to ON is OFF again so I cannot check if voltage really changed.

I tried read inputs from MCP2307 but no reaction however using
Read GPIO-Byte from Port B:

sudo i2cget -y 1 0x20 0x13

gives proper results

      pin-b0:
        pin: 08
    direction: 'input' 
    ### Pin Resistor
    resistor: 'pulldown' # can be 'pullup', 'pulldown', or 'off'

The only thing that is fully correct is GPIO input read on pin 17, it immediately changes state on OH when I connect cable to Raspberry pin.

Any ideas what else could be wrong?

What mqttany version are you using ?
Latest is 0.14.3

@mircopolo Your configuration above looks good, but you need to be running the latest v0.14.3 as it includes some bug fixes for the MCP230xx devices.

Now with v0.14.3 I can read inputs on MCP23017 :slight_smile:
My last problem is that outputs gets reset to OFF every polling interval…
no matter if I set it to ON from MQTT Explorer or OpenHab interface


2021-03-17 13:00:44,301 [INFO ] [core                    ] MQTTany 0.14.3-dev starting
2021-03-17 13:00:44,302 [WARN ] [core                    ]
2021-03-17 13:00:44,303 [WARN ] [core                    ] ########  DEVELOPMENT VERSION  ########
2021-03-17 13:00:44,304 [WARN ] [core                    ] #                                     #
2021-03-17 13:00:44,305 [WARN ] [core                    ] #  This is a development version and  #
2021-03-17 13:00:44,306 [WARN ] [core                    ] #    may be incomplete or unstable    #
2021-03-17 13:00:44,307 [WARN ] [core                    ] #                                     #
2021-03-17 13:00:44,308 [WARN ] [core                    ] #######################################
2021-03-17 13:00:44,309 [WARN ] [core                    ]
2021-03-17 13:00:44,421 [INFO ] [core.gpio               ] Detected board: RASPBERRY_PI_3B_PLUS
2021-03-17 13:00:44,771 [INFO ] [core                    ] Module 'mqtt' started successfully
2021-03-17 13:00:44,778 [INFO ] [core                    ] Module 'gpio' started successfully
2021-03-17 13:00:44,785 [INFO ] [gpio.digital            ] Setting up 'gpio17' on GPIO17 as INPUT
2021-03-17 13:00:44,789 [INFO ] [gpio.digital            ] Setting up 'gpio18' on GPIO18 as OUTPUT
2021-03-17 13:00:44,787 [INFO ] [core                    ] Module 'i2c' started successfully
2021-03-17 13:00:44,801 [INFO ] [mqtt                    ] Connected to broker '192.168.0.15:1883'

Sounds like a bug. Please open an issue over on github and attach a log from a test run using the -vv option.

CrazyIvan359 helped me with this. It was my mistake. I did not use “set” command so output was not staying in ON state. Like on this video

So the path should be like that:
image

Look at my post above…i wrote:

…and this OH3 command topic… roottopic/mcp23017-1/pin-a0/set

1 Like