Access to MCP23017 from other programs (aside from HA) possible ? #17
Replies: 4 comments 1 reply
-
|
Hi Lars, Can you check mcp23027 visibility (from host/from within container) and report results. $ i2cdetect -y 1If/where the device is visible can you try basic accesses (from host/from within container) and report results as well This should remove your script from the equation and help to root cause the issue. Cheers, PS: probably obvious but to access a shell within your docker image from host $ sudo docker run -it <image_name> /bin/bash |
Beta Was this translation helpful? Give feedback.
-
|
Hi jpc, OK, from the host 'i2cdetect -y 1' produces: 00: -- -- -- -- -- -- -- -- (I do have four MCP23017's ... ) and I can hear the attached relays click, when I run the python script from this page: So all working fine from the host. From within the container:
because I did not have access to i2c-tools there. (So still not quite sure, how I can check, if the MCP23017 is visible from within the container.) However, (Script still runs but relays are not cklicking - as if the commands to the MCP23017 are ending in nirvana ... ) Although, on the host, '$ i2cdetect -y 1' still produces: 00: -- -- -- -- -- -- -- -- And also: gives a nice click on the connected relay. So access to the MCP23017 is still working from the host shell ! So I assume there is some take-over happening on the python(3) level ...) Hope this helps, |
Beta Was this translation helpful? Give feedback.
-
|
Hi Chris, Thanks for the results, I believe I understand now what is happening. MCP23017 has two possible register map (cfr. table 3.1 p12 of MCP23017 dataheet); default one is IOCON.BANK = 0 while HA-mcp23017 integration uses IOCON.BANK = 1 in order to be compatible/usable with mcp23008 as well. Therefore, I suppose that if you change IODIRA = 0x00 # Pin direction register
OLATA = 0x14 # Register for outputs
GPIOA = 0x12 # Register for inputsby IODIRA = 0x00 # Pin direction register
OLATA = 0x0a # Register for outputs
GPIOA = 0x09 # Register for inputsYour script should work Now, be carefull with scripts changing settings of the device as they may interfere with expected HA-mcp23017 behavior, i.e. OK to read GPIO or write OLAT (HA-mcp23017 will track that) but nothing more, e.g. remove following lines from the script when HA-mcp23017 is running (device configuration handled there) # Set all GPA pins as outputs by setting
# all bits of IODIRA register to 0
bus.write_byte_data(DEVICE,IODIRA,0x00)
# Set output all 7 output bits to 0
bus.write_byte_data(DEVICE,OLATA,0)Cheers, PS: you can install i2c-tools in HA container by running apk add i2c-tools |
Beta Was this translation helpful? Give feedback.
-
|
Hi Lars, Thanks for your feedback, always appreciated :-)! Wrt chip mode, "byte mode" (IOCON.BANK = 1) was the original mode for devices with 8 I/Os while "sequential mode" was introduced for 16 I/Os devices like mcp23017 to enable read/write of the same register in two different banks with a single i2c transaction using automatic address increment. They should have kept compatible/byte mode as default for all devices and a clean way to set/get the mode you are in (rather than a workaround to implement this). Wrt your use case, I'm not sure what your script is doing but can't that be implemented as an automation within HA ? (and avoid conflicts between two possible clients) Cheers, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Kia Ora from New Zealand and thank you for writing this integration for HA ! :-)
I would have one question :
Once this is installed and running on on a Raspberry Pi, is it at all possible to control pins of the MCP23017 from a different task - say a standalone python script ?
I have a new installation of HA supervised in Docker on a brand new install of BullsEye and my python3 script runs fine from a standard system shell (not inside a docker container and not in HA), controlling the pins of the MCP23017.
As soon as I restore my backup of HA, which has HA-mcp23017 installed, my script cannot control the MCP23017 anymore,
while - of course - I CAN control them from within HA then.
I am still to find out, if this changes definitely after installing your HA-mcp23017 integration (only) or if this might be caused by some other thing contained in my restored backup...
From your description, where you are saying that you are pulling pin states every 100ms, I would gather though, that installing this on HA will make access to the MCP23017 exclusively to HA and no other task can access the chip via I2C, while your intergration is controlling it.
Can you confirm this, or should it still be possible to control some pins from within HA and some others from a different task ?
Thank you for any help with this,
best regards
Lars
Beta Was this translation helpful? Give feedback.
All reactions