Interfacing with the Jetson TX1 GPIO (General Purpose Input/Output) subsystem can be accomplished with a small “C” programming language library and knowledge of the J21 expansion header. Looky here:
Background
In a previous JetsonHacks article GPIO Interfacing – NVIDIA Jetson TK1, we covered how to interface with the Jetson TK1 GPIO subsystem. This article discusses interfacing with the Jetson TX1 in a similar manner.
Note: The usual warning, you are dealing with electricity and all that, there is a chance you could fry your Jetson by hooking it up incorrectly. Be strong, be brave, but also be very careful.
In the demonstration, a simple GPIO library interface for the Jetson TK1 was created, and a little hardware/software demo was built. The hardware consists of a couple of circuits, a LED driven by a GPIO pin on the Jetson, and a button switch which is read from another GPIO pin on the Jetson.
Jetson TX1 GPIO Layout
The Jetson TX1 J21 Header signal layout is described on this page: J21 Header Pinout.
There are few documents which are used to derive the list of GPIO header signals on the J21 Header of the Jetson TX1 Development Kit. J21 is a 40 pin header. The documents are all available from the NVIDIA Embedded Download Center.
- Jetson TX1 Module Pinmux – Spreadsheet which lists how signals are routed from the TX1 Module to the Jetson Carrier Board
- Jetson TX1 Developer Kit Carrier Board Specification – Information about the Carrier Board and Interface Connectors. Section 3.4 Expansion Header gives the Expansion Header Pin Descriptions in table form.
- Jetson TX1 Developer Kit Carrier Board Schematics and Layout Files – Schematics for the Carrier Board (useful, but may not be necessary for the given task)
- The kernel source file: drivers/pinctrl/pinctrl-tegra210.c contains the signal name to gpio number mappings
There are 8 GPIO signal pins on the Jetson TX1 J21 Header:
Jetson TX1 J21 Header | |||
---|---|---|---|
Sysfs GPIO | Pin | Jetson Signal Name | PUPD |
gpio36 | Pin 32 | AO_DMIC_IN_CLK | PULL_DOWN |
gpio37 | Pin 16 | AO_DMIC_IN_DAT | PULL_DOWN |
gpio38 | Pin 13 | GPIO20/AUD_INT | PULL_DOWN |
gpio63 | Pin 33 | GPIO11_AP_WAKE_BT | PULL_DOWN |
gpio184 | Pin 18 | GPIO16_MDM_WAKE_AP | PULL_DOWN |
gpio186 | Pin 31 | GPIO9_MOTION_INT | PULL_UP |
gpio187 | Pin 37 | GPIO8_ALS_PROX_INT | PULL_DOWN |
gpio219 | Pin 29 | GPIO19_AUD_RST | PULL_UP |
The Signal Name represents the name of the signal on the Jetson TX1. The signal names are provided as the suggested interface pin for people who are designing and adding the given named functionality to the Jetson. This does not mean that the GPIO pins are dedicated, all GPIO pins are generic. In other words, the names do not signify any built in functionality.
Sysfs GPIO is the name of the virtual file that can be used to access the GPIO port. The file is accessed in the ‘/sys/class/gpio’ directory.
Signals on the header can be configured to run at 3.3V or 1.8V by shorting the appropriate pins on the J24 header. For this example, 3.3V is selected, which is the standard configuration.
Signals on the J21 header can be configured with a resistor as a PULL_DOWN, PULL_UP, or NORMAL circuit. The standard configuration is noted in the table. The resistance value is 4KΩ.
All of the signals are enabled for E_input.
The Jetson TX1 includes the ability to export GPIO control and status for use in an application using sysfs. No other driver can be using the GPIO of interest.
Pinmux
In the Jetson community, you may run across the term ‘Pinmux’. On the Jetson TX1 module, there are more signals on the chip than there are on the carrier board. A multiplexer (or “mux”) is a device that selects one of several input signals and forwards the selected input into a single line. The Pinmux table is used to describe which pins are selected on the processor and how to route them to the board using the multiplexer. This table is typically described in a source code format which once compiled into a data structure can be used by the operating system for signal routing. This data structure, called the ‘Device Tree’, is loaded at boot time by the operating system.
Source files for the Device Tree are located in the kernel source for L4T, and have a .dts or .dtsi extension. Compiled .dts files have a .dtb extension. In addition to the base Device Tree, overlays can be created to add additional functionality without having to recompile the entire Device Tree or maintain a monolithic binary blob. The pinmux description can be changed for different signal routing depending on the system needs. For this article, it is assumed that the standard configuration is being used.
Parts
For the LED circuit:
- 2.3V 16ma LED
- BC547 transistor
- 10KΩ resistor
- 560Ω resistor
For the button circuit:
- Tactile Button Switch
- 100Ω resistor
- 1KΩ resistor
Note: All resistors are 1/4 watt
Jumper Wires, 2.54mm 1p to 1p male to female
Breadboard (In the video, a Solderless BreadBoard, 400 tie-points, 4 power rails was used)
Multimeter (Optional, a Fluke 115 Electricians True RMS Multimeter was used)
The The Arduino Starter Kit has a wide selection of the above components).
GPIO Interfacing Wiring
Here are some pseudo schematics of the circuits:
If we look at the Jetson TX1 J21 header pinout, we see that Pin 13 is gpio38. We will use this as our button input to the Jetson. We also see that Pin 29 is gpio219, which we will use to drive the LED.
Breadboard Layout
Software Installation and Demonstration
The GPIO library and example code to run the breadboard prototype is stored on the JetsonHacks Github account. To clone the repository:
$ git clone git://github.com/jetsonhacks/jetsonTX1GPIO.git
To build the example:
$ cd jetsonTX1GPIO
$ ./build.sh
Once the example has been compiled, run the example:
$ sudo ./exampleGPIOApp
The ‘sudo’ is needed to get permission for accessing the GPIO subsystem. The example application will start up and flash the LED a few times. Next, the user can tap the button to turn the light on and off, the button pressed is ‘on’, the button not pressed is ‘off’. The application runs until the user hits the ‘Esc’ key on the keyboard.
Other GPIO Pins
There are other GPIO signals available on the camera and display connectors on the Jetson TX1. These signals can be accessed much the same way in software as the ones on the J21 header, but are a little harder to interface with through the fine pitch board connectors.
Conclusion
This is a simple way to interface with GPIO on the Jetson, try it out! The code is provided for the library, as is the example application. Note that this is a very simplistic version of a GPIO interface library. There are many types of device interface strategies for using GPIO, this is a starting basis for how it could be approached.
Notes
The demonstration was performed on a Jetson TX1 development kit running L4T 23.1.
42 Responses
Hi Kangalow,
I’m trying to interface the new MM7150 IMU by Microchip to Jetson TX1 and I need an info: how can I configure PULL UP/DOWN resistor on GPIO pins?
Thank you
Walter
Hi Walter,
I do not know how to configure them. I hope you can work through it, your IMU project seems interesting.
Where did u find the information of which pins are pulled up and which are pulled down?
Just about every connection from the Jetson GPIO pins to the board has some kind of resistor on it. Whyso?
The most basic answer is that you don’t want to short directly to ground (resistors limit current flow), but the real answer is elementary electrical engineering and beyond the scope of this article.
Coming from the Arduino world, this is far more resistors than I’d see in the equivalent circuit.
Specifically, this circuit does the same thing as the classic Arduino “button” example, which uses only one resistor:
https://www.arduino.cc/en/Tutorial/Button
This circuit for the Jetson adds resistors on the input pin back to detect the button press, and the P pin of the transistor. Why do you need those? Are the Jetson GPIO pins so fragile that we need to make sure they always have at least nominal resistance for any voltage on them?
(The purpose of the other two resistors are indeed obvious.)
Arduinos have built in pull up resistors on their pins (programmable) to protect them. For example in the tutorial diagram there is another resistor, it’s just built into the Arduino board itself and therefore not shown.
On the other hand, the Jetson TX1 has pull-up/pull-down/none (4KΩ) on pins depending on configuration. The above circuit just assumed no other resistors being set onboard the Jetson itself. At the time when this article was written I had just figured out the GPIO pin mappings. While I believe that the above table with resistance values is correct, I decided to take a conservative route and just add the extra resistors.
Makes sense. Thanks!
If I’m not mistaken the internal pull up’s on the Arduino are off by default and in order to you use them you have to expressly enable them. The shown sketch does not do that… mention this because I’m also curious, like Sam, why the schematics differ. I suspect it has to do something with the the possibility that the Vcc lines of the Arduino do not provide that much current. Assuming the TX1 is closer in design to something like an RaspeberryPi, the GPIO and Vcc lines provide almost as much current as the DC power source.
Indeed, the design of the J21 40 pin GPIO header follows the Raspberry Pi very closely. If you compare pin outs, you’ll notice that they’re laid out in a similar fashion. I just went with something that I knew would work, and wouldn’t fry the Jetson. I’m sure there are much better circuits to use, I just used something simple as a demonstration for how to use GPIO pins. The point of the article is how to access the GPIO pins from software.
Is there a way to get interrupt calls from GPIO input on the TX1? (instead of just polling them).
My guess is that there is a way to do that, but I don’t know how. You’ll probably have to check through the reference material, source code and pinmux spreadsheet mentioned above to figure out how to map it correctly. Good luck, and thanks for reading!
How did you figure out the mapping from gpio number to pin number? (For example, how did you figure out that gpio38 is pin13?)
By piecing together information from the 4 documents listed in the section Jetson TX1 GPIO Layout
Is it work on jetson tx-2 too?? I’m working with jetson tx2 and I want to make GPIO interface..
It is similar. The GPIO numbers are different. See:
https://jetsonhacks.com/nvidia-jetson-tx2-j21-header-pinout/
Thanks for reading!
Thank you for your reply. It was very helpful!
And I have another question..
Is the code from the video works at tx2 same as tx1??
Once you change the GPIO numbers, it should. However, I have not tried it myself. Good luck!
Hey i was testing gpio s in my tx1 but it seems that my some of my pins are not working properly.
I used the same code and changed its pins to one that are in the layout yet it gives me different results. i am using my pins as outputs only maybe this is my problem? any ideas? i’m just stuck in this for days. thx
Hi David,
This isn’t enough information to make a suggestion. What are you connecting to the Jetson?
Kangalow, Do you have libraries for opencv and c++? or how can I access to the GPIO.
Greetings
Hi Jose,
This is an article about accessing the GPIO. Have you tried it?
KangaloW,
done it already, I want to acces to GPIO using OpenCV is that posible ?
Sorry, I don’t know what that means. OpenCV is for running computer vision algorithms, the GPIO is accessed with low level code. Whatever programming language you are using to access the OpenCV library can be used to access the GPIO.
Hei kangalow 🙂
Using your site a lot, it’s very informative and a good resource. So thanks in for doing this!
Anyway, I am thinking of using GPIO to read encoder input. Will that work? I was thinking of the rate of pulses by the encoder, will the GPIO read correct? I have this motor (with encoder); https://www.dfrobot.com/product-1210.html
Any thoughts?
It seems like it should work, though I don’t have any experience with them. Note that the encoders are 5V, the GPIO on the Jetson is 1.8/3.3V. You will have to convert the signal to the appropriate voltage. Thanks for reading!
Are there any ways to use GPIO J26 header? Could I use GPIO J26 under sysfs?
You should be able to. You will need to translate the signals to their sysfs numbering appropriately.
How to do that? How to translate signals to sysfs?
Should I add GPIO J26 to device tree, recompile kernel, if I want just connect button to CAN_GPIO4, CAN_GPIO5, CAN_GPIO6 (1, 9, 13 pins)?
Hi,
My suggestion is to ask for help in the official NVIDIA Jetson TX1 Forum: https://devtalk.nvidia.com/default/board/164/jetson-tx1/
There may be developers there which have already worked through how to do this.
Hey,
You have mentioned that there are 8 GPIOpins that can be used on J21 header. However,this header has total of 40 pins. I understand some of them are reserved for 5V, 3.3V,GND,I2C or serial interface (so they cannot be used). But still there are other pins (for example Pin 7, 11, 12, 15 etc.)that don’t look reserved to me.
Can we not use these?
Here’s a map: https://jetsonhacks.com/nvidia-jetson-tx1-j21-header-pinout/
You can reassign pins not related to power to anything as needed using the device tree. Thanks for reading!
Hello Jim! Do you know if this tutorial will work on the Jetson TX2 with the GPIO mapped accordingly? I’m using Jetpack 3.3. Thanks!
Yes, it should. Please compare the pinouts on the TX1 and the TX2 to make sure you have the right pins and Linux gpio values. Thanks for reading!
Hi,
I have a Jetson TX2 dev kit and I want to use its GPIO pins under ROS. The GPIO example on the website works properly, but I need to have the GPIO pins without the sudo privileges because of ROS. I tried to add the nvidia user to the dialout group but that does not solved anything. Do you know any solution for this?
Thanks
Please ask this question on the official NVIDIA Jetson forum where a large number of developers and NVIDIA engineers share their experience. The forum is here: https://devtalk.nvidia.com/default/board/188/jetson-tx2/
Apparently, you need to be very careful how you do this or else it will screw up your TX2. Whatever the solution, maybe try it on a raspberry pi first to check it works ok.
Hello! I am currently working on a Jetson TX2 project and unsure about how to interface an Olimexino(Arduino like) controller to the Jetson. My objective is to establish a communication between both to send/recieve data from each other.I understand GPIOs are used for digital input/output, however I want to transfer float values. Could you suggest me a solution?
https://github.com/paddygoat/WEEDINATOR/blob/master/platforms/Jetson%20TX2/detectnet-camera/detectnet-camera.cpp
Thank you for the help! Unfortunate for me, I am working on python in my project, and I am not very good at C++. Could you refer me a solution in the python platform?
Thank you for the help! Unfortunate for me, I am working on python in my project, and I am not very good at C++. Could you refer me a solution in the python platform?
Please ask this question on the official NVIDIA Jetson forum where a large number of developers and NVIDIA engineers share their experience. The forum is here: https://devtalk.nvidia.com/default/board/164/jetson-tx1/