Перейти к основному контенту

GPIO usage

GPIO pin assignment

Document Pictures

GPIO Pin distribution

SPIPWMI2CLCDGPIO NUMNAMEPINPINNAMEGPIO NUMUARTLCDPWMSPI
N/A+3.3V
1
2
+5VN/A
I2C_SDA58GPIO58
3
4
+5VN/A
I2C_SCL57GPIO57
5
6
GNDN/A
55GPIO55
7
8
GPIO55UART_TX
N/AGND
9
10
GPIO66UART_RX
42GPIO42
11
12
GPIO3838LCD_HSYNC
43GPIO43
13
14
GNDN/A
47GPIO47
15
16
GPIO5454
N/A+3.3V
17
18
GPIO5151
SPI_MOSI52GPIO52
19
20
GNDN/A
SPI_MISO53GPIO53
21
22
GPIO5050
SPI_SCLK48GPIO48
23
24
GPIO4949
N/AGND
25
26
GPIO5656
45GPIO45
27
28
GPIO4040
LCD_VSYNC37GPIO37
29
30
GNDN/A
LCD_DE39GPIO39
31
32
GPIO4646PWM0
PWM159GPIO59
33
34
GNDN/A
63GPIO63
35
36
GPIO3636LCD_CLK
60GPIO60
37
38
GPIO6161
N/AGND
39
40
GPIO4444

If pin multiplexing is required, please refer to: https://milkv.io/zh/docs/mars/getting-started/gpio_full_multiplexing

Configure GPIO

  1. Perform the following operations to configure GPIO:

Take GPIO44 as an example.

$ cd /sys/class/gpio

$ echo 44 | sudo tee export

You can run the command ls /sys/class/gpio to list the GPIO directory, check whether gpio44 appears, and confirm that the export is successful.

совет

The 44 in the command is the sys number, corresponding to GPIO44

  1. Set the direction of GPIO

Run the command echo "out" | sudo tee gpio44/direction to set the direction of GPIO44 to output.

Run the command echo "in" | sudo tee gpio44/direction to set the direction of GPIO44 to input.

You can check the set direction by running the command cat gpio44/direction .

  1. Set the voltage of GPIO44

Run the command echo "1" | sudo tee gpio44/value to set the voltage of GPIO44 to a high level.

Run the command echo "0" | sudo tee gpio44/value to set the voltage of GPIO44 to a low level.

You can view the set value through the command cat gpio44/value .