Skip to content

Character_LCD_I2C: add support for PCF8574 I2C expander backpack #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Roman3349
Copy link

No description provided.

@Roman3349 Roman3349 force-pushed the feature/i2c-expander-pcf8574 branch 2 times, most recently from a2a3a43 to 3f0a6c3 Compare February 6, 2025 00:28
@Roman3349 Roman3349 force-pushed the feature/i2c-expander-pcf8574 branch from 3f0a6c3 to daa56fb Compare February 6, 2025 00:30
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this! It fixes a long-requested need, e.g. #81.

I have some higher-level comments about how the code is structured:

The PCF8574 support uses the superclasses _write8() support, which sets the bits one at a time. In #80, I changed the code to write the bits four at time, which sped up things considerably. It would be good to do that here too. Unfortunately, the 8-bit-wide GPIO support for the two libraries is not the same. However, small wrapper classes could be written to make an common API. Then an instance of either wrapper class could be passed into the constructor, instead of passing in an instance of one of the library objects.

In addition, this code imports both the PCF8574 and MCP23008 libraries. On boards with limited RAM (e.g. SAMD21), this will use up noticeably more RAM. So passing in a wrapper class instance will avoid needing to import both libraries at once.

An example of this wrapper technique is in https://github.com/dhalbert/CircuitPython_LCD. The internal API presented by that library is not the same, so you wouldn't copy the code directly, but the technique is what I mentioned.

Would you be willing to do this? This would allow other I/O expanders in the future to be added in a modular way (not that I can think of any right now). Thanks.

@Roman3349
Copy link
Author

@dhalbert Thank you for your code review.

I fixed the code so that when using PCF8574 the bits are written in bulk similar to MCP23008.

When I have some free time, I'll try to develop a system of wrappers that will allow to extend the library with possible additional I2C expanders and possible different GPIO pin mappings when the used I2C backpack is wired differently.

@Roman3349 Roman3349 force-pushed the feature/i2c-expander-pcf8574 branch from e2b618f to 9cecf0c Compare February 6, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants