Jetson/GPIO
Contents
GPIO on Jetson TK1
The Jetson TK1 has both a 50-pin and a 75-pin expansion port, both with 2mm spacing in rows of 25 pins:
- J3A1 (SKT2X25_THR_R 50-pin 2-row 2mm-spaced socket)
- J3A2 (SKT3X25_THR_R 75-pin 3-row 2mm-spaced socket).
The sockets on the board are female, so you have a few options for physically connecting to the expansion ports:
- The Samtec TW-25-06-F-5-420-110 header can cover the whole 5x25 expansion port. It might be difficult to find if you just want 1 or 2 of them.
- You could use separate 3x25 + 2x25 connectors such as a 2-row connector from Digikey.
- You could just connect to some of the pins individually with solid hookup work or breadboarding pins, particularly if you just want access to several pins.
- You could build a PCB board with pins sticking out at 2mm spacing, providing you access to potentially all 125 expansion port pins.
To quickly test some GPIO pins
If you are building your own kernel or using an early L4T kernel before 19.2, then you need to make sure your kernel .config file contains this before building your kernel:
CONFIG_GPIO_SYSFS=y
To set GPIO_PH1 as an output:
sudo su (Enter your user password. Defaults to "ubuntu") # See which pins are currently configured as GPIO, and what their state is. cat /sys/kernel/debug/gpio # Validate that the entry for the Tegra GPIO controller has a base value of 0. If not, add on whatever the base value is to the “57” in the commands below.
echo 57 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio57/direction echo 1 > /sys/class/gpio/gpio57/value
Put a voltmeter on pin 50 (gpio57) of the 2-row header (J3A1) & pin 2 (GND) also of the 2-row header, as shown in the following photo (click to enlarge):
You should now see that it is at +1.8V. This pin is LCD_BL_PWM (GPIO_PH1). Setting it to 0:
echo 0 > /sys/class/gpio/gpio57/value
You should now see that it is at 0.0V (roughly).
Once you’re done:
echo 57 > /sys/class/gpio/unexport exit
Jetson TK1 GPIO pinout
In addition to gpio57 shown above, you can also access gpio160 to gpio166 (ports GPIO_PU0 to GPIO_PU6) as GPIO, and potentially various other pins too if you don't use 2 CSI cameras, etc.
Port | sysfs filename | Physical pin | Notes |
---|---|---|---|
GPIO_PU0 | gpio160 | Pin 40 on J3A2 | |
GPIO_PU1 | gpio161 | Pin 43 on J3A2 | |
GPIO_PU2 | gpio162 | Pin 46 on J3A2 | (Disabled by default) |
GPIO_PU3 | gpio163 | Pin 49 on J3A2 | |
GPIO_PU4 | gpio164 | Pin 52 on J3A2 | |
GPIO_PU5 | gpio165 | Pin 55 on J3A2 | |
GPIO_PU6 | gpio166 | Pin 58 on J3A2 | |
GPIO_PH1 | gpio57 | Pin 50 on J3A1 |
PWM output
You can also play with PWM output via sysfs at runtime too! You’ll need to make sure that the pinmux is set up so that PWM is routed to the pin, and that the GPIO for that pin is not claimed, so that the pinmux function is not overridden. Again, you’ll need the following in .config:
CONFIG_PWM_SYSFS=y
Then:
cd /sys/devices/soc0/7000a000.pwm/pwm/pwmchip0
Note: In the L4T kernel, the “soc0” directory component might not be there, and the PWM controller might be named something different like “pwm.0” or “pwm.1”. You might want to just run “cd /sys; find . –type d –name pwmchip*”.
Note: You might need to replace “0” in the commands below with a different PWM channel ID:
echo 0 > export cd pwm0 echo 1000000 > period echo 500000 > duty_cycle # or whatever number 0..period you want; you can write to this file later to change the duty cycle echo 1 > enable
and when you’re done:
cd .. echo 0 > unexport
I2C communication
For I2C, the commands you want for direct access are i2c{detect,dump,get,set}. Better would be to write a kernel-mode driver for the device, so that user-mode access isn’t required.
Jetson TK1 GPIO electrical connections
The GPIO pins on Jetson TK1 are all 1.8V logic and are low-current, meaning that you can't simply attach common 5V or 3.3V logic signals or devices directly to the Jetson TK1 GPIO pins. There are several options for using the 1.8V GPIO:
- Design & build your own transistor or FET based switching circuit. This is a reasonable solution if you just want to turn on 1-2 output pins and/or read 1-2 input pins and you don't need high-speed or bidirectional behavior. For example, if you only want to turn on a single LED or motor or relay then you could connect a GPIO pin through a resistor to a transistor, and get the transistor to turn on the LED, motor or relay (with a flyback diode for protection), such as explained at Transistor as a switch.
- Use a bidirectional logic level shifter to allow bidirectional behavior at high-speeds for multiple GPIO pins. This is the recommended option, particularly if you want to use more than 2 or 3 GPIO pins. Some examples are:
- An 8-channel bidirectional level shifter for $8 (might have problems with I2C).
- A 4-channel bidirectional level shifter for $4 (should handle I2C).
- Use a one-way opto-isolated level shifter, such as A 2-channel opto-isolated level shifter for $5. Opto-isolation allows you to use a separate power circuit (eg: separate batteries) for a high-power load such as a robot's motor, compared to the logic circuitry, and this is fairly crucial for industrial or rugged projects such as outdoor robotics, but typically not needed for low-power hobby projects.