I am using a Pico W with a rotary encoder that has a button on the knob. This is software debounced and configured as follows;When I press the button the first few times usually everything is OK and it activates my relay for 3 seconds and shuts it off and only fires one interrupt. My relay is a 2 channel SPDT board and it is powered by the 5v power rail the pico is also on and uses that ground because it has to.
But eventually it will just start acting like the interrupt is constantly firing. I can watch the print message from it firing in the code over and over and over again. Eventually sometimes it will stop. If I pull the button wire, it stops immediately... SOMETIMES. But not always. SO WEIRD
The rotary encoder is wired directly to the pico using the 3v3 as power and the pico on board ground.
I replaced the encoder with another one to make sure that it wasn't bad hardware but it still happens.
There is another single channel relay which does not have this problem. It is similar to the two channel in many ways.
I would be tempted to think that this is flyback or capacitance but I added a way oversized cap and tried a flyback diode with no luck but also...
...it isn't entirely related to the relay changing state because it will just sit there spamming interrupts the entire time the relay is active.
I came from ardu and this is the first time I've encountered this with the pico and I'm not sure what to do or what to change about the config to make it work. I can clearly see a steady light on the screw terminal breakout and there is no interruption in the state for the button pin.
Is this pico bad or something?
MENU DOWN
ROTARY PRESS 1722690043 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690048 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690053 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690057 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690060 (and now onward it just keeps firing the interrupt forever...)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690063
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690066
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690069
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690072
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690075
am I not meant to use interrupts for buttons? do I have to put a scanner in main for the state?
Is it possible that the internal pull up for the pico is not enough???
(the state reads fine by the way there is something wild with the interrupt itself, if I just scan the state in main and call the same function as the interrupt it works 100% fine and there is no bounce or anything,0 but is laggy because it runs in main)
Do I need to fake an interrupt with a thread that scans the state? I am so confused as to why this extremely simple thing wouldn't work
Code:
'e_button' : Pin(21, mode=Pin.IN, pull=Pin.PULL_UP),self.pins['e_button'].irq(trigger = Pin.IRQ_RISING, handler=self.encoderButton)
But eventually it will just start acting like the interrupt is constantly firing. I can watch the print message from it firing in the code over and over and over again. Eventually sometimes it will stop. If I pull the button wire, it stops immediately... SOMETIMES. But not always. SO WEIRD
The rotary encoder is wired directly to the pico using the 3v3 as power and the pico on board ground.
I replaced the encoder with another one to make sure that it wasn't bad hardware but it still happens.
There is another single channel relay which does not have this problem. It is similar to the two channel in many ways.
I would be tempted to think that this is flyback or capacitance but I added a way oversized cap and tried a flyback diode with no luck but also...
...it isn't entirely related to the relay changing state because it will just sit there spamming interrupts the entire time the relay is active.
I came from ardu and this is the first time I've encountered this with the pico and I'm not sure what to do or what to change about the config to make it work. I can clearly see a steady light on the screw terminal breakout and there is no interruption in the state for the button pin.
Is this pico bad or something?
MENU DOWN
ROTARY PRESS 1722690043 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690048 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690053 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690057 (actual press)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690060 (and now onward it just keeps firing the interrupt forever...)
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690063
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690066
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690069
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690072
ROTARY PRESS: FLUSH SYSTEM
ROTARY PRESS 1722690075
am I not meant to use interrupts for buttons? do I have to put a scanner in main for the state?
Is it possible that the internal pull up for the pico is not enough???
(the state reads fine by the way there is something wild with the interrupt itself, if I just scan the state in main and call the same function as the interrupt it works 100% fine and there is no bounce or anything,0 but is laggy because it runs in main)
Do I need to fake an interrupt with a thread that scans the state? I am so confused as to why this extremely simple thing wouldn't work
Statistics: Posted by underhilll — Sat Aug 03, 2024 12:28 pm — Replies 1 — Views 70