class Pin – control I/O pins

A pin is the basic object to control I/O pins. It has methods to set the mode of the pin (input, output, etc) and methods to get and set the digital logic level. For analog control of a pin, see the ADC class.

Usage Model:

Constructors

class machine.Pin(id, ...)

Create a new Pin object associated with the id. If additional arguments are given, they are used to initialise the pin. See pin.init().

Methods

pin.value([value])

Get or set the digital logic level of the pin:

  • With no argument, return 0 or 1 depending on the logic level of the pin.
  • With value given, set the logic level of the pin. value can be anything that converts to a boolean. If it converts to True, the pin is set high, otherwise it is set low.
pin([value])

Pin objects are callable. The call method provides a (fast) shortcut to set and get the value of the pin. See pin.value for more details.

pin.alt_list()

Returns a list of the alternate functions supported by the pin. List items are a tuple of the form: ('ALT_FUN_NAME', ALT_FUN_INDEX)

Availability: WiPy.

Attributes

class Pin.board

Contains all Pin objects supported by the board. Examples:

Pin.board.GP25
led = Pin(Pin.board.GP25, mode=Pin.OUT)
Pin.board.GP2.alt_list()

Availability: WiPy.

Constants

The following constants are used to configure the pin objects. Note that not all constants are available on all ports.

IN
OUT
OPEN_DRAIN
ALT
ALT_OPEN_DRAIN

Selects the pin mode.

PULL_UP
PULL_DOWN

Selects the whether there is a pull up/down resistor.

LOW_POWER
MED_POWER
HIGH_POWER

Selects the pin drive strength.

IRQ_FALLING
IRQ_RISING
IRQ_LOW_LEVEL
IRQ_HIGH_LEVEL

Selects the IRQ trigger type.