MCP23017 on Openhab 3.0

Anybody used MCP23017 on OH3.0?

“sudo i2cget -y 1 0x20 0x12”
I can read pin values from command line but when I add binding v3.0 in Paper UI returned channel value is NULL.
and Thing status is like this:

“Status:
UNINITIALIZED
HANDLER_INITIALIZING_ERROR
sun/misc/SharedSecrets”

in log viewer:

“changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR): sun/misc/SharedSecrets”

“Caused by: java.lang.ClassNotFoundException: sun.misc.SharedSecrets cannot be found by org.openhab.binding.mcp23017_3.0.0”

I found in other topic that old .jar bindings will not work with OpenHab 3.
Anyway I tried coping v2.4 to addon folder but no binding showed up on the list and a lot of errors in log viewer.

I found in another forum:
To use Pi4J v1.2’s I2C functionality, sun.misc.SharedSecrets.class is required, but this class can only be used up to Java 8 and cannot be used since Java 9.

I have not used the MCP23017 binding, so I can’t offer help there. If you are looking for an alternate or remote solution you could check out my MQTTany software. It supports MCP230xx devices and communicates over MQTT.

Did you find a solution?
This needs to be fixed - otherwise I can’t upgrade

I’m afraid the mcp23017 binding is at the moment beyond repair. It needs an update of the used pi4j library, but there is no new version available yet.

What about binding for Raspberry onboard GPIOs?
There is no such for v3 I guess.
How do you guys access them easiest way?

@mircopolo @Lars_R MQTTany works with MCP23017 devices and GPIO pins. Using it would allow you to upgrade to OH3 and keep using all your devices. You would just need to setup MQTT things for them and change the channel links on your items, no other changes to your setup would be needed.

Hi there, is any progress on this? I didn´t find any news about this problem and would really need this solution… Many Thanks in advance!!

It basically depends when Pi4J will be ready (with Java11), probably after that MCP23017 binding can be tested if it will work, or there are braking changes in the new library.
Progress at the moment:
https://v2.pi4j.com/about/

I had to downgrade back to OH2. I intensively use MCP23017 and until it is not fixed on OH3 i will have to stick to an older version…

Is there any progress or anything new? I also still can’t use MCP23017 with OpenHAB3

[INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mcp23017:mcp23017:chipA' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR): sun/misc/SharedSecrets

On march 7, 2021 the updated pi4j library was merged: [mcp23017] Update Pi4J to 1.4 so binding works with Java 11 by mrumpf · Pull Request #10293 · openhab/openhab-addons · GitHub. That should fix the java 11 compatibility problem. If you are on an openHAB version after that and it still doesn’t work please open an issue on GitHub to track the problem.

thx @hilbrand

I use openHABian v3.0.2, Java 11.0.11, Pi4J 1.4

With i2cdetect I can detect all of my MCP23017and I/O with i2cset everything worked.
I don’t know if I do sth. wrong.

I have the same problem after switching to OH3. I read that the latest version 3.1.0 was supposed to fix it but I just upgraded and still have the problem.

I have tried it, it works. Go through these steps:

sudo apt-get update
sudo apt-get install i2c-tools libi2c-dev python-smbus

sudo nano /etc/modules
#Add these two lines:
i2c-dev
i2c-bcm2708

sudo nano /boot/config.txt
#Add to the bottom:
dtparam=i2c_arm=on
dtparam=i2c1=on

Do a restart…

sudo adduser openhab i2c
sudo i2cdetect -y 1

sudo apt-get install wiringpi
+
curl -sSL https://pi4j.com/install | sudo bash

The sites where I took these info’s from:

https://pi4j.com/1.4/install.html
https://www.mathworks.com/help/supportpkg/raspberrypiio/ref/add-digital-i-o-pins-to-raspberry-pi-hardware-using-mcp23017.html

2 Likes

Hi @zolee24 !

I’m trying to setup I2C controlling a relay board with 16 relays. I can control everything manually. However, I’m stumbling over the OH3 v3.1.0 setup. I’m running on Pi3, Buster with current kernel. Could you possibly provide short summary/snapshot of what your things, items, and rules look like for something attached to your I2C?

Thank you!

Hello,

Went back to 2.5.10 because there is something wrong with the addon or Openhab3 itself. The MCP23017 binding does not work every time. My guess is that Openhab3 transforms the items into this “UI based” items, and does not take the textual configuration into account (eg. the mcp.items that was put into the items folder)… Meaning this: “While the way of defining an Item using the graphical, interactive UI is different, the elements and the nature of an Item definition are identical using either method.” is not entirely true when using this addon. Have not reported it yet though…

Things list: (you can define them in the UI as well):

Thing mcp23017:mcp23017:B1  "MCP23017 chip B1" [address=20,bus=1] {
    Type output_pin : output#A0
    Type output_pin : output#A1
    Type output_pin : output#A2
    Type output_pin : output#A3
    Type output_pin : output#A6
    Type output_pin : output#A7
    Type output_pin : output#B0
    Type output_pin : output#B1
    Type output_pin : output#B3
    Type output_pin : output#B4
    Type output_pin : output#B5
    Type output_pin : output#B6
    Type output_pin : output#B7
}

Thing mcp23017:mcp23017:B2 "MCP23017 chip B2" [address=21,bus=1] {
    Type input_pin : input#A0   [pull_mode="OFF"]
...

Items list:

Switch	Sw_Living_1	"Living Chandelier" (Lights,Living,LivingRoom,Switches) 	{channel="mcp23017:mcp23017:B1:output#B4", alexa="Switchable"}
Contact	B_Living_1   (Buttons)  {channel="mcp23017:mcp23017:B2:input#B1"}

Rules: (nothing special):

rule "Special Light Button Living 2"

when 
    Item B_Living_6 changed
then
    Sw_Living_1.sendCommand(if (Sw_Living_1.state != ON) ON else OFF)
	Sw_Living_2.sendCommand(if (Sw_Living_1.state != ON) ON else OFF)
end

Hope it helps.

If you are looking for a working solution you could use MQTTany to control your devices. See post #3

Thank you @zolee24 and thank you @CrazyIvan359!!!

The project has DS18B20s paired with the relays controlled by the 23017, I have OH3 setup on a new Pi so there is some incentive to get that configuration working. I appreciate your tip because after I read @zolee24 I was ready to just go with a python script to check status and made adjustments about every minute and use Rokk’s tips once OH3 was fixed.

Unrelated to the current topic, this is my second hit from OH3 - my home alarm system was impacted by the DSC Alarm binding error (ticket #10728). :frowning:

I think I may need to invest the time/energy into being able to compile my own bindings because #10728 looks like a simple fix and maybe I could help help with I2C.?.? CrazyIvan359, your code may be just the learning curve that I need!

Thanks!

@garyn glad to help. If you’re going to get into compiling bindings I recommend using VSCode if you’re already familiar with it, and make sure your system has at least 16GB RAM and a decent multicore processor because the builds are no joke.