JetsonHacks

Developing on NVIDIA® Jetson™ for AI on the Edge

I2C – NVIDIA Jetson TX2 Development Kit

It is straightforward to connect an I2C device to a Jetson TX2. Looky here:

Background

I2C is a straightforward serial protocol. There are usually two wires, one is for transferring data (SDA), the other is a clock which is used to mark the begin and end of data packed (SCL). Most devices will also require power (VCC) and ground (GND). There are several I2C busses on the NVIDIA Jetson TX2 Development Kit. You can access I2C bus 0 and I2C bus 1 on the J21 GPIO header.

Hardware

Note:A Jetson TX2 with 64 bit L4T 28.2.1 (JetPack 3.2.1) is shown in the demo

First, before powering up the Jetson, let’s wire up the LED Segment Display. Here’s the pinout of the J21 GPIO Header. In our example, we power the display from the Jetson GPIO header at 5V.

For this example project, a Adafruit 0.56″ 4-digit 7-segment Display W/i2c Backpack – Green is wired to a Jetson. The Display is assembled per the Adafruit instructions.

On a Jetson TX2, here’s a wiring combination for I2C Bus 1:

GND J21-6 -> LED Backpack (GND)
VCC J21-2 -> LED Backpack (VCC – 5V)
SDA J21-3 -> LED Backpack (SDA)
SCL J21-5 -> LED Backpack (SCL)

Note that the TX2 also has a I2C Bus 0 interface. See the J21 Pinout Diagram.

If you wish to interface with I2C Bus 0:

GND J21-6 -> LED Backpack (GND)
VCC J21-2 -> LED Backpack (VCC – 5V)
SDA J21-27 -> LED Backpack (SDA)
SCL J21-28 -> LED Backpack (SCL)

Note: To use Bus 0 with the example, you will need to modify the example source code.

Software Installation

Once the board is wired up, turn the Jetson on.
Install the libi2c-dev library. In order to be able inspect the LED Display, you may find it useful to also install the i2c tools:

$ sudo apt-get install libi2c-dev i2c-tools

After installation, in a Terminal execute (1 is the I2C bus in this case):

$ sudo i2cdetect -y -r 1

ubuntu@tegra-ubuntu:~$ sudo i2cdetect -y -r 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — — — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: 70 — — — — — — —

You should see an entry of 0x70, which is the default address of the LED Segment Display. If you have soldered the address pins on the Display to change the address, you should see the appropriate address.

Next, install the library and example code which is available in the JHLEDBackpack repository on the JetsonHacks Github account. To install:

$ git clone https://github.com/jetsonhacks/JHLEDBackpack.git
$ cd JHLEDBackpack
$ cd example

You are then ready to compile the example and run it.

$ make
$ sudo ./displayExample

The display will go through a couple of examples, a blinking set of dashes, a hexadecimal display, a floating point number display, a count down timer and a clock example. Hit the ‘Esc’ key during the clock example to end the example.

The library defaults to I2C Bus 1. If you want to use Bus 0, modify the example file displayExample.cpp:

HT16K33 *displayMatrix = new HT16K33() ;
// Add the following line
displayMatrix->kI2CBus = 0; // Use I2C bus 0
int err = displayMatrix->openHT16K33();

Make sure you save the file, and run make on it.

Notes

Equipment and Supplies

The segmented LED display is a kit. You will need some elementary soldering skills for assembly. We tend to use:

New to electronics? This is a pretty easy project, looky here: Electronics Tutorials for some introductory material on how to start becoming a master.

Conclusion

Accessing the I2C bus on the Jetson TX2 J21 GPIO header is straightforward, and makes for easy prototyping!

Facebook
Twitter
LinkedIn
Reddit
Email
Print

27 Responses

  1. I am having trouble installing the two libraries that you mention in your tutorial. When I try I get this:

    sudo apt-get install lib2c-dev lib2c-tools
    [sudo] password for nvidia:
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package lib2c-dev
    E: Unable to locate package lib2c-tools

    Here is my /etc/apt/sources.list file:

    nvidia@tegra-ubuntu:/etc/apt$ cat sources.list
    # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    # newer versions of the distribution.

    deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse
    deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe multiverse

    ## Major bug fix updates produced after the final release of the
    ## distribution.
    deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe multiverse
    deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe multiverse

    ## Uncomment the following two lines to add software from the ‘universe’
    ## repository.
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team. Also, please note that software in universe WILL NOT receive any
    ## review or updates from the Ubuntu security team.
    deb http://ports.ubuntu.com/ubuntu-ports/ xenial universe
    deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial universe
    # deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe
    # deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe

    ## N.B. software from this repository may not have been tested as
    ## extensively as that contained in the main release, although it includes
    ## newer versions of some applications which may provide useful features.
    ## Also, please note that software in backports WILL NOT receive any review
    ## or updates from the Ubuntu security team.
    # deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted
    # deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted

    deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse
    deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse
    # deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe
    # deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe
    # deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse
    # deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse

    Any help would be appreciated

  2. hello,
    I has read your post about TX2 pinout before,
    and the excel of GPIO mapping I have some question.
    Why you know which pin can’t used as GPIO ?
    Because the pin is for communication ?
    Thanks.

      1. eg. I run this in terminal:
        sudo ~/jetson_clocks.sh && cd jetson-inference/build/aarch64/bin && ./detectnet-camera coco-dog

        Then get this printed in terminal:
        0 bounding boxes detected
        0 bounding boxes detected
        0 bounding boxes detected
        0 bounding boxes detected
        1 bounding boxes detected
        bounding box 0 (428.906250, 438.679688) (500.812500, 510.679688) w=71.906250 h=72.000000
        draw boxes 1 0 0.000000 200.000000 255.000000 100.000000
        0 bounding boxes detected
        0 bounding boxes detected

        …. And I want to access the data eg. 428.906250 and w=71.906250
        What file prints this data? What’s it called and where does it live? What’s the name of the variables used?

        Thanks !!!!

    1. Thanks – that’s very helpful!

      Any chance you could extend this tutorial a little bit to get your I2C code working within the jetson-inference module?

      I’m not a linux expert and dont know how to change the jetson-inference makefile to get everything to work properly …… yet !!!

      I guess I could just dump your code into detectnet-camera.cpp, but this would be a bit of a mess i would think !!

      1. I think that’s a good project for you to work on, it should be very straightforward. It’s not clear what device one would be sending data to over I2C, it sounds like you have a very specific project in mind. Good luck on your project!

    1. I am not sure what article you are referring to. In general, if you are using a device that has a different signal (ie 5.0V of an I2C device vs 3.3V of the Jetson), you need to shift the levels to match. The Jetson can output 3.3V or 1.8V signals. Note that these signals voltages are different than the power voltages (VCC).

  3. Hello.
    Can you please post some code on how to send a string to an i2c device? I want to use it to send commands to an Arduino, preferably from python or C/C++.

    Thanks,
    Alex

  4. Hello,
    I am using Jetson TX2 along with STM Discovery Kit to automate a vehicle. So my plan is to send PWM values(an int value) over I2C to STM board and that board will convert to PWM signal and control the motors of the vehicle. So my question is how do i use the above library and send the commands as per my application.
    Is there any alternate efficient approach than what I am thinking. Please suggest

    1. The library in the article is just sample code, not very robust. For a real project, you should either write it yourself or find a more comprehensive library. For example, something like: https://github.com/amaork/libi2c

      You have two sides, the Jetson and the STM. You will need to determine the needs for your project, whether you use I2C, USB and so on. You will need code for both the Jetson side, and the STM side. You will need to investigate the STM side also, and wether there is any code which could be used by both platforms. Good luck on your project!

    1. It should work. You have two I2C busses you can use, or I think you should just be able to wire the two I2C devices together. You will need to set the bus number and device address according to how you wire it up.

  5. When I use a 8×8 LED matrix, the output of ic2detect was this:

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: — — — — — — — — — — — — —
    10: — — — — — — — — — — — — — — — —
    20: — — — — — — — — — — — — — — — —
    30: — — — — — — — — — — — — — — — —
    40: UU UU UU UU — — — — — — — — — — — —
    50: — — — — — — — — — — — — — — — —
    60: — — — — — — — — — — — — — — — —
    70: 70 — — — UU — — UU

    What does this mean?

    1. The LED display uses a different LED driver than the one in the article. The one you reference is a TM1637, which does not use I2C. You would have to port the driver to the Jetson from the Arduino code.

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