-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
[Bug] GPIO buttons need to be debounced (Program can restart on cancel on Technic Hub) #716
Comments
It's the button: from pybricks.hubs import TechnicHub
from pybricks.parameters import Button
from pybricks.tools import wait, StopWatch
hub = TechnicHub()
hub.system.set_stop_button(None)
watch = StopWatch()
# Print the time between button state changes
state = False
while True:
now = bool(hub.button.pressed())
if now != state:
print(watch.time())
watch.reset()
state = now Continuously clicking the button gives a steady output and sometimes jitter like this:
|
Also seen on cityhub running from pybricks.hubs import ThisHub
# from pybricks.parameters import Button
from pybricks.tools import StopWatch
# from pybricks.tools import wait
hub = ThisHub()
hub.system.set_stop_button(None)
watch = StopWatch()
# Print the time between button state changes
state = False
while True:
now = bool(hub.button.pressed())
if now != state:
print(watch.time())
watch.reset()
state = now Console:
|
Not seen on the movehub (not in a few minutes) on |
I wasn't able to reproduce this on my Technic hub but was able to reproduce on my City hub. And only one time I saw a 4 ms time on the Essential hub (no 0. or 1 on that hub). |
Would an interrupt approach have less overhead than polling? And/Or are there any ways to configure the pins differently (avoiding any software process) or wouldn't this help due to how they are wired? |
Technically, I suppose would be lower overhead in terms of total execution time, but polling every 10 milliseconds is probably hardly measurable (e.g. in terms of pystones). And using interrupts is quite a bit more complex to implement. There isn't any hardware debounce on STM32 AFAIK. |
Describe the bug
On a Technic Hub, the user program sometimes restarts when you stop it with the button. I have not seen this on the other hubs, yet.
It's possible we've had this for a long time, but maybe it is more noticable now we support restarting programs with the button.
Maybe we can also reproduce this within a user script to rule out any download-and-run logic issue.
To reproduce
This is not specific to any program, but the following helps to visualize it. When canceling, the light becomes blue when you press, and sometimes it turns green again upon release, which shouldn't happen.
The text was updated successfully, but these errors were encountered: