API

class pingo.Board[source]

Abstract class defining common interface for all boards.

Instance attributes of interest to end-users:

«board».pins
A dict with physical pin locations as keys and Pin instances as values.
«board».cleanup()
This should be called to release the pins for other applications on some boards. It is called automatically when the script finishes.

Implementations of Board subclasses should:

  • Call super(«BoardSubclass», self).__init__() and self._add_pins(«pins») in their __init__ method.
  • Implement _set_pin_mode() and _set_pin_state().
  • Override cleanup(), if the board needs it.
filter_pins(*pin_types)[source]

Get a list of pins that are instances of the given pin_types

See the digital_pins property for an example of use.

Arguments:
pin_types: an iterable of types (usually, Pin subclasses)
select_pins(locations)[source]

Get list of pins from iterable of locations

digital_pins

[property] Get list of digital pins

cleanup()[source]

Releases pins for use by other applications.

Overriding this stub may or may not be needed in specific drivers. For example, scripts running on boards using standard sysfs GPIO access should unexport the pins before exiting.

_add_pins(pins)[source]

Populate board.pins mapping from Pin instances.

The __init__ method of concrete Board subclasses should call this method to populate the board instance pins mapping.

Arguments:
pins: an iterable of Pin instances
_set_pin_mode(pin, mode)[source]

Abstract method to be implemented by each Board subclass.

The «pin».mode(…) property calls this method because the procedure to set pin mode changes from board to board.

_set_pin_state(pin, state)[source]

Abstract method to be implemented by each Board subclass

The «pin».__change_state(…) method calls this method because the procedure to set pin state changes from board to board.

_get_pin_state(pin)[source]

Abstract method to be implemented by each Board subclass

class pingo.AnalogInputCapable[source]

Mixin interface for boards that support AnalogInputPin

Concrete AnalogInputCapable subclasses should implement _get_pin_value to read the values of analog pins.

_get_pin_value(pin)[source]

Abstract method to be implemented by each Board subclass.

The «AnalogPin».value(…) method calls this method because the procedure to read pin analog signal changes from board to board.

_set_analog_mode(pin, mode)[source]

Abstract method to be implemented by each Board subclass.

The «pin».mode(…) property calls this method because the procedure to set pin mode changes from board to board.

class pingo.Pin(board, location, gpio_id=None)[source]

Abstract class defining common interface for all pins.

mode

[property] Get/set pin mode to pingo.IN, pingo.OUT pingo.ANALOG or pingo.PWM

class pingo.DigitalPin(board, location, gpio_id=None)[source]

Defines common interface for all digital pins.

Implementers of board drivers do not need to subclass this class because pins delegate all board-dependent behavior to the board.

state

[property] Get/set pin state to pingo.HIGH or pingo.LOW

low()[source]

Set voltage of pin to pingo.LOW (GND).

lo()

Set voltage of pin to pingo.LOW (GND).

high()[source]

Set state of the pin to pingo.HIGH (Vcc).

hi()

Set state of the pin to pingo.HIGH (Vcc).

class pingo.AnalogPin(board, location, resolution, gpio_id=None)[source]

Defines common interface for all analog pins.

Implementers of board drivers do not need to subclass this class because pins delegate all board-dependent behavior to the board.

This pin type supports read operations only.

__init__(board, location, resolution, gpio_id=None)[source]
Parameters:
  • board – the board to which this ping belongs
  • location – the physical location of the pin on the board
  • resolution – resolution of the AD converter in bits
  • gpio_id – the logical id for GPIO access, if applicable
value

[property] Pin value as integer from 0 to 2 ** resolution - 1

ratio(from_min=0, from_max=None, to_min=0.0, to_max=1.0)[source]

Pin value as a float, by default from 0.0 to 1.0.

The from... and to... parameters work like in the Arduino map function, converting values from an expected input range to a desired output range.

percent

[property] Pin value as float from 0.0 to 100.0