Jetson GPIO and Sensors with Python: the short answer
3 V and 5 V power, ground, I2C, SPI, UART and GPIO pins. 3 V and must never see 5 V. Example: The Jetson's AI results control the real world through GPIO. A transistor keeps the header pin's current tiny.
- Level
- Beginner
- Time
- About 6 min
- Topic
- NVIDIA Jetson
Use the Jetson's 40-pin header from Python with Jetson.GPIO, safely connect buttons, LEDs and I2C sensors, and know its limits.
Before this: First Boot on a Jetson Orin Nano, Digital Inputs and Outputs
The Jetson Orin Nano Developer Kit has a 40-pin header laid out like a Raspberry Pi's, with 3.3 V and 5 V power, ground, I2C, SPI, UART and GPIO pins. The signals are 3.3 V and must never see 5 V. The header pins can supply only small currents, less than a Raspberry Pi's, so drive LEDs at a few milliamps or through a transistor, and use a buffer or level shifter for anything else.
The Jetson.GPIO library comes with JetPack and uses the same style as RPi.GPIO: import Jetson.GPIO as GPIO; GPIO.setmode(GPIO.BOARD); GPIO.setup(12, GPIO.OUT); GPIO.output(12, GPIO.HIGH). BOARD mode uses physical pin numbers, which is the least confusing choice on a Jetson. To use the pins without sudo, add your user to the gpio group as described in the library's README and log in again. Pins configured for special functions such as PWM may need to be enabled first with sudo /opt/nvidia/jetson-io/jetson-io.py.
I2C sensors work as on a Pi. The header's I2C pins (3 and 5) appear as one of several buses; run i2cdetect -l to list the buses and i2cdetect -y -r followed by the bus number to scan for devices, then use smbus2 or an Adafruit CircuitPython library in a virtual environment. For anything with strict timing, many motors or lots of analog inputs, connect an Arduino, ESP32 or Pico over USB serial and let the Jetson focus on AI.
A 40-pin header like the Pi's
The Jetson's 40-pin header follows the Raspberry Pi layout for many pins, and the Jetson.GPIO library gives a similar interface to RPi.GPIO. Choose a numbering mode, either by the board's physical pin numbers or by the chip's names, and use the same mode throughout. The pins are 3.3 V logic and are not 5 V tolerant.
Set a pin as input or output, read or write it, and call cleanup at the end so the pins return to a safe state.
Permissions and limits
Your user needs permission to use the pins, usually by being in the gpio group, otherwise the program fails with a permission error. The pins supply only a few milliamps, so drive a relay, motor or bright LED through a transistor or driver. Use the I²C and SPI buses for sensors, and check they are enabled for the pins you use.
Add a short software delay or hardware filter for buttons, to cope with contact bounce.
Reading sensors
With I²C, use a library such as smbus2 and check the address with the i2cdetect tool. Sensors on 3.3 V can connect directly, and 5 V modules need level shifting. Handle read errors in a loop, so a loose wire does not crash the program.
- Connecting 5 V signals directly to the header pins.
- Mixing physical and chip pin numbering in one program.
- Driving a relay or motor straight from a pin.
Light a 'person detected' LED from a detection script
- detectnet finds a person with confidence above 0.6.
- The script calls GPIO.output(12, GPIO.HIGH) and records the time.
- If no person is seen for 3 seconds, it sets the pin LOW.
- The LED is driven through an NPN transistor so the header pin supplies under 1 mA.
Result. The Jetson's AI results control the real world through GPIO. A transistor keeps the header pin's current tiny.
Wire an LED (with a resistor sized for about 3 mA) and a button to the Jetson's header. Write a Python script with Jetson.GPIO that toggles the LED on each button press. Then scan the I2C bus on pins 3 and 5 with a BME280 connected and read it from Python.
3 quick questions
What voltage are the Jetson header's GPIO signals?
Which numbering does GPIO.BOARD use?
How do you find which I2C bus is on pins 3 and 5?
