Quantcast
Viewing all articles
Browse latest Browse all 4899

MicroPython • Re: Can someone explain the input pins?

I get that you need to add Pin.IN when creating the pin in micropython and that you also need to add the internal resistor (PULL_UP or PULL_DOWN)
Not entirely. You need to specify "Pin.IN" so MicroPython knows you are dealing with an input pin, but adding PULL_UP or PULL_DOWN is entirely optional.

With most electronic devices there are no internal pull-up or pull-downs so a button input would need to be as below to give a reliable high or low signal -

Code:

          ___________                ___________         |           |              |           |  --.----| +V        |       --.----| +V        |   .|.   |           |         |    |           |   | |   |           |       _|O    |           |   |_|   |           |      |_|     |           |    |    |           |        |O    |           |    |    |           |         |    |           |    }--->| INPUT     |         }--->| INPUT     |    |    |           |         |    |           |  _|O    |           |        .|.   |           | |_|     |           |        | |   |           |   |O    |           |        |_|   |           |    |    |           |         |    |           |  --^----| 0V        |       --^----| 0V        |         |___________|              |___________|
The RP2040 does however have the ability to use internal pull-ups and pull-downs which allows, what would have been externally required resistors, to be replaced by internal resistors -

Code:

          ___________                ___________         |           |              |           |        -|---.- +V   |       --.----|----- +V   |         |  .|.      |         |    |           |         |  | |      |       _|O    |           |         |  |_|      |      |_|     |           |         |   |       |        |O    |           |         |   |       |         |    |           |    .--->|---^- IN   |         `--->|---.- IN   |    |    |           |              |   |       |  _|O    |           |              |  .|.      | |_|     |           |              |  | |      |   |O    |           |              |  |_|      |    |    |           |              |   |       |  --^----|----- 0V   |             -|---^- 0V   |         |___________|              |___________|
MicroPython allows you to specify "Pin.PULL_UP" and "Pin.PULL_DOWN" to do this, but it doesn't need to be done. But if not you will need external resistors.

Most will use "Pin.PULL_UP" and "Pin.PULL_DOWN" because it makes things easier and cheaper, saves on needing those external resistors and having to fit them, which may become a significant saving if you have more than one button.

Statistics: Posted by hippy — Thu Aug 01, 2024 10:50 am



Viewing all articles
Browse latest Browse all 4899

Trending Articles