<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Button presses register multiple times]]></title><description><![CDATA[<p dir="auto">Hello!<br />
I am right now making my LoPy4 send some data to a LoRa-gateway and change the color of the rgb light whenever I press the S1 button on my expansion board v3.1. However, it's not very responsive. The LoRa payload seems to be pretty quick, but it sometimes takes several seconds before the light changes color. Also the biggest issue is that for whatever reason, one click can sometimes register twice??</p>
<p dir="auto">Look here in my LoRa gateway data, this is the result of ONE button press.</p>
<p dir="auto"><img src="/assets/uploads/files/1562760729527-f11c4767-a06f-4114-8e1f-8c9dcca8112f-image.png" alt="f11c4767-a06f-4114-8e1f-8c9dcca8112f-image.png" class="img-responsive img-markdown" /></p>
<p dir="auto">So I pressed the button, it sent a message, and then for whatever reason it had a rising edge also 3 seconds later. This is very odd, and I am certain I did not press the button, and I have seen the same behavior when just printing inside the button callback function.</p>
<p dir="auto">This is the code for the button. I have tried using PULL_DOWN instead to see if there were some floating values fucking me over, but it had the same behavior.</p>
<pre><code>btn = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)
btn.callback(trigger=Pin.IRQ_RISING, handler=rnd_triage)
</code></pre>
]]></description><link>https://forum.pycom.io/topic/4993/button-presses-register-multiple-times</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Jul 2026 16:09:23 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/4993.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Jul 2019 12:15:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Button presses register multiple times on Wed, 10 Jul 2019 12:15:18 GMT]]></title><description><![CDATA[<p dir="auto">Hello!<br />
I am right now making my LoPy4 send some data to a LoRa-gateway and change the color of the rgb light whenever I press the S1 button on my expansion board v3.1. However, it's not very responsive. The LoRa payload seems to be pretty quick, but it sometimes takes several seconds before the light changes color. Also the biggest issue is that for whatever reason, one click can sometimes register twice??</p>
<p dir="auto">Look here in my LoRa gateway data, this is the result of ONE button press.</p>
<p dir="auto"><img src="/assets/uploads/files/1562760729527-f11c4767-a06f-4114-8e1f-8c9dcca8112f-image.png" alt="f11c4767-a06f-4114-8e1f-8c9dcca8112f-image.png" class="img-responsive img-markdown" /></p>
<p dir="auto">So I pressed the button, it sent a message, and then for whatever reason it had a rising edge also 3 seconds later. This is very odd, and I am certain I did not press the button, and I have seen the same behavior when just printing inside the button callback function.</p>
<p dir="auto">This is the code for the button. I have tried using PULL_DOWN instead to see if there were some floating values fucking me over, but it had the same behavior.</p>
<pre><code>btn = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)
btn.callback(trigger=Pin.IRQ_RISING, handler=rnd_triage)
</code></pre>
]]></description><link>https://forum.pycom.io/post/28636</link><guid isPermaLink="true">https://forum.pycom.io/post/28636</guid><dc:creator><![CDATA[robertsehlstedt]]></dc:creator><pubDate>Wed, 10 Jul 2019 12:15:18 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Wed, 10 Jul 2019 16:50:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/4813">@robertsehlstedt</a> buttons use to bounce, so there may be various events in ms time distance, which have bee registered and processed later. Since a server may respond to any message after one or two seconds, the LoRa stack most likely waits for that time before sending the next message. The three seconds you see is well within the uncertainty of the time taking.</p>
]]></description><link>https://forum.pycom.io/post/28646</link><guid isPermaLink="true">https://forum.pycom.io/post/28646</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Wed, 10 Jul 2019 16:50:33 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Thu, 11 Jul 2019 06:27:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> Alright thanks! Is there some way to avoid it?</p>
]]></description><link>https://forum.pycom.io/post/28652</link><guid isPermaLink="true">https://forum.pycom.io/post/28652</guid><dc:creator><![CDATA[robertsehlstedt]]></dc:creator><pubDate>Thu, 11 Jul 2019 06:27:48 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Thu, 11 Jul 2019 06:35:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> Also I do want to say, to clear up any confusions here - that if I just make a button callback function which prints &quot;Button pressed&quot; or something like that, actually I can clearly see that sometimes when I click the button, it will register once, and then again a few seconds later. Which means that the delay probably isn't on the server end.</p>
]]></description><link>https://forum.pycom.io/post/28653</link><guid isPermaLink="true">https://forum.pycom.io/post/28653</guid><dc:creator><![CDATA[robertsehlstedt]]></dc:creator><pubDate>Thu, 11 Jul 2019 06:35:23 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Thu, 11 Jul 2019 07:25:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/4813">@robertsehlstedt</a> So you tried a callback that just prints the message? Using that little script, I get quite a few responses. And the sleep in the callback causes  events to seem happening later.</p>
<pre><code>#
from machine import Pin
from time import sleep_ms

count = 0
def rnd_triage(p):
    global count
    print(&quot;callback fired&quot;, count)
    sleep_ms(1000)
    count += 1


while True:
    btn = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
    btn.callback(trigger=Pin.IRQ_FALLING, handler=rnd_triage)
    sleep_ms(100)

</code></pre>
<p dir="auto">Besides that, I'm not saying the the problem is at the server end. The problem is local, but LoRa might not send a second message before the RX2 periods of the first message has passed, and the scheduler for callbacks might not schedule the next callback before the message sending has been finished.<br />
The callbacks a not ISR's. Whenever an interrupt happens, it is just registered and the callback is added to a queue and executed whenever it's time to do so. There is no guarantee for  a timely service.</p>
]]></description><link>https://forum.pycom.io/post/28657</link><guid isPermaLink="true">https://forum.pycom.io/post/28657</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Thu, 11 Jul 2019 07:25:10 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Thu, 11 Jul 2019 08:04:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a>  I tried something similar to you and yeah I keep getting similar results where there are two button presses registered. I am not sure if I am following you, but it seems like there is nothing to be done about it? For the moment I am using the button to just demo some functionality, but in the future we will use other pins. I hope they won't have the same behaviour!</p>
]]></description><link>https://forum.pycom.io/post/28660</link><guid isPermaLink="true">https://forum.pycom.io/post/28660</guid><dc:creator><![CDATA[robertsehlstedt]]></dc:creator><pubDate>Thu, 11 Jul 2019 08:04:16 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Thu, 11 Jul 2019 08:45:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/4813">@robertsehlstedt</a> There are many attempts for debouncing, both in software and hardware. As an example, I quick-hacked together some code, based on a time interrupt and a low pass filter.</p>
<pre><code>#
from machine import Pin, Timer
from time import sleep_ms

btn = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)

state = False
btn_state = 1

LIMIT_ON = 0.1
LIMIT_OFF = 0.9
TIME_CONSTANT = 0.25

def switch_state(p):
    global btn_state, state
    # low pass filtering of the input valeue
    btn_state += TIME_CONSTANT * (btn.value() - btn_state)
    if btn_state &lt; LIMIT_ON:
        if state == False:
            print(&quot;Button pressed&quot;)
        # may schedule something else here, like sending a message
        state = True
    elif btn_state &gt; LIMIT_OFF:
        if state == True:
            print(&quot;Button released&quot;)
        state = False

alarm = Timer.Alarm(switch_state, 0.01, periodic = True)

while True:
    sleep_ms(100)

</code></pre>
]]></description><link>https://forum.pycom.io/post/28663</link><guid isPermaLink="true">https://forum.pycom.io/post/28663</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Thu, 11 Jul 2019 08:45:29 GMT</pubDate></item><item><title><![CDATA[Reply to Button presses register multiple times on Thu, 11 Jul 2019 08:53:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> Thanks! I tried pulling a cable between two pins using the following code.</p>
<pre><code>count = 0
def rnd_triage(arg):
    global count
    print(&quot;callback fired&quot;, count)
    count += 1

p = Pin('P13', mode=Pin.IN, pull=Pin.PULL_DOWN)
p.callback(trigger=Pin.IRQ_RISING, handler=rnd_triage)

t = Pin('P12', mode=Pin.OUT, pull=None, alt=-1)

while True:
    time.sleep(3)
    t.value(0)
    time.sleep(3)
    t.value(1)
</code></pre>
<p dir="auto">It seems to be working quite well at least, so maybe I will just endure the button performance for now. Thanks a lot for the help!</p>
]]></description><link>https://forum.pycom.io/post/28664</link><guid isPermaLink="true">https://forum.pycom.io/post/28664</guid><dc:creator><![CDATA[robertsehlstedt]]></dc:creator><pubDate>Thu, 11 Jul 2019 08:53:09 GMT</pubDate></item></channel></rss>