-
Notifications
You must be signed in to change notification settings - Fork 302
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
Add support for MCP23008 and MCP23017 ICs #651
base: master
Are you sure you want to change the base?
Conversation
ce07d40
to
0a02261
Compare
Codecov Report
@@ Coverage Diff @@
## master #651 +/- ##
===========================================
+ Coverage 74.84% 86.53% +11.69%
===========================================
Files 22 40 +18
Lines 4214 7823 +3609
Branches 609 0 -609
===========================================
+ Hits 3154 6770 +3616
- Misses 987 1053 +66
+ Partials 73 0 -73
Continue to review full report at Codecov.
|
I did live tests of this implementation with 2 x MCP23017 attached to a Raspberry Pi 3. |
0f87efd
to
6b0d02f
Compare
When called, EventsMixin._fire_event() queries the pin state. Before this change, it happenned that the actual pin state was different from the one known by the poller. _fire_deactivated() was sometimes NOT called, resulting in a buggy behavior.
Because time-dependent tests usually fails. They did randomly on Travis with the previous approach.
6b0d02f
to
7291730
Compare
d7c745e
to
5a1b0dc
Compare
5a1b0dc
to
17e1659
Compare
Before this change, callbacks were ran directly in the poller thread, so when a callback did a long operation, it blocked the whole poller thread.
6e14159
to
0d8474f
Compare
Does this implement the interruption pin for using MCP23017 ports as inputs? |
I don't think that the MCP230xx class belongs to the I think the correct architecture should be to create an This approach doesn't tie the MCP230xx implementation to a specific pin access protocol, you could still use your chosen pin library. |
For instance, I use pigpio for the pin factory because I need a specific method from this library to configure a glitch filter. If I use the MCP23017Factory I cannot use this function from pigpio. May I try to refactor your code architecture as explained? |
@pmuller could you enter this conversation? After studying some of the code and using this pull-request in my application, I've reconsidered my opinion and I think you've used the right approach. I found only a bug so far, somehow in the creation of a |
So, regarding the pull problem, the error occurs because the Also, I found a really complex bug in the Inside it's loop implementation, everytime the poller checks for a pin state change it calls the factory pin creation method for ALL 16 pins. Every. single. loop. Also I think this poller is very inneficient since it does lot's of unnecessary gpio reads. Why is this poller class necessary and not use the default gpiozero behaviour for checking state changes? |
@ffleandro I believe I set the default to "floating" because it is the MCP230xx ICs default (I created another PR to handle this: #658). I don't know what should be the proper default value in the context of gpiozero. Any opinion @bennuttall ?
Yes, but MCP230xxPin objects are cached: https://github.com/RPi-Distro/python-gpiozero/pull/651/files#diff-a583da2ae5f3f1c2e67628bf52236b58R566
The default gpiozero behavior is to rely on factories' native method to be notified of state change (i.e. https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/). But this only works for the Pi's GPIO. For MCP230xx ICs, I only about 2 methods:
I fully agree interruptions is the way to go to prevent useless polling (and resources waste), but I am afraid I lack the necessary expertise to design a generic framework that allows interruption usage with all those configuration options. |
True, although it's ineficient to check for a state change in an unnused pin. Also, if you have more than one Here is a proposition for the
I removed the line |
May I ask/suggest something not strictly related to this PR, but on a similar direction? I mean, you adding not only support for the mentioned ICs, but also doing some ground work for the I2C support itself. I'm very interested in I2C support, and willing to help in its implementation. Although I'm not super experienced with gpiozero nor python, I could lend a hand and hopefully put some other devices in the supported list too. My proposal would be to have the I2C support into it's own PR and specific devices would follow that. Makes sense? |
Any status on this? I'm looking for MCP23017 support as well. |
Great work @pmuller! I just seamlessly integrated an MCP23017 thanks to you. 🎉 @bennuttall is there anything we as the community can do to help speed things up? Specifically, what is missing in this PR to move this from "Less important / not ready" to at least "Less important / ready" (besides the obvious conflicts)? 😃 I'd be willing to help. |
+1 on this. |
I have some questios:
Thanks in advance and sorry for my bad english PS: I am try to buy this chip in the SPI-variant (MCP23Sxx) to demonstrate the cross implementation of the same chip on different kind of busses (I2C and SPI ... etc.) Andy |
I did a bit of digging, and it looks like this is why. And it looks like there's a little bit more info here. 👈 @bennuttall |
Thanks for fast response .... investigating
greets andy
Gesendet: Samstag, 26. Februar 2022 um 15:18 Uhr
Von: "Andrew Scheller" ***@***.***>
An: "gpiozero/gpiozero" ***@***.***>
Cc: "agruenberger" ***@***.***>, "Manual" ***@***.***>
Betreff: Re: [gpiozero/gpiozero] Add support for MCP23008 and MCP23017 ICs (#651)
Why is CI (travis) not working any more
I did a bit of digging, and it looks like this is why. And it looks like there's a little bit more info here. 👈 @bennuttall
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
This is a pull request adding a new set of complex features which function quite differently to the way the rest of the library work. We always wanted to add I2C support for devices such as the expander chips, and had ideas for how best they would fit alongside the rest of the library, but we've since got busy with other projects such as piwheels and since gpiozero works well for its original purpose (making projects with everyday GPIO devices in education) and much more, it's ok to slow/pause development for now.
Travis-CI shut down and now we use GitHub Actions: https://github.com/gpiozero/gpiozero/actions
With the above in mind, the best approach would be to implement your solution in a new project which extends gpiozero classes. Import the bits of gpiozero you need, and build on those foundations. If you wanted to, you could publish this as a new module, so that others can use it. It is not necessary for this functionality to be a part of the core gpiozero library for it to be useful to you and others.] Hope that helps |
Thanks for your quck response, i'll do it as you have been proposed |
Fix #199