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 andPin
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__()
andself._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)
-
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 shouldunexport
the pins before exiting.
-
_add_pins
(pins)[source]¶ Populate
board.pins
mapping fromPin
instances.The
__init__
method of concreteBoard
subclasses should call this method to populate the board instancepins
mapping.- Arguments:
pins
: an iterable ofPin
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.
-
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.
-
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
orpingo.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
orpingo.LOW
-
lo
()¶ Set voltage of pin to
pingo.LOW
(GND).
-
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...
andto...
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
-