Skip to content
Boris Lovosevic edited this page Aug 7, 2019 · 4 revisions

machine Module

Editing in progress ...

Class Pin

This class includes support for using K210 gpios
GPIOHS are used for Pin functions

  • Configurable as input or output
  • Each IO is an independent interrupt source
  • Edge-triggered or level-triggered interrupt support
  • Each IO can be assigned to one of the 48 pins on the FPIOA
  • Configurable pull-up and pull-down resistors, or high impedance in input mode

Create the Pin instance object

pin = machine.Pin(gpio [,args])

Argument Description
gpio gpio number, if invalid or used gpio number is entered, an exception will be raised
mode optional; pin operating mode
use one of the constants: IN, OUT
default: IN
pull optional; activate internal pull resistor if pin is configured as input
use one of the constants: PULL_UP, PULL_DOWN, PULL_FLOAT
default: PULL_FLOAT
value optional; set the initial value for an output pin; default: do not set
handler optional; Pin irq callback function
If set, the pin interrupt will be enabled and the given function will be called on interrupt
default: no irq enabled
trigger optional; the pin interrupt mode
use on of the constants: IRQ_DISABLE, IRQ_RISING, IRQ_FALLING, IRQ_ANYEDGE
default: IRQ_DISABLE
Note: Level interrupts are currently not enabled.
debounce optional; debounce time on pin interrupt in micro seconds, 0 for debounce disable
valid range: 100 - 500000 µs
default: 0

Only gpio argument is required, all the other are optional and will be set to the default values if not given.
Arguments value, handler, trigger, debounce must be given as kw arguments (arg=value)


Methods


pin.init([args])

Change the pin configuration and options after the pin instance object was created.

For arguments description see Create the Pin instance object above.


pin.deinit()

Deinitialize the Pin object, free all resources..


pin.value([val])

Get or set the pin value.
If no argument is given, returns the current pin value (level), 0 or 1
It the val argument is given, set the pin level. val can be 0, 1, False or True

Note: If the pin is set to output mode (OUT), the returned value will always be 0


pin.irqvalue()

Returns the pin level at the time when the last interrupt occured.
Can be used inside the interrupt handling function.


pin.irqenable(True|False)

Enable or disable pin interrupt.


pin.stat([reset])

Returns the pin interrupt counters tuple:
(pin, gpio_id, num_interrupts, num_callbacks, num_missed_cb)
It the optional agumetn reset is True, resets all interrupt counters.

Clone this wiki locally