Jetpack<6.2的的话没有问题,Jetpack>=6.2.2有更简单的修复方法,而我刚好卡在6.2版本,非常之难绷
常规流程
按照jetson-gpio的README即可简单完成
-
安装Jetson.GPIO库
1
sudo pip install Jetson.GPIO
-
设置用户权限
1
2sudo groupadd -f -r gpio
sudo usermod -a -G gpio {your_user_name} -
运行示例程序jetson-gpio/samples,如
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26import Jetson.GPIO as GPIO
import time
# Pin Definitions
output_pin = 18 # BCM pin 18, BOARD pin 12
def main():
# Pin Setup:
GPIO.setmode(GPIO.BCM) # BCM pin-numbering scheme from Raspberry Pi
# set pin as an output pin with optional initial state of HIGH
GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.HIGH)
print("Starting demo now! Press CTRL+C to exit")
curr_value = GPIO.HIGH
try:
while True:
time.sleep(1)
# Toggle the output every second
print("Outputting {} to pin {}".format(curr_value, output_pin))
GPIO.output(output_pin, curr_value)
curr_value ^= GPIO.HIGH
finally:
GPIO.cleanup()
if __name__ == '__main__':
main()
Jetson GPIO库提供了四种给I / O引脚编号的方法(GPIO.setmode)
- BOARD:物理引脚编号(40针接口顺序)
- BCM:Broadcom SoC 的 GPIO 编号
- CVM:CVM/CVB 连接器的信号名称
- TEGRA_SOC:Tegra SoC 信号名称
查询Jeston型号
1 cat /proc/device-tree/model
1 NVIDIA Jetson Orin NX Engineering Reference Developer Kit Super查看Jetpack版本
1 jtop右上角显示版本
Jetpack 6.2 L4T 36.4.3
一般到这里你就可以根据引脚定义图愉快地开始控制了,但如果你的Jetpack版本大于等于6.2的话,你会发现无论如何也无法切换到输出模式输出高电平或者低电平
6.0>=Jetpack版本<6.2.2
由于下游内核驱动的变动,现在上层软件不能直接切换GPIO模式,所以要通过busybox更改引脚复用器,在Jetson Orin NX引脚表格中可以看到很多GPIO的默认模式是Input,所以需要进行修改
-
更新
Jetson.GPIO1
pip install -U Jetson.GPIO
2.1.7版本没有jetson-gpio-pinmux-lookup工具所以要更新,我更新到2.1.12版本就有了
-
使用Pinmux 查找工具可以快速查询到寄存器地址,如简单直观的引脚定义图或下图所示

比如我要让GPIO09也就是7号针脚改为输出控制,
1
2
3
4
5
6
7
8$ jetson-gpio-pinmux-lookup 7
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
GPIO Pin 7: Mux Register Address = 0x2448030 -
查询到地址为
0x2448030,使用devmem工具查看寄存器值1
2
3
4
5
6# 一台Jetson
$ sudo busybox devmem 0x02448030
0x0000005A
# 另一台Jetson
$ sudo busybox devmem 0x02448030
0x0000045A -
使用
devmem工具设置寄存器1
2# gpio09 板载7号
sudo busybox devmem 0x02448030 w 0x004比如还有GPIO11也就是31号针脚
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 查询寄存器地址
$ jetson-gpio-pinmux-lookup 31
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
GPIO Pin 31: Mux Register Address = 0x2430070
# 查询寄存器的值
$ sudo busybox devmem 0x02430070
0x00000058
# 修改寄存器的值 goio11 板载31号
$ sudo busybox devmem 0x02430070 w 0x004
这么一番折腾之后,你会发现终于可以输出高电平与低电平了,
如果你想知道为什么是0x004,你可以在这份文档里看到,0x004也就是100,bit10是0也就是GPIO,bit6是0也就是禁用INPUT也就是使用OUTPUT
- Set GPIO: Bit 10 = 0.
- For the output, set Bit 4 = 0 ; Bit 6 = 0.
- For Input, set Bit 4 = 1 ; Bit 6 = 1.

Jetpack版本>=6.2.2
更新到 Jetpack 6.2.2 版本有所帮助,因为现在 jetson-io.py 提供了单独启用引脚 GPIO 的选项
1 | sudo /opt/nvidia/jetson-io/jetson-io.py |

PWM控制
1 | sudo /opt/nvidia/jetson-io/jetson-io.py |
Configure Jetson 40pin Header->Configure header pins manually
勾选你想要控制的pwm口,只有给定的几个可以用,比如勾选pwm5(板载33号) pwm7(板载32)
参考
https://jetsonhacks.com/nvidia-jetson-xavier-nx-gpio-header-pinout/
https://github.com/NVIDIA/jetson-gpio
https://github.com/NVIDIA/jetson-gpio/issues/120
https://github.com/NVIDIA/jetson-gpio/issues/114
https://blog.csdn.net/shaoyantao123/article/details/147252691
https://www.linkzeelabs.com/wiki/books/jetson-orin-nx/page/gpio
说些什么吧!