How to Control GPIO on Nvidia Jetson Orin Nano Developer Kit
Issue Overview
Users are experiencing difficulties controlling GPIO pins, specifically the CAM0 PWDN pin (GPIO3 PH.06), on the Nvidia Jetson Orin Nano Developer Kit. The main issue is a discrepancy between the expected GPIO pin assignment and the actual system output when using the gpioinfo
command. Users are unable to control the output high and low levels of this pin as desired.
Key details:
- IDE: Jetson 36.0
- JetPack: 6.0
- Core board: Orin Nano 4GB
- Board: Jetson Orin Nano Developer Kit
- Kernel source: Jetson Linux 36.3
- Rootfs source: Basic Flavor Root File System
Possible Causes
- Driver Occupation: The GPIO pin is being used by a camera control driver, preventing user-space access.
- Device Tree Configuration: The device tree may have a pre-configured node that sets the GPIO as a camera control output.
- Pinmux Configuration Mismatch: There might be a mismatch between the pinmux configuration and the actual system implementation.
- Software Version Incompatibility: The issue could be related to specific versions of JetPack or Jetson Linux.
Troubleshooting Steps, Solutions & Fixes
-
Verify GPIO Status:
Run the following command to check the current status of GPIO pins:sudo gpioinfo
Look for the line corresponding to PH.03 or PH.06.
-
Identify Driver Usage:
If the GPIO is marked as [used], it’s likely being controlled by a driver. In this case, you’ll see an output similar to:line 46: "PH.03" "camera-control-output-low" output active-high [used]
-
Review Device Tree:
Check your device tree for nodes similar to:#define CAM0_PWDN TEGRA234_MAIN_GPIO(H, 6) gpio@2200000 { camera-control-output-low { gpio-hog; output-low; gpios = <CAM0_PWDN 0>; label ="cam0-pwdn"; }; };
-
Modify Device Tree (if camera control is not required):
- Remove the camera control node from the device tree.
- Recompile the device tree and flash it to your Jetson Orin Nano.
-
Use User-space GPIO Control:
If you’ve removed the camera control node, you can now control the GPIO from a user-space application. Use thelibgpiod
library for GPIO control:Install libgpiod:
sudo apt-get install libgpiod-dev
Example C code to control GPIO:
#include <gpiod.h> #include <stdio.h> #include <unistd.h> #define CHIP_NAME "gpiochip0" #define GPIO_LINE 49 // PH.06 int main() { struct gpiod_chip *chip; struct gpiod_line *line; int ret; chip = gpiod_chip_open_by_name(CHIP_NAME); if (!chip) { perror("Open chip failed"); return 1; } line = gpiod_chip_get_line(chip, GPIO_LINE); if (!line) { perror("Get line failed"); gpiod_chip_close(chip); return 1; } ret = gpiod_line_request_output(line, "example", 0); if (ret < 0) { perror("Request line as output failed"); gpiod_chip_close(chip); return 1; } // Set GPIO high gpiod_line_set_value(line, 1); sleep(1); // Set GPIO low gpiod_line_set_value(line, 0); gpiod_chip_close(chip); return 0; }
-
Update JetPack and Jetson Linux:
Ensure you’re using the latest compatible versions of JetPack and Jetson Linux to rule out any software-related issues. -
Consult Nvidia Documentation:
Review the Jetson Linux Developer Guide and Jetson Orin Nano Developer Kit documentation for any specific instructions or known issues related to GPIO control. -
Community Support:
If the issue persists, consider posting a detailed description of your problem, including your hardware setup and software versions, on the Nvidia Developer Forums for additional assistance.