• Hi, I tried to use the GPIO pins on the GPY but I failed.
    I want to create 4 inputs
    This is my code

    from machine import Pin
    import time
    led = Pin('P9', mode = Pin.OUT)
    button = Pin('P10', mode = Pin.IN)
    check1 = Pin('P11', mode = Pin.IN)
    check2 = Pin('P12', mode = Pin.IN)
    check3 = Pin('P17', mode = Pin.IN)
    while True:
        if(button() == 1 or check1() == 1 or check2() == 1 or check3() == 1):

    only the "button pin works" => the led on the expantion board lights up if the button is pressed.
    I use the expantion board 3.1 iI use a pull up resistor for the pin11 and pin12 for pin17 it is not necessary according the datasheet.
    Did someone used these pins already ?


  • @carl-declercq Not by default. If I need them, I add them as appropriate.

  • @robert-hh Hm, nice plan, .... do you use pull up resistors ?

  • @carl-declercq I use my own carrier board for the modules, where I definitely know where and what is connected.

  • Yes indeed that is strange .... that is my consern .... (Note that I use the expantion board ! I don't have a scheme to see how the components are connected.
    When the button is pressed, if I measure with a multimeter, I get 0V at pin10.
    Do you use the expantion board ?

  • @carl-declercq That's strange than. What do you get with button() when the button is pressed()?

  • @robert-hh The LED lights up at led.value(1) => the LED must light up if P10 OR P11 OR P12 OR P17 are at the state "1"

  • @carl-declercq Just start with the simple pieces.
    At what state does the LED light up. with led.value(1) or led.value(0)?
    And what do you want to achieve? Should the LED light up, when any of the inputs is 0 or at another logical combination?

  • @robert-hh Hi Robert thanks for your reply. I use the expantion board 3.1 => P10 is connected to a button S1 and if I measure the voltage on that pin10 I'll get 3.3V (I suppose there is a pull up resistor connected to it via the expantion board).
    If I press the button S1 the voltage drops to 0V and the LED that is connected to P9 lites up, the LED is on the expantion board also, so I didn't soldure it myself, and I can't find a decent sceme from the expantion board).
    So I get a fysical "0" at P10 and at first I used the code from the tutorial on the site. link to the documentation
    It was confusing because they use "IF P10 is "1" the OUTPUT P9 will be "1" and the fysical input from P10 is "0" !?
    Now i can live with that so I start building ....

    I simular to P10, I placed a 10k pull up resistor for P11 and P12. If I use these pins induvidual it works as expected .... but If I use the "OR" command (P10 OR P11 OR P12 must be "1") it does not work. So I tried the AND command to compair.
    The AND function works !? so why does the OR function don't ? If I use the OR function in my code and connect the P10 P11 and P12 Pysicaly like an "AND" so they all must be "1" in stead of one of the Pin's must be "1", the LED lite up.

    I know it is confusing and explaining without actualy seeing it, ... but thanks for your reply man, I appreciate it.

    Thanks !!

  • This post is deleted!

  • @carl-declercq So you connected the button between P10 and GND? How did you connect the LED? If between P1 and GND, it will lite up with a 1 at P9. If connected between P9 and 3V3, it will lite up with a 0 at P9. Nevertheless, the logical operators of MicroPython work as expected. If your set-up does not work as expected, it is better to check the actual levels at the pins individually.

  • I tried the "AND" function and that works fine => more the "OR" function reacts like an "AND" function !??

Log in to reply

Pycom on Twitter