Lesson 04: Jetson mini CUBE Nano Case
Vendor: Yahboom
5.1 Cube Nano Driver Library
The CubeNano driver library allows for controlling RGB lights and fans via API functions. This guide outlines the steps to install version 1.0.1 of the CubeNano driver library.
Installation of Dependent Libraries
- Install SMBus Library:
The smbus library is needed to access serial I2C devices. Use the following command to install it:
pip3 install smbus
- Install Adafruit_SSD1306 Library
The OLED display requires the Adafruit_SSD1306 library. Install it with the following command:
If the system shows a missing PIL library message, use the following solution:pip3 install Adafruit_SSD1306
sudo apt-get install libjpeg-dev zlib1g-dev pip3 install setuptools pip3 install Pillow
Python Driver Library Files
Download the CubeNano Python driver library from the GitHub. The latest version is CubeNanoLib_V1.0.1. Then, transfer the CubeNanoLib_V1.0.1.zip file to the Jetson Orin Nano system.
- Driver Library Installation:
Open a terminal in the directory containing the zip file and run the following commands:
If the installation is successful, you will see the installation version number.sudo apt-get install libjpeg-dev zlib1g-dev unzip CubeNanoLib_V1.0.1.zip cd CubeNanoLib_V1.0.1 sudo python3 setup.py install
- Importing Library Files:
To use the CubeNano driver library in your program, import it as follows:
from CubeNanoLib import CubeNano
Querying the Firmware Version Number
Enter the Python interactive interface and run each statement separately:
from CubeNanoLib import CubeNano # Import the CubeNano driver library
bot = CubeNano(i2c_bus=7) # Create the object, where 7 stands for /dev/i2c-7 (Orin Nano DevKit)
version = bot.get_Version() # Get version number
print("CubeNano Drive Library Version: ", version) # Print the version number
del bot # Delete objects
API Introduction
Below is a brief introduction to the API functions in the CubeNano driver library.
Methods
- __init__(self, i2c_bus=7, delay=0.002, debug=False): Initialize the object.
- get_Version(self): Get the firmware version number.
- set_Fan(self, state): Control the fan (0=off, 1=on).
- set_RGB_Color(self, color): Set RGB light effect color (0-6).
- set_RGB_Effect(self, effect): Control RGB light effects (0-6).
- set_RGB_Speed(self, speed): Set RGB light effect speed (1-3).
- set_Single_Color(self, index, r, g, b): Set the color of an individual RGB light.
For more details on each method, refer to the CubeNano API documentation.
5.2 OLED Display
The CUBE Nano case comes with an SSD1306 OLED display. It can display the system status in real-time, such as current system time, CPU usage, memory consumption, SD disk usage, and local IP address. Before installing the programs, ensure a proper connection between the OLED display and the chassis expansion board.
Installing Dependent Libraries
- Adafruit_SSD1306 Library: If you have already installed the Adafruit_SSD1306 library in the "5.1 Cube Nano Driver Library" tutorial, you can skip this step.
- This library is required to control the data display on the OLED.
- Install the library using the following command:
pip3 install Adafruit_SSD1306
- If the tutorial suggests that the PIL library is missing, use the following commands to install additional dependencies:
sudo apt-get install libjpeg-dev zlib1g-dev pip3 install setuptools pip3 install Pillow
Running the oled.py File
- Copy the oled.py file from the documentation to the Jetson motherboard system.
- Open a terminal in the directory where the oled.py file is located, and run the file using the following command:
python3 oled.py
- To terminate the run, press Ctrl + Z.
Modify oled.py if Necessary
If no messages are displayed on the OLED screen, you may need to modify the oled.py code. Find the class definition, change the parameter i2c_bus=1 to i2c_bus=7, and then save it.
- Edit the oled.py File:
Open the oled.py file using the following command:sudo nano oled.py
- Find the line containing i2c_bus=1 and replace it with i2c_bus=7. Save the changes and exit the editor.
class OLED: def __init__(self, i2c_bus=7, clear=False, debug=False): self.__debug = debug self.__i2c_bus = i2c_bus self.__clear = clear self.__top = -2 self.__x = 0
Functions in oled.py file
Below is a brief introduction to the functions available in the oled.py
- Functionality of OLED:
- begin(): Initialize the OLED.
- clear(): Clear the OLED display.
- add_text(start_x, start_y, text, refresh): Add characters to the OLED display at the specified coordinates.
- add_line(text, line, refresh): Add a line of text to the OLED display.
- refresh(): Refresh the OLED display.
- Functions of reading system information:
- getCPULoadRate(): Read CPU usage
- getSystemTime(): Read system time
- getUsagedRAM(): Read memory footprint and total memory
- getUsagedDisk(): Read TF Card Space Occupancy and total TF Card Space
- getLocalIP(): Get the local IP
- getFreeDisk(): Read free TF card space and total TF card space