Quantcast
Channel: JetsonHacks
Viewing all articles
Browse latest Browse all 339

Adafruit PiOLED on Jetson Nano

$
0
0

The Adafruit PiOLED is a useful addition for many projects on the NVIDIA Jetson Nano Developer Kit. Looky here:

Background

One of the first public tech demos of the Jetson Nano is the JetBot. The JetBot is an open-source, entry level robot that specializes in teaching entry level deep learning.

One of the hardware items on the JetBot is the Adafruit PiOLED (product id 3527). You can pick this up at the JetsonHacks Amazon Storefront, or directly from Adafruit itself.

While the Adafruit PiOLED is useful on the JetBot, there are a wide range of applications and uses that make this a valuable addition to our project tool chest. It’s great to be able to display a small snippet of information without having the bulkiness of a full display!

You can imagine several uses where this may be particularly valuable. For example, let’s say you have a robot where you need to be able to determine the network address. It’s difficult to guess what the address might be, so having it display on the PiOLED is a really nice feature.

In fact, many headless applications of the Jetson Nano can benefit from this. In the example we provide, you can monitor such things as memory usage, disk usage, and even make simple graphs for CPU and GPU use. Plus, you won’t have to SSH into the Jetson to have to figure out some simple things you could have at a glance.

Installation

The PiOLED is simple to install on the Jetson. The female header on the PiOLED mounts directly to the Jetson Nano J21 GPIO expansion header pins 1 through 6. You should be able to align the pins with the header, and by gently pressing down, be able to seat the display. It should look like this.

Software Installation

On the JetsonHacksNano Github account, there is a repository installPiOLED. From a Terminal, clone the repository, and switch over to that repositories directory:

$ git clone https://github.com/JetsonHacksNano/installPiOLED
$ cd installPiOLED

The PiOLED uses a SSD1306 driver chip. Adafruit has written a driver to interface with the chip. To install the driver along with a simple example app:

$ ./installPiOLED

You can now test the PiOLED:

cd pioled
sudo python3 stats.py

Note: About the sudo usage. The isntallPiOLED sets user permissions so you can access the display from ‘user space’. These permissions take effect once you log out/log in to your account. We use sudo here, just because we didn’t do that. Rebooting works too, of course.

To terminate the app, use Ctrl-C in the Terminal.

Running on Startup

One of the cool features of the JetBot is that the PiOLED starts displaying when the Jetson Nano starts up. We’ve nicked that code here too, and modified it a little for our use.

To turn our app as a startup service, execute:

$ ./createService.sh

This will build the app into a Python project distribution .whl file, and install it for global use. In the shell script, we use pip3 for the install.

Note: If we use sudo with pip3, the project will install in /usr/local/bin/python3.6/dist-packages. If we do not use sudo, pip3 installs the library in a hidden local folder, ~/.local/ lib/python3.6/site-packages. We want to be able to use this globally, so we use sudo.

After installation, we can power down the Jetson. The next time we power up the Nano, the PiOLED will display our app information.

About Python Packaging & Startup

A couple of things about packaging Python code. The script in the repository is the barest of skeleton for doing this. There are three points to look at if you want to do this for ‘reals’.

First, the top level directory contains the file setup.py. This file builds the proper descriptors for a Python package. There are many items in a properly constructed setup statement, you will need to research these items to determine which are suitable for your project.

Second, there’s a bit of Python nomenclature. A module is simply a Python script, in our case stats.py. A Python package is a directory/folder which contains module(s) and a special file, __init__.py. You may hear people refer to this as dunder init (double underscore). The dunder init tells the Python packaging script to include this directory in the package.

On Linux/Ubuntu, one of the places to store startup actions is in /etc/systemd. In our case, we store a .service file in the subfolder system. The script utils/create_stats_service.py builds the pioled_stats.service file. It’s worth looking through the .service file, the important line is:

ExecStart=/bin/sh -c “python3 -m pioled.stats”

This line launches a shell, and runs python3 with our application. pioled.stats resolves to the stat.py that we install from our previous script. Notice that because out display loop for PiOLED is in an infinite loop, the process will not terminate after we start it up.

A more detailed explanation

Over on the NVIDIA Jetson Nano forum, user mdegans wrote a way excellent post on how to properly set up a program/script to run at startup using the systemd service mechanism. Well worth the read if your interests lie in understanding and implementing a startup service correctly.

Notes

December 2019

  • Initial Release
  • Jetson Nano
  • Adafruit PiOLED
  • L4T 32.2.1/JetPack 4.2.2

The post Adafruit PiOLED on Jetson Nano appeared first on JetsonHacks.


Viewing all articles
Browse latest Browse all 339

Trending Articles