gpio - GPIO Pins¶
The gpio module allows you to use card10’s GPIO pins as input and
output in your scripts.
Example:
import gpio
gpio.set_mode(gpio.WRISTBAND_1, gpio.mode.OUTPUT)
gpio.write(gpio.WRISTBAND_1, True)
gpio.set_mode(gpio.WRISTBAND_2, gpio.mode.INPUT | gpio.mode.PULL_UP)
state = gpio.read(gpio.WRISTBAND_2)
print("State of Wristband pin 2:", state)
-
gpio.set_mode(pin, mode)¶ Configure GPIO pin state.
- Parameters
pin (int) – ID of the pin to be configured.
mode (int) – An integer with the bits for the wanted mode set. Create your integer by ORing
gpio.mode.OUTPUT,gpio.mode.INPUT,gpio.mode.ADC,gpio.mode.PULL_UP,gpio.mode.PULL_DOWN.
Note
On WRISTBAND_3, there is no ADC functionality available
-
gpio.get_mode(pin)¶ Get GPIO pin state.
- Parameters
pin (int) – ID of the pin of to get the mode of.
- Returns
An integer with the configure mode bits set.
-
gpio.write(pin, value)¶ Write a value to a GPIO pin.
- Parameters
pin (int) – ID of the pin of to get the mode of.
value (bool) – New pin value.
-
gpio.read(pin)¶ Read GPIO pin value.
- Parameters
pin (int) – ID of the pin of to get the mode of.
- Returns
Current value of the GPIO pin. If the pin is configured as ADC, the value returned will be between 0 and 1000, representing voltages from 0V to 3.3V (
gpio.ADCis only available in 1.9+).
-
gpio.WRISTBAND_1¶ Pin ID for Wristband GPIO 1.
-
gpio.WRISTBAND_2¶ Pin ID for Wristband GPIO 2.
-
gpio.WRISTBAND_3¶ Pin ID for Wristband GPIO 3.
-
gpio.WRISTBAND_4¶ Pin ID for Wristband GPIO 4.
-
gpio.mode.OUTPUT¶ Configures a pin as output.
-
gpio.mode.INPUT¶ Configures a pin as input.
-
gpio.mode.ADC¶ Configure pin as ADC input.
-
gpio.mode.PULL_UP¶ Enables the internal pull-up resistor of a pin.
-
gpio.mode.PULL_DOWN¶ Enables the internal pull-down resistor of a pin.