Page 1 of 1

One Button Code Lock

Posted: Sun May 05, 2019 11:43 am
by Michel De Meester
Hello All,

Sorry for writing in "bad English" but I'm living in the Flemish speaking part of Belgium.

I'm building a simplified alarm system (RPI3 and python 3.7) using some (magnetic) door switches and push buttons.
One of these push buttons will be used to activate / deactivate the alarm.

What Do I want this button to do:

- When the button is pushed in a "morse - alike" pattern the alarm should be unlocked. (short and long presses)
- Of course there has to be some "tolerance", It's impossible to press "the correct pattern - timing" every time again.

I already have some buttons defined using interrupts:

Code: Select all

GPIO.add_event_detect(dct_DK, GPIO.BOTH, callback=my_callback_dct_duivenkot, bouncetime=300)
GPIO.add_event_detect(dct_KO, GPIO.BOTH, callback=my_callback_dct_koer, bouncetime=300)
GPIO.add_event_detect(dct_SL, GPIO.BOTH, callback=my_callback_dct_sloep, bouncetime=300)
GPIO.add_event_detect(but_AD, GPIO.FALLING, callback=my_callback_but_actdeact, bouncetime=300)
GPIO.add_event_detect(but_SL, GPIO.FALLING, callback=my_callback_but_sloep, bouncetime=300)
It's the last button (but_SL) that should do the job, it's wired btween the GPIO and ground, and internally pulled up by using:

Code: Select all

GPIO.setup(but_SL, GPIO.IN, pull_up_down=GPIO.PUD_UP)
"my_callback_but_sloep" is the routine that is called when the button is pressed and where the magic should happen :-)

I think there will be some timers involved but I really don't know where to start writing this routine.

Has somebody any idees to get me started.

Thanks in advance,
Michel

Re: One Button Code Lock

Posted: Sun May 05, 2019 2:00 pm
by MrYsLab
If you absolutely have to a single button used to input the code, then as you say, the synchronization of human to computer timing is difficult. Perhaps, you could provide an LED that lights to tell the user when to enter the next press. If there is no press between flashes, then the input is considered "0".

If you have room on your panel for one or more additional switches, you could utilize one switch as an "enter" key. Using multiple switches would allow for a more complex entry code.

Re: One Button Code Lock

Posted: Sun May 05, 2019 2:18 pm
by hippy
It should be possible; it's been done with far simpler microcontrollers than a PI.

It will depend on being able to time how long buttons were pushed for and how long they were released for. From that list and the range of times you can determine dots and dashes and gaps between letters and words ...

0100-0-1 / 11-0 / 00-1 = LET ME IN

Then simply check if it matches what was expected; "open sesame" or "release the hounds".

Re: One Button Code Lock

Posted: Mon May 06, 2019 5:53 am
by Michel De Meester
Hello MrYsLab,
MrYsLab wrote:
Sun May 05, 2019 2:00 pm
If you absolutely have to a single button used to input the code, then as you say, the synchronization of human to computer timing is difficult. Perhaps, you could provide an LED that lights to tell the user when to enter the next press. If there is no press between flashes, then the input is considered "0".
I want to us a single button because:
  • I already have them available: https://benl.rs-online.com/web/p/push-b ... /?sra=pstk
    I don't have enough place to mount a 12 key keypad
    The switch I will use looks rather like a "led ring" than like a switch, so people won't know the alarm can be deactivated, or if an alarm is installed anyway.
As a musician (tenor saxophone - guitar - bluesharp) I am able to tap a steady beat, so timing should be doable... ;-)

Greetz,
Michel