Remember when you had to jump through all sorts of hoops to get your NVIDIA Jetson NVIDIA Kit to be able to understand Serial Protocol Interface (SPI) devices? Those days be gone. Looky here:
Background
The introduction of JetPack 4.3 brings with it a new tool, Jetson-IO. All of the Jetson developer kits include a 40-pin GPIO expansion header. Many of the pins can be used either as General Purpose I/O (GPIO) or Special Function I/O (SFIO). SFIO are functions such as I2C, I2S, SPI, and so on.
The default configuration of the pins is defined and programmed into the Jetson when flashed. Previously you had to go through a, let’s call it less than straightforward, process to reconfigure the pins to your needs.
The new Jetson-IO tool is here to help! While the previous process is useful for system designers, the majority of developers many times just look to modify the pins to the NVIDIA recommended special functions.
For example, if we look at a typical Jetson GPIO Expansion Header (such as this one for the Jetson Nano), we see that there are several pins that list as SPI_1, but we know that in the default configuration they are GPIO.
This is similar to other Linux embedded systems such as the Raspberry Pi. The RPi has a similar utility, raspi-config, to help with configuring pins on that device.
The default configuration sets most of the pins to GPIO. Here’s how to run Jetson-IO to change that.
Jetson-IO
The Jetson-IO utility is just a youngster, and in its initial release on the Jetson in JetPack 4.3 (L4T 32.3.1) there are some issues. These issues are noted in the documentation. The following two issues have been addressed in later releases.
The first issue involves initialization of some of the code. To fix it:
$ sudo find /opt/nvidia/jetson-io/ -mindepth 1 -maxdepth 1 -type d -exec touch {}/__init__.py \;
The second issue occurs only on the Jetson Nano. On the Jetson Nano, one of the directories needs to be set up:
$ sudo mkdir /boot/dtb
$ sudo cp -v /boot/tegra210-p3448-0000-p3449-0000-[ab]0[02].dtb /boot/dtb/
Then there’s a niggle to which you should be aware. If the Terminal window that you are working in is too small, then the menus have difficulty displaying. Make sure that your Terminal window is large, so it can hold the menus.
Running Jetson-IO
After the setup, we’re ready to go:
$ sudo /opt/nvidia/jetson-io/jetson-io.py
Which will bring us to the main screen:
We select Configure 40-pin expansion header:
In our case we select SPI1 (pins 19,21,23,24,26). Use the arrow keys to navigate to the desired entry, Return selects/deselects the entry. Select Back when done. You should see the new configuration on the main menu. Save and reboot to reconfigure pins. You will go through the familiar Confirm/’Deny everything you have ever done’ prompts, then the system will reboot. After that, SPI goodness is available.
Of course, the Jetson-IO utility has much more functionality than this simple example. Look through the documentation to see what you can do to amaze your friends and confuse your enemies!
SPI Display Example
In the video, we connect to a Adafruit 1.8″ TFT Display to a Jetson Nano. The display is also available through Digikey and Adafruit. There is an excellent tutorial on the Adafruit site about the Display and how to use it. We won’t go over this too much more here.
After soldering the headers onto the display, we wire the display:
Jetson Nano | Adafruit 1.8″ TFT Display |
Pin 6 GND | Pin 1 GND |
Pin 1 3.3V | Pin 2 VCC |
Pin 18 gpio15 | Pin 3 Reset |
Pin 22 gpio13 | Pin 4 D/C |
Not Connected | Pin 5 CARD_CS |
Pin 24 SPI_1_CS0 | Pin 6 TFT_CS |
Pin 19 SPI_1_MOSI | Pin 7 MOSI |
Pin 23 SPI_1_SCK | Pin 8 SCK |
Not Connected | Pin 9 MISO |
Pin 17 3.3V | Pin 10 LITE |
Note that while SPI is only 4 signals (6 if you count power and ground), this device has a couple of more in use. One of the extra connections provides power to the backlight of the display.
There are a couple of examples for this particular display on the JetsonHacksNano account on Github in the repository SPI-Playground. Clone the repository, and switch over that that repositories example directory:
$ git clone https://github.com/JetsonHacksNano/SPI-Playground
$ cd SPI-Playground/examples
There you will find instructions on how to install the prerequisites in the README.md file:
$ sudo apt-get install python3-pip
$ pip3 install adafruit-blinka
$ pip3 install adafruit-circuitpython-busdevice
$ pip3 install adafruit-circuitpython-rgb-display
$ sudo apt-get install python3-pil
Examples
There are two examples here.
Example 1 will display a shark on the screen.
$ python3 rgb_display_pillow_image.py
The second example shows some of the Jetson stats on the display:
$ python3 rgb_display_pillow_stats.py
All in all, pretty straightforward. At least compared to the old days!
Notes:
- Example shown: JetPack 4.3/L4T 32.3.1
- Jetson Nano
The post SPI on Jetson – Using Jetson-IO appeared first on JetsonHacks.