Problems with setWatch #5076
Replies: 1 comment
-
Posted at 2015-10-17 by @allObjects Had similar issues that the event queue picked up more than sunchronously could be handled. Therefore, I used the setWatch-es non-repeated for trigger the read the status (delayed). Initially I built this keypad module the same way and then changed it to overcome these out-of-sync issues... Only afterwards I became aware of the existing one which uses a similar approach SW and HW as yours... and most likely has the same issues. I use the two different edges in one-time setWatches and sufficient debounce... that will solve your issue... and for adding a separate layer of stability, you can place on switch change a timeout to change state again after may be 500...1000 ms. Posted at 2015-10-17 by @gfwilliams What happens if you change:
into
Not sure, but it would be interesting to see. I don't think the issue is that the queue is overflowing (you'd see with Posted at 2015-10-18 by Rollo @allObjects thanks to your suggestions I have played with different timers and debounce values again and I think I'm getting somewhere. @gfwilliams it's even less reliable this way, it's difficult to describe LED's behavior now so I have changed the code to use First try:
Now let's try with
Any ideas, please? Is my wiring ok? Posted at 2015-10-20 by @gfwilliams Strange... Your wiring looks ok, but I just had a thought: Is the pullup resistor you have actually connected and working? Maybe try Because it could be that when you close the reed switch, that's fine and you get a 0. But when you open it, the pullup isn't there and it just 'floats' - which would mean that you get all kinds of readings - and potentially One other thing to try is to put small (0.1uF?) capacitor across the reed switch. It shouldn't be needed, but it would stop the signal changing so frequently and causing problems. Posted at 2015-10-20 by @allObjects Before implementing the keypad un-biased myself, I felt understanding how Espruino's event queue and setWatch()'s debouncing works... after all I implemented Resistive Touchscreen directly (no touch controller) and used it successfully in multiple applications, such as UI Module w/ Buttons, Checkboxes,... for Display w/ Touchscreen and Puzzle16+ Game on ILI9341 2.8" 262K Color TFT LCD w/ Resistive Touch Screen, and also the press-time detection in Software Buttons - Many buttons from just one hardware button. After implementing the keypad, I'm not so sure anymore about how they work - more precisely: how my code should interact with them properly - especially the way how I tested it: I just used a wire connected (firmly) to the driver side - output - (high/low - 3.3V/GND) and touching the - input - GPIO 'pin' (castellation / board pad, header pin). The moving wire may have just overstepped the working boundaries of the debounce, because I got a flurry of events (callback calls), no matter how I did set the debouncing. Therefore, I switched to the setup as outlined:
If I do not see any 'on' in step 2 - check/scan state - I consider the trigger as an errant (button not pressed long enough), and return right away to step 1. Even though this setup made it work for me, there is still the possibility that step 3 - watchng the switch turning 'off' - will not trigger, because it's setup was too late and the switch had already returned to initial - 'off' - state. To make it more predictable, a timeout - 'safety net timer' - has to be setup at the same time as the setWatch is set to check the state... just in case... ;-). If the state shows (still) 'on', the setWatch will eventually fire. If the state is 'off', the watch has to be called off (clearWatch), and process has to return to step 1. If the watch fires before the 'safety net timer' expires, the timer has to be cleared when returning to step 1. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-10-17 by Rollo
Hello, I'm having problems with Pico and magnetic reed switches.
The idea is that on board LED indicate state of that switch i.e. green LED on when open, green LED off when closed. It all works well at first but when I quickly toggle the switch for a little while then LED gets "out of sync" with my switch, that is it lights green when closed.
I'm having this issue both with pull-up and pull-down connections, tried with a different switch and debounce values. I must be missing something - but what? :)
Example code:
Beta Was this translation helpful? Give feedback.
All reactions