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:
- A soldering iron: Hakko FX888D-23BY Digital Soldering Station
. The tip on the soldering iron used is the one included with the product.
- Solder, in the video 60/40 lead free solder was used.
Note: For the lead free solder, the iron was set at 750 degrees fahrenheit.
Note: A fan or fume extractor (such as the Hakko FA400-04 Bench Top ESD-Safe Smoke Absorber) should be used to avoid breathing soldering fumes.
- Breadboard (In the video, a Solderless BreadBoard, 400 tie-points, 4 power rails
was used)
- We also used some M/F breadboard jumper wire
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!
27 Responses
Any chance this works on a TX1?
It does, the bus numbers for the pins are reversed. Pins 27 and 28 on the TX1 are for I2C Bus 1. Thanks for reading!
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
It looks like you have a typo. Try:
$ sudo apt-get install libi2c-dev i2c-tools
I hate it when that happens… Thanks for your help…
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.
This is beyond what I can cover here. 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/
Thanks for the tutorial – it works a treat!
Do you know how to send bounding box coordinates data to I2C?
Or any clues on how to do it?
Thanks!
I do not know what you mean by bounding box coordinates. Please see the code example on how to send data over the I2C bus. Thanks for reading!
The bounding box is the box the software draws around an object that has been recognised 🙂
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 !!!!
It is in the source code for the detectnet-camera program you are using. This is not related to this article. Please ask this question on the official NVIDIA Jetson forum where a large number of developers and NVIDIA engineers share their experience. Jetson TX2 forum: https://devtalk.nvidia.com/default/board/188/jetson-tx2/
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 !!
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!
OK I’ll try. Project is WEEDINATOR and I2C message is to TC275 MCU for controlling motors etc.
https://hackaday.io/project/53896-weedinator-2018
I notice that you have used a logic level shifter with the TX1 and not the TX2 – what’s the reasoning here? Thanks !
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).
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
You can modify writeDisplay in the source folder to meet your needs. Good luck on your project!
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
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!
Can I use one Jetson tx2 to drive two LED devices? One is this LED 4 segments and the other is LED 8×8 matrix https://www.adafruit.com/product/902?gclid=EAIaIQobChMIrM-H7uyk5AIVgrfsCh2B5gozEAQYAiABEgKVW_D_BwE?
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.
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?
It says that there is a device attached at 0x70 and internal devices attached at 0x40-0x43, 0x74, and 0x77. Not quite sure what your question means.
I am using this LED https://www.amazon.com/gp/product/B07MCGDST2/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1. I thought it is the same. However, it did not work. When I run
sudo i2cdetect -y -r 1
It could not see anything on address 0x70.
Why?
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.