-
Notifications
You must be signed in to change notification settings - Fork 24
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
Interrupt issue in MicroPython when using multiple i2cencoders #22
Comments
This solution is a bit of a hack, but I've discovered if I check the pin status in the interrupt callback, I can determine whether or not to call updateStatus() and keep from crashing the microcontroller:
Do you have any ideas as to why the interrupt callback is firing after the pin returns high, and why this would only happen with multiple i2cencoders? |
This still seems like a hack, but I've discovered that if I reinit the interrupt pin inside the Encoder_INT function, the continuous calls to the function cease. I'm now getting solid, consistent callback triggering, like with the stand-alone i2cencoder.
I did modify the i2cEncoderLibV2 library slightly to include:
This allows the callbacks to know which i2cencoder triggered it. I would like to have your thoughts on this approach. Thank you, |
Hello, |
Thanks for the reply... In testing this work around mentioned above, eventually, after some number of interactions with the i2cencoder, the interrupt stops firing. So it seems I have three options:
I'll let you know how it goes. Cameron |
A follow-up here... I've been pretty successful using four I2CEncoders with my project. I did settle with a separate GPIO pin for each encoder's interrupt. I was never able to figure out why the interrupt callback kept firing when trying to poll the encoders to see which fired when sharing interrupt pins. What I'm seeing now that maybe I should create a new issue about is that during operation, several times, I've seen an encoder become unresponsive. Sometimes, the other encoders continue to work. Other times, the whole program crashes. I attribute this to I2C bus overruns. I'm currently running with encoder.writeAntibouncingPeriod(40) for each encoder. Is this the only deterrent to slow down I2C comms? In my project, during MIDI playback, which is in it's own thread, I have four encoders controlling four output levels in the main thread. The code is set up so that the encoders scale the duty cycle of each output and the RGB LED in each encoder shows a color indicative of the output level (green, to yellow, to red). I also have an elapsed time display running. While the MIDI file is playing and adjusting the encoders, sometimes I see this problem. In these cases, the encoder adjustment is triggering back-to-back calls to readEncoder8() and writeRGBCode(), one triggering the other. Is the solution here to queue the comms? I would certainly rather have a slight delay in the RGB color changing than the program be interrupted. Thank you, |
Hello,
I'd like to use the i2cencoders for a project that is coded in MicroPython. I wasn't able to find an existing library, so I ported the Python library to MicroPython here: https://github.com/cameronprince/i2cEncoderLibV2
Everything has been working well with a single i2cencoder, but once I added additional i2cencoders to the bus, the interrupt pin sticks low on the first interaction with any i2cencoder. This causes the interrupt handler to fire continuously until the ESP-WROOM-32 grinds to a halt.
My initial order from you was for five of the i2cencoders. I soldered four together using the castellations and have one stand alone. The stand-alone i2cencoder has the same address (0x50) as the first i2cencoder in the group of four. Both of these have the i2c bus pull-up pads soldered.
When testing the four i2cencoders together, I initially had a single set of callbacks that were being shared with all four i2cencoders. I thought this might have something to do with the problem, so I switched to separate callbacks. This made no difference. I also tried initializing each of the four individually, but this also made no difference. Additional delays were tried in various places, as well. All four have the same problem, but the stand-alone continues to work fine by itself.
Here is my test code:
With the four i2cencoders, this is the output in which I rotated the first i2cencoder two detents:
The Encoder_INT method fires continuously until I reset the microcontroller.
This is the output when testing with the stand-along i2cencoder:
This output stops after each interaction.
Would you have any idea as to what might be happening?
Thank you,
Cameron
The text was updated successfully, but these errors were encountered: