API¶
-
class
pingo.Board[source]¶ Abstract class defining common interface for all boards.
Instance attributes of interest to end-users:
«board».pins- A
dictwith physical pin locations as keys andPininstances 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
Boardsubclasses 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_pinsproperty for an example of use.- Arguments:
pin_types: an iterable of types (usually,Pinsubclasses)
-
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
sysfsGPIO access shouldunexportthe pins before exiting.
-
_add_pins(pins)[source]¶ Populate
board.pinsmapping fromPininstances.The
__init__method of concreteBoardsubclasses should call this method to populate the board instancepinsmapping.- Arguments:
pins: an iterable ofPininstances
-
_set_pin_mode(pin, mode)[source]¶ Abstract method to be implemented by each
Boardsubclass.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
AnalogInputCapablesubclasses should implement_get_pin_valueto 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.OUTpingo.ANALOGorpingo.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.HIGHorpingo.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
-