Skip to content

MicroPython: GPIO Pins

Leo Vidarte edited this page Mar 7, 2017 · 2 revisions

The way to connect your board to the external world, and control other components, is through the GPIO pins. Not all pins are available to use, in most cases only pins 0, 2, 4, 5, 12, 13, 14, 15, and 16 can be used.

The pins are available in the machine module, so make sure you import that first. Then you can create a pin using:

>>> from machine import Pin
>>> pin = Pin(14, Pin.OUT)

You can read the value on the pin using:

>>> pin.value()
0

Then set its value using:

>>> pin.value(0)
>>> pin.value(1)

Or:

>>> pin.low()
>>> pin.high()