Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Simple button example

    Scheduled Pinned Locked Moved LoPy
    lopyarduino
    7 Posts 3 Posters 3.2k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      markj
      last edited by

      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?
        https://www.arduino.cc/en/tutorial/button
      2. Or this simple example?
        https://www.arduino.cc/en/tutorial/pushbutton
      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?

      Thanks,
      Mark

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @markj
        last edited by

        @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

        think about people first, then computers

        1 Reply Last reply Reply Quote 0
        • M Offline
          markj
          last edited by

          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?

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @markj
            last edited by

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

            think about people first, then computers

            M 1 Reply Last reply Reply Quote 0
            • M Offline
              markj @livius
              last edited by

              @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?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @markj
                last edited by robert-hh

                @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: https://docs.pycom.io/pycom_esp32/library/machine.PWM.html?highlight=pwm

                M 1 Reply Last reply Reply Quote 1
                • M Offline
                  markj @robert-hh
                  last edited by

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

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom