Simple button example

  • Hello,

    I am new to this platform. I have some experience with the Arduino, so that's why I want to compare the two boards a bit.

    1. Could someone explain if it is possible and if yes, how to do this example on the Lopy?
    2. Or this simple example?
    3. On Arduino I can also connect a led with a resistor to an output port to turn it on and off, can I also do this with the Lopy?


  • @robert-hh Thanks a lot Robert and Livius! I saw indeed the PWM example in the Micropython docs to dim a led.

  • @markj hello mark. Yes, the chip or at least that port may break if you draw more than recommended. A LED will light up at any current, just the intensity is a little bit lower. 20mA are just a typical figure, not the minimal current, and that value is kind of aged.
    And yes, you can control the LED by writing a value to the port.
    By using the PWM class, you can control the brightness, just like Arduino analog_write(). Look here for an exmaple:

  • @livius Thanks livius, but it is still not very clear to me. Hopefully you can answer these questions:

    1. So it is correct you can only draw 12 mA current? Will the board break if you pull more?

    2. Can we control the led by writing a value to the pin (e.g. P2 High turns on the led)?

    3. I = (3.3 - 1.9) / 620 = 0.002 A, I doubt the led will light on?

  • @markj
    you can test external led, but you must add resistor e.g. 620ohm

  • Thank you for your response.

    Have you tried the examples on the Lopy?
    And does the internal led work the same way as for Arduino?
    Pin high and the led goes on?

    Datasheet mentions 6 mA recommended, while most leds are already more than 20 mA. So I thought examples with external leds were not possible?

  • @markj
    the wire is "the same" but you must remember about 3V3 voltage to use not 5V.

    and code for button is really simple:

    from machine import Pin
    button_ext_pull = Pin('P18', mode=Pin.IN, pull=None)
    button_int_pull = Pin('P19', mode=Pin.IN, pull=Pin.PULL_UP)

    button_ext_pull is with external pullup resistor
    button_int_pull is with internall pullup resistor

Log in to reply

Pycom on Twitter