<?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[Pin Handler with an inside &quot;while&quot; function start again and again !]]></title><description><![CDATA[<p dir="auto">Hello to all,<br />
Pytrack2 with Wipy3 ( all are firmware updated ).<br />
I use the Pin Handler ( set to 0 ) function an work fine! but start again and again, sometime not ?<br />
When I check the value of the pin I read &quot;1&quot; and the function start again like if I press the button !<br />
Is someone know the problem or have a suggestion ?<br />
Waiting your answers<br />
Best regards,  Jiemde</p>
]]></description><link>https://forum.pycom.io/topic/7372/pin-handler-with-an-inside-while-function-start-again-and-again</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 23:07:14 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/7372.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Nov 2021 13:56:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Mon, 29 Nov 2021 13:56:40 GMT]]></title><description><![CDATA[<p dir="auto">Hello to all,<br />
Pytrack2 with Wipy3 ( all are firmware updated ).<br />
I use the Pin Handler ( set to 0 ) function an work fine! but start again and again, sometime not ?<br />
When I check the value of the pin I read &quot;1&quot; and the function start again like if I press the button !<br />
Is someone know the problem or have a suggestion ?<br />
Waiting your answers<br />
Best regards,  Jiemde</p>
]]></description><link>https://forum.pycom.io/post/39611</link><guid isPermaLink="true">https://forum.pycom.io/post/39611</guid><dc:creator><![CDATA[DEFRAINE.JM]]></dc:creator><pubDate>Mon, 29 Nov 2021 13:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Mon, 29 Nov 2021 14:25:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/5158">@DEFRAINE-JM</a> You'll probably need to share (the relevant parts of) your code, along with any logs and traces and description of what you do.</p>
]]></description><link>https://forum.pycom.io/post/39613</link><guid isPermaLink="true">https://forum.pycom.io/post/39613</guid><dc:creator><![CDATA[jcaron]]></dc:creator><pubDate>Mon, 29 Nov 2021 14:25:38 GMT</pubDate></item><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Tue, 30 Nov 2021 10:14:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1538">@jcaron</a> Thanks for your reply, here is the code of the pin-handler code:</p>
<pre><code>def pin_handler(arg):
    print(&quot;got an interrupt in pin %s&quot; %(arg.id()))

    pycom.rgbled(red)
    print(&quot;Sequence de lecture RFID !&quot;)

    rfid = UART(1, baudrate=9600, pins=('P16', 'P17'))
    rfid.init(baudrate=9600, bits=8, parity=None, stop=1, timeout_chars=2, pins=('P16', 'P17'), rx_buffer_size=2048)


    global uuid                 # = bytearray(16)
    rfid_power.value(1)         # Powering the RFID decoder via a power load
    time.sleep(0.5)
    uuid = rfid.read(17)        # first reading of the rfid decoder buffer for cleaning it

    
    time.sleep(0.5)             
    pycom.rgbled(orange)
           

    while True:
        uuid = rfid.read(17)     # reading of the buffer of the rfid buffer
        time.sleep(1)
        print('id = ', uuid)

        if uuid is not None:        # if buffer has something different than &quot;None&quot;
            global rfid_number
            print(&quot;   ID detected !&quot;)                    
            rfid_power.value(0)
            pycom.rgbled(green)     # led sequence for seeing that RFID number is detected
            time.sleep(0.1)
            pycom.rgbled(black)
            time.sleep(0.1)
            pycom.rgbled(green)
            time.sleep(0.1)
            pycom.rgbled(black)     
            time.sleep(0.1)
            pycom.rgbled(green)
            time.sleep(0.1)
            pycom.rgbled(black)
            time.sleep(0.1)
            pycom.rgbled(green)
            time.sleep(1.5)
            pycom.rgbled(black)
            rfid_number = uuid
            rfid.deinit()
            print(p_in.value())       # just to know the pin value for verification
            time.sleep(3)
            break                     # breaking the while function  
</code></pre>
<p dir="auto">And the while (True): start with the p_in callback ( P10 ):</p>
<pre><code>while (True):

    p_in = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
    p_in.callback(Pin.IRQ_RISING, pin_handler, arg = None)


    print(y)                                # comptage du nombre de transmission ( en minutes ) avant reset ( test )
    print(&quot;RFID&quot;, rfid_number[0:14])


    gps   = l76.coordinates()
    pitch = acc.pitch()
    accel = acc.acceleration()
    roll  = acc.roll()
    batt  = py.read_battery_voltage()
    rfid  = rfid_number[0:14]
    # TempA = sensor.read_ambiant_temp()
    # TempO = sensor.read_object_temp()

</code></pre>
<p dir="auto">I use an rfid decoder (134.2Khz ) with uart output  RDM660 TTL</p>
<p dir="auto">Here is the terminal info:</p>
<pre><code>1
got an interrupt in pin P10
Sequence de lecture RFID !
id =  None
id =  b'967000009112695\r\n'
   ID detected !
1
got an interrupt in pin P10
Sequence de lecture RFID !
id =  None
id =  b'967000009112695\r\n'
   ID detected !
3
RFID b'96700000911269'
(None, None) - (2021, 11, 30, 10, 9, 33, 345068, None) - 2531328
Gps:            (None, None)
Acceleration:   (-0.01611328, -0.00793457, 0.9969482)
Roll:           0.5656762
Pitch:          0.4559399
Batt Volt:      4.455878
Rfid:           b'96700000911269'
{&quot;TIME&quot;: [2021, 11, 30, 10, 9, 33, 441458, null], &quot;DATAS&quot;: {&quot;ROLL&quot;: 0.5656762, &quot;BATTERY&quot;: 4.455878, &quot;ID&quot;: &quot;96700000911269&quot;, &quot;GPS&quot;: [null, null], &quot;PITCH&quot;: 0.4559399, &quot;ACCELERATION&quot;: [-0.01611328, -0.00793457, 0.9969482]}}
1
WIFI connected succesfully
SENDING PAYLOAD to NODERED
MQTTClient disconnected
WIFI disconnected ! 

got an interrupt in pin P10
Sequence de lecture RFID !
id =  None
id =  b'967000009112695\r\n'
   ID detected !
1
got an interrupt in pin P10
Sequence de lecture RFID !
id =  None
id =  b'967000009112695\r\n'
   ID detected !
1
</code></pre>
<p dir="auto">&quot;1&quot; alone,  is the value of the pin(P10).<br />
You can see that the rfid value is ok in the sequence so the while function must break !<br />
Sometime it break at the first occurence and sometime it need 8 occurences before breaking !</p>
<p dir="auto">Thanks in advance for helping.<br />
Best regards<br />
Jiemde</p>
]]></description><link>https://forum.pycom.io/post/39620</link><guid isPermaLink="true">https://forum.pycom.io/post/39620</guid><dc:creator><![CDATA[DEFRAINE.JM]]></dc:creator><pubDate>Tue, 30 Nov 2021 10:14:12 GMT</pubDate></item><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Tue, 30 Nov 2021 11:20:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/5158">@DEFRAINE-JM</a> Did you connect P10 to  button switch? If yes, that switch will bounce and create multiple interrupts.</p>
<p dir="auto">On a side note: I would not create the UART object in the callback over and over again. You can create if beforehand and store the object in a global variable. You would have to declare that in the callback as global, otherwise it is not visible.<br />
Besides that, P16 and P17 are input only pins. You cannot use them for UART TX. But you do not write to UART in your code, so it might be fine. Better add an external  pull-up resistor to the TX pin.</p>
]]></description><link>https://forum.pycom.io/post/39621</link><guid isPermaLink="true">https://forum.pycom.io/post/39621</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Tue, 30 Nov 2021 11:20:24 GMT</pubDate></item><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Wed, 01 Dec 2021 06:59:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/5158">@DEFRAINE-JM</a> also, I wouldn’t re-assign the pin handler in the loop. Do it just once at startup and be done with it.</p>
]]></description><link>https://forum.pycom.io/post/39624</link><guid isPermaLink="true">https://forum.pycom.io/post/39624</guid><dc:creator><![CDATA[jcaron]]></dc:creator><pubDate>Wed, 01 Dec 2021 06:59:24 GMT</pubDate></item><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Wed, 01 Dec 2021 08:24:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1538">@jcaron</a> Thanks for reply,<br />
I've moved the assign of the pin handler outside the loop, but the result is the same!</p>
]]></description><link>https://forum.pycom.io/post/39625</link><guid isPermaLink="true">https://forum.pycom.io/post/39625</guid><dc:creator><![CDATA[DEFRAINE.JM]]></dc:creator><pubDate>Wed, 01 Dec 2021 08:24:01 GMT</pubDate></item><item><title><![CDATA[Reply to Pin Handler with an inside &quot;while&quot; function start again and again ! on Wed, 01 Dec 2021 08:59:54 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 for your reply.<br />
Yes &quot;P10&quot; is connected to the Gnd by a simple push button. But I had no idea that the system was logging an interrupt every time I went to Gnd.</p>
<p dir="auto">Question: what solution to adopt?   -  debouncing hardware or software?<br />
What is the solution adopted on the expansion board 3.1 for the &quot;S1&quot; button ?</p>
<p dir="auto">Indeed I only use uart reception. it works great, however i will heed your suggestion of external resistance.</p>
]]></description><link>https://forum.pycom.io/post/39626</link><guid isPermaLink="true">https://forum.pycom.io/post/39626</guid><dc:creator><![CDATA[DEFRAINE.JM]]></dc:creator><pubDate>Wed, 01 Dec 2021 08:59:54 GMT</pubDate></item></channel></rss>