MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / __init__

Method __init__

Software/Python/easysensors.py:88–132  ·  view source on GitHub ↗

Constructor for creating a connection to one of the available grove ports on the `GoPIGo3`_. :param str port: Specifies the port with which we want to communicate / interact with. The string literals we can use for identifying a port are found in the following graphical drawing : :

(self, port, pinmode, gpg, use_mutex=False)

Source from the content-addressed store, hash-verified

86 PORTS = {}
87
88 def __init__(self, port, pinmode, gpg, use_mutex=False):
89 """
90 Constructor for creating a connection to one of the available grove ports on the `GoPIGo3`_.
91
92 :param str port: Specifies the port with which we want to communicate / interact with. The string literals we can use for identifying a port are found in the following graphical drawing : :ref:`hardware-ports-section`.
93 :param str pinmode: The mode of operation of the pin we're selecting.
94 :param easygopigo3.EasyGoPiGo3 gpg: An instantiated object of the :py:class:`~easygopigo3.EasyGoPiGo3` class. We need this :py:class:`~easygopigo3.EasyGoPiGo3` class for setting up the `GoPiGo3`_ robot's pins.
95 :raises TypeError: If the ``gpg`` parameter is not a :py:class:`~easygopigo3.EasyGoPiGo3` object.
96
97 The ``port`` parameter can take the following string values:
98
99 * ``"AD1"`` - for digital and analog ``pinmode``'s.
100 * ``"AD2"`` - for digital and analog ``pinmode``'s.
101 * ``"SERVO1"`` - for ``"OUTPUT"`` ``pinmode``.
102 * ``"SERVO2"`` - for ``"OUTPUT"`` ``pinmode``.
103 * ``"I2C"`` - the ``pinmode`` is irrelevant here.
104 * ``"SERIAL"`` - the ``pinmode`` is irrelevant here.
105
106 These ports' locations can be seen in the following graphical representation - :ref:`hardware-ports-section`.
107
108 The ``pinmode`` parameter can take the following string values:
109
110 * ``"INPUT"`` - for general purpose inputs. The `GoPiGo3`_ has 12-bit ADCs.
111 * ``"DIGITAL_INPUT"`` - for digital inputs. The port can detect either **0** or **1**.
112 * ``"OUTPUT"`` - for general purpose outputs.
113 * ``"DIGITAL_OUTPUT"`` - for digital outputs. The port can only be set to **0** or **1**.
114 * ``"US"`` - that's for the :py:class:`~easysensors.UltraSonicSensor` which can be bought from our `shop`_. Can only be used with ports ``"AD1"`` and ``"AD2"``.
115 * ``"IR"`` - that's for the `infrared receiver`_. Can only be used with ports ``"AD1"`` and ``"AD2"``.
116
117 .. warning::
118
119 At the moment, there's no class for interfacing with the `infrared receiver`_.
120
121 """
122 debug("Sensor init")
123
124 if not isinstance(gpg, gopigo3.GoPiGo3):
125 raise TypeError("Use a GoPiGo3 object for the gpg parameter.")
126 self.gpg = gpg
127 debug(pinmode)
128 self.set_port(port)
129 self.set_pin_mode(pinmode)
130 self.use_mutex = use_mutex
131
132 self.reconfig_bus()
133
134 def reconfig_bus(self):
135 """

Callers

nothing calls this directly

Calls 4

set_portMethod · 0.95
set_pin_modeMethod · 0.95
reconfig_busMethod · 0.95
debugFunction · 0.70

Tested by

no test coverage detected