Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

get_ functions in Python Libraries?

The IO Pi Plus is a 32 channel MCP23017 GPIO expander for the Raspberry Pi

1033 Views - Created 17/06/2020

17/06/2020

Posted by:
PeterB

PeterB Avatar

Location:
Philippines

I have/am using Python Libraries dating from August 2018.

The class IO in the ExpanderPi file implements some 'get_port' functions (get_port_direction, get_port_pullups & get_port_polarity). These are missing from the IOPi file. Further, I note that the current release of the libraries omit these functions both in the Expander and the IO files.

Is there a good reason for these omissions?

Presumable, if the get_port functions would still work, then get_pin functions could also be implemented?

My reason for investigating these functions is that I'm looking for a method to determine whether the hardware has already been set up in the case that the software has to restart.

Oops, I've just noticed that the class __init__ function is (needlessly/just for consistency?) writing some registers to their default POR/RST values. I guess that I would have to disable some of that functionality in order to achieve what I want (which is to eliminate lights flickering in the event of software restart)!

I'll have to have a play!

17/06/2020

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hello Peter

Sorry I didn't realise I had deleted the get_ functions from the Expander Pi library. I made some updates to the IO Pi library which I copied across into the Expander Pi library and I must have accidentally removed those functions in the process.

I have added the missing functions back into the Expander Pi library and also added them into the IO Pi library. I will add get_pin functions into both libraries over the next couple of days.

Both the IO Pi and Expander Pi libraries now include an initialise parameter which can get set to False when you create an IOPi or ExapanderPi object. This will stop the port direction and pull-ups from being set to their default values so the boards will keep their existing configuration.

To use the initialise parameter on the IO Pi you would use the following code.


iobus = IOPi(0x20, False)


On the Expander Pi you would use.


iobus = ExpanderPi.IO(False)


You can download the updated libraries from our GitHub repository at https://github.com/abelectronicsuk/ABElectronics_Python_Libraries

17/06/2020

Posted by:
PeterB

PeterB Avatar

Location:
Philippines

Wow, that is so very helpful, Andrew. I'm really grateful to you! I was thinking that I would customise the libraries myself, but I think that you've covered it all!

Of course, when I'm using IOPi and ExpanderPi together, I have to use the IO library from the IOPi file.

In my application, adding the parameter to the class initialisation simply requires a minor edit to my .xml configuration file! :)

Just had a qiuick look at the library code - looks good. I'll give it a try tomorrow as it's almost 11pm here now.

Sign in to post your reply


Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.