What is the extension board button right id?



  • Hello There,

    I am trying to use the button from the Extension board, so I have written the following code:

    #Pin.IN/Pin.OUT using RGB LED

    Autor: XXXXX

    from machine import Pin
    import pycom
    pycom.heartbeat(False)

    #Inputs Pins
    pin_i1 = Pin('G17', mode=Pin.IN, value=None)
    #Output Pins

    while (True):
    #Review pin_i1
    if pin_i1.value() != 1:
    pycom.rgbled(0x007f00) # green
    else:
    pycom.rgbled((0x7f0000) # red

    it is not working, does not do anything. Can anyone confirm if I have addressed the right pin in the extension boar (G17)?

    if I measure voltage between GND and G10, its 3.3V, and it does not matter if I press button on/off, 3.3V value still there.

    Cheers
    Colombian1976



  • @RobTuDelft ok fair enough. so Following code should work right?

    import time
    from machine import Pin
    import machine
    import pycom

    pycom.heartbeat(False)

    def toggle_rgbled_blue(arg):
    pycom.rgbled(0xff)
    time.sleep(2)
    pycom.rgbled(0)

    def toggle_rbgled_red(arg):
    pycom.rgbled(0x7f0000)
    time.sleep(2)
    pycom.rgbled(0)

    button_blue = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
    button_blue.callback(Pin.IRQ_RISING, toggle_rgbled_blue)

    buton_red = Pin('P0', mode=Pin.IN, pull=Pin.PULL_UP)
    button_red.callback(Pin.IRQ_RISING, toggle_rgbled_red)

    Cheers
    Colombian



  • @ColombianAus With callbacks you are assured that you always capture the event. I think that is the main advantage. Up to 16 events can be queued this way. Using a loop is also possible of course, but then it might interfere with other processes.



  • @RobTuDelft

    Hey

    Thank you very much for your assistance, your code works like a charm. I guess (and please correct me if I am wrong), the way you deal with Inputs in WiPy will be with interrupts? and not the way I was doing it..

    Cheers
    Colombian



  • @ColombianAus

    Glad you are making progress!
    To help you a little bit, this example should probably work for you (didn't test it):

    import time
    from machine import Pin
    import os
    import machine
    import pycom
    
    
    uart = machine.UART(0, 115200)
    os.dupterm(uart)
    
    pycom.heartbeat(False)
    
    
    def toggle_rgbled(arg):
        pycom.rgbled(0xff)
        time.sleep(2)
        pycom.rgbled(0)
        
    
    button = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
    button.callback(Pin.IRQ_RISING, toggle_rgbled)
    


  • @RobTuDelft

    Hello Rob,

    I think that I have made some progress :-). now I have following program

    from machine import Pin
    import pycom
    pycom.heartbeat(False)
    
    #Inputs Pins
    pin_i1 = Pin('GP1', mode=Pin.IN, value=PULL_UP)
    #Output Pins
    
    while (True):
    	#Revisar pin_i1 
    	if pin_i1.value() != 1:
     		pycom.rgbled(0x007f00) # green
    	else:
    		pycom.rgbled((0x7f0000) # red
    

    so...I have changed from my input pin to G1, (P0) in the board. AND connected a cable from G17 to G1. I still don't see my program working but...I'll get there :-)

    Cheers
    Colombian



  • @RobTuDelft

    hey Rob,

    Thank you for your reply mate.

    yes, I am trying to set use expansion board button to activate RGB LED. ..I did try to set up value to PIN.PULL_UP, but no change...and as I mentioned on my initial post, how weird that I measure voltage from P10 to GND and it is 3.3V all the time, no matter if the button is press or not.

    Great suggestion about the code block, trying to find a suitable coding standard....:-)

    Cheers
    Colombian



  • The user button on the expansion board is indeed P10 - G17.

    Are you trying to set a value for an input pin (value=None)?

    With ````you can make a code block:

    from machine import Pin
    import pycom
    pycom.heartbeat(False)
    
    #Inputs Pins
    pin_i1 = Pin('G17', mode=Pin.IN, value=None)
    #Output Pins
    
    while (True):
        #Review pin_i1
        if pin_i1.value() != 1:
           pycom.rgbled(0x007f00) # green
        else:
           pycom.rgbled((0x7f0000) # red
    

Log in to reply
 

Pycom on Twitter