Pin - Control I/O Pins
This class provides methods of reading and writing GPIO. A pin object is used to control I/O pins (also known as GPIO - general-purpose input/output). The pin class has methods to set the mode of the pin (IN, OUT, etc) and methods to get and set the digital logic level.
Example:
Constructor #
machine.Pin
#
Parameter:
-
GPIOn
- Integer type. GPIO number. Click here to view the mapping relationship between GPIO pin numbers and physical pins. -
direction
- Integer type. I/O mode.IN
- Input mode.OUT
- Output mode. -
pullMode
- Integer type. Pull selection mode. Descriptions are as follows:
PULL_DISABLE - Floating mode
PULL_PU - Pull-up mode
PULL_PD - Pull-down mode -
level
- Integer type. Pin level.0
- Set pin to low level.1
- Set pin to high level.
Example:
Mapping Relationship Between GPIO Pin Numbers and Physical Pins:
Description of GPIO corresponding pin numbers: GPIO pin numbers provided in the document correspond to external pin numbers of the module. For example, for EC600M-CN module, GPIO1 corresponds to pin10, which is an external pin number of the module. See the provided hardware documents for external pin numbers of the module.
适用平台 | GPIO number | Pin number |
---|---|---|
BC25PA | GPIO1 | Pin3 |
BC25PA | GPIO2 | Pin4 |
BC25PA | GPIO3 | Pin5 |
BC25PA | GPIO4 | Pin6 |
BC25PA | GPIO5 | Pin16 |
BC25PA | GPIO6 | Pin20 |
BC25PA | GPIO7 | Pin21 |
BC25PA | GPIO8 | Pin22 |
BC25PA | GPIO9 | Pin23 |
BC25PA | GPIO10 | Pin25 |
BC25PA | GPIO11 | Pin28 |
BC25PA | GPIO12 | Pin29 |
BC25PA | GPIO13 | Pin30 |
BC25PA | GPIO14 | Pin31 |
BC25PA | GPIO15 | Pin32 |
BC25PA | GPIO16 | Pin33 |
BC25PA | GPIO17 | Pin2 |
BC25PA | GPIO18 | Pin8 |
Methods #
Pin.read
#
This method reads the pin level.
Return Value:
Pin level.
0
- low level.
1
- high level.
Pin.write
#
This method sets the pin level.
Note: You need to ensure that the pin is in the output mode before you set the pin level.
Parameter:
-
value
- Integer type. Pin level.0
- low level.1
- high level.
Return Value:
0
- Successful execution
-1
- Failed execution
Example:
Pin.set_dir
#
This method sets I/O mode of the pin.
Parameter:
-
value
- Integer type. I/O mode of the pin.0
- Input mode.1
- Output mode.
Return Value:
0
- Successful execution
-1
- Failed execution
Pin.get_dir
#
This method gets I/O mode of the pin.
Return Value:
I/O mode of pins.
0
- Input mode.
1
- Output mode.
Example:
Constants #
适用平台 | Constant | Description |
---|---|---|
BC25PA | Pin.GPIO1 | GPIO1 |
BC25PA | Pin.GPIO2 | GPIO2 |
BC25PA | Pin.GPIO3 | GPIO3 |
BC25PA | Pin.GPIO4 | GPIO4 |
BC25PA | Pin.GPIO5 | GPIO5 |
BC25PA | Pin.GPIO6 | GPIO6 |
BC25PA | Pin.GPIO7 | GPIO7 |
BC25PA | Pin.GPIO8 | GPIO8 |
BC25PA | Pin.GPIO9 | GPIO9 |
BC25PA | Pin.GPIO10 | GPIO10 |
BC25PA | Pin.GPIO11 | GPIO11 |
BC25PA | Pin.GPIO12 | GPIO12 |
BC25PA | Pin.GPIO13 | GPIO13 |
BC25PA | Pin.GPIO14 | GPIO14 |
BC25PA | Pin.GPIO15 | GPIO15 |
BC25PA | Pin.GPIO16 | GPIO16 |
BC25PA | Pin.GPIO17 | GPIO17 |
BC25PA | Pin.GPIO18 | GPIO18 |
BC25PA | Pin.IN | Input mode |
BC25PA | Pin.OUT | Output mode |
BC25PA | Pin.PULL_DISABLE | Floating mode |
BC25PA | Pin.PULL_PU | Pull-up mode |
BC25PA | Pin.PULL_PD | Pull-down mode |