gpio.rst 2.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.. py:module:: gpio

``gpio`` - GPIO Pins
==========================
The :py:mod:`gpio` module allows you to use card10's GPIO pins as input and
output in your scripts.

**Example**:

.. code-block:: python

   import gpio

   gpio.set_mode(gpio.WRISTBAND_1, gpio.mode.OUTPUT)
   gpio.write(gpio.WRISTBAND_1, True)
Rahix's avatar
Rahix committed
16

17
18
19
20
   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)

21
.. py:function:: set_mode(pin, mode)
22
23
24
25
26
27

   Configure GPIO pin state.

   :param int pin: ID of the pin to be configured.
   :param int mode: An integer with the bits for the wanted mode set. Create your
      integer by ORing :py:data:`gpio.mode.OUTPUT`, :py:data:`gpio.mode.INPUT`,
28
29
30
31
      :py:data:`gpio.mode.ADC`, :py:data:`gpio.mode.PULL_UP`,
      :py:data:`gpio.mode.PULL_DOWN`.

   .. note:: On WRISTBAND_3, there is no ADC functionality available
32

33
.. py:function:: get_mode(pin)
34
35

   Get GPIO pin state.
Rahix's avatar
Rahix committed
36

37
38
39
   :param int pin: ID of the pin of to get the mode of.
   :returns: An integer with the configure mode bits set.

40
.. py:function:: write(pin, value)
41
42

   Write a value to a GPIO pin.
Rahix's avatar
Rahix committed
43

44
45
   :param int pin: ID of the pin of to get the mode of.
   :param bool value: New pin value.
Rahix's avatar
Rahix committed
46

47
.. py:function:: read(pin)
48
49

   Read GPIO pin value.
Rahix's avatar
Rahix committed
50

51
52
   :param int pin: ID of the pin of to get the mode of.
   :returns: Current value of the GPIO pin.
53
54
55
      If the pin is configured as ADC, the value returned
      will be between 0 and 1000, representing voltages from
      0V to 3.3V
56

57
.. py:data:: WRISTBAND_1
58
59
60

   Pin ID for Wristband GPIO 1.

61
.. py:data:: WRISTBAND_2
62
63
64

   Pin ID for Wristband GPIO 2.

65
.. py:data:: WRISTBAND_3
66
67
68

   Pin ID for Wristband GPIO 3.

69
.. py:data:: WRISTBAND_4
70
71

   Pin ID for Wristband GPIO 4.
Rahix's avatar
Rahix committed
72

73
74
75
76

.. py:module:: gpio.mode

.. py:data:: OUTPUT
77
78

   Configures a pin as output.
Rahix's avatar
Rahix committed
79

80
.. py:data:: INPUT
81
82

   Configures a pin as input.
Rahix's avatar
Rahix committed
83

84
.. py:data:: PULL_UP
85
86

   Enables the internal pull-up resistor of a pin.
Rahix's avatar
Rahix committed
87

88
.. py:data:: PULL_DOWN
89
90

   Enables the internal pull-down resistor of a pin.