JetsonHacks

Developing on NVIDIA® Jetson™ for AI on the Edge

GPIO Interfacing – NVIDIA Jetson TX1

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 GPIOPinJetson Signal NamePUPD
gpio36Pin 32AO_DMIC_IN_CLKPULL_DOWN
gpio37Pin 16AO_DMIC_IN_DATPULL_DOWN
gpio38Pin 13GPIO20/AUD_INTPULL_DOWN
gpio63Pin 33GPIO11_AP_WAKE_BTPULL_DOWN
gpio184Pin 18GPIO16_MDM_WAKE_APPULL_DOWN
gpio186Pin 31GPIO9_MOTION_INTPULL_UP
gpio187Pin 37GPIO8_ALS_PROX_INTPULL_DOWN
gpio219Pin 29GPIO19_AUD_RSTPULL_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:

Schematic GPIO Jetson TX1
Schematic GPIO Jetson TX1
Jetson TX1 GPIO LED Interface
Jetson TX1 GPIO LED Interface

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

Jetson TX1 GPIO Example - Button and LED
Jetson TX1 GPIO Example – Button and LED
Interfacing GPIO on the Jetson TX1 with a breadboard
Interfacing GPIO on the Jetson TX1 with a breadboard

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.

Facebook
Twitter
LinkedIn
Reddit
Email
Print

42 Responses

  1. 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

    1. 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.

      1. 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.)

        1. 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.

          1. 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.

    2. 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.

    1. 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!

  2. How did you figure out the mapping from gpio number to pin number? (For example, how did you figure out that gpio38 is pin13?)

  3. Is it work on jetson tx-2 too?? I’m working with jetson tx2 and I want to make GPIO interface..

      1. 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??

  4. 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

    1. 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.

  5. 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?

    1. 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!

      1. 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)?

  6. 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?

  7. 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!

  8. 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

    1. 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.

  9. 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?

      1. 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?

  10. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclaimer

Some links here are affiliate links. If you purchase through these links I will receive a small commission at no additional cost to you. As an Amazon Associate, I earn from qualifying purchases.

Books, Ideas & Other Curiosities