yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Jetson CUBE case📖
0.ReadMenew
  • ReadMe
1.Assembly Tutorial
  • 1.Installation Video
  • 2.Wiring Instructions
2.Drive Tutorials
  • 1. Install CubeNano driver library
  • 2. OLED display
  • 3. Fan drive
  • 4. RGB Light Bar Driver
  • 5. Setting up boot-up
Download
  • Instruction Manual
  • I2C Protocol
  • Code
  • Drive_ORIN_22.04
  • Drive_JetsonNANO_ORIN_20.04
Download ZIP

Welcome to Jetson CUBE case repository

4. RGB Light Bar Driver

RGB Light Bar Driver

RGB Light Bar DriverI. Learning ObjectivesII. Preparation before experimentIII. Using CubeNano driver library to control RGB light bar1. Import the CubeNano driver library and create the objects.2. Setting up RGB light effects3. Setting the speed of RGB light effects4. Setting the RGB light effect colours5. Setting individual RGB light colours6. Code DemonstrationIV. Using Jupyter lab to control RGB light bar1. Import the CubeNano driver library and create objects2. Setting up RGB light effects3. Setting the speed of RGB light effects4. Setting the RGB light effect colours5. Setting individual RGB light colours6. Deleting objects7. Code Demo8. Jupyter lab basic operationV. Experimental phenomena

I. Learning Objectives

  • Master the Jetson Nano series motherboards to control RGB light bars
  • Control RGB light bar with CubeNano driver library
  • Control RGB light bar through Jupyter lab

II. Preparation before experiment

Install the Jetson CUBE Nano chassis according to the assembly video tutorial, or refer to the "Jetson CUBE Nano Chassis_Hardware Wiring" tutorial document for installation, here we show the chassis expansion board and RGB light bar and fan hardware connections.

1

Chassis expansion board3 Pin connector2Pin connector
 RGB light barFan

III. Using CubeNano driver library to control RGB light bar

1. Import the CubeNano driver library and create the objects.

The name of CubeNano driver library is CubeNanoLib, use CubeNanoLib to import the library in the programme.

from CubeNanoLib import CubeNano

The CubeNanoLib library functions needed to control the RGB light bar:

xxxxxxxxxx
set_RGB_Effect(effect)  #设置RGB灯特效#Setting up RGB light effects
set_RGB_Speed(speed)    #设置RGB灯特效速度#Setting the speed of RGB light effects
set_RGB_Color(color)    #设置RGB灯特效颜色# Setting the colours of RGB light effects
set_Single_Color(index, r, g, b)    #设置单个RGB灯颜色# Setting individual RGB light colours

2. Setting up RGB light effects

set_RGB_Effect(effect): set RGB light effects
 

 

Effect valueRGB Light Effect
0Turn off effects
1Single colour breathing light
2runaway light
3rainbow light
4dazzling light
5flowing light
6cycling breathing light

3. Setting the speed of RGB light effects

set_RGB_Speed(speed): set the speed of RGB light effects
 

 

Speed valueRGB light effects speed
1low speed
2medium speed
3high speed

4. Setting the RGB light effect colours

Note: This function can only set the effect in single-colour breathing light and running light.

set_RGB_Color(colour): set RGB light effect colour
 

 

Color valueRGB light effect color
0red
1green
2blue
3yellow
4purple
5cyan
6white

5. Setting individual RGB light colours

Note: All colours can be combined from different brightness levels of red, green and blue;

set_Single_Color(index, r, g, b): set a single RGB light colour
 

 

parametricIndividual RGB light colour
indexSerial number (0 - 13, 255)
rRed (0 - 255)
gGreen (0 - 255)
bBlue (0 - 255)

index parameter: 0-13 corresponds to the serial number of different lamp beads respectively; where index = 255, means set all RGB lamp colours.

r, g, b parameter: 0-255 means different colour brightness level.

6. Code Demonstration

  • control RGB light bar effects and functions (python interactive interface: each statement needs to be run separately)

​x
from CubeNanoLib import CubeNano
bot = CubeNano(i2c_bus=1)
​
bot.set_RGB_Effect(0)
bot.set_RGB_Effect(1)
bot.set_RGB_Effect(2)
bot.set_RGB_Effect(3)
bot.set_RGB_Effect(4)
bot.set_RGB_Effect(5)
bot.set_RGB_Effect(6)
​
bot.set_RGB_Speed(1)
bot.set_RGB_Speed(2)
bot.set_RGB_Speed(3)
​
bot.set_RGB_Effect(1)
​
bot.set_RGB_Color(0)
bot.set_RGB_Color(1)
bot.set_RGB_Color(2)
bot.set_RGB_Color(3)
bot.set_RGB_Color(4)
bot.set_RGB_Color(5)
bot.set_RGB_Color(6)
​
bot.set_Single_Color(5,0,0,255)
bot.set_Single_Color(255,255,255,255)
del bot

3584071b35fbb2cc965a64170bf63d2d

  • RGB Light Effects Test (RGB_Test.py)

xxxxxxxxxx
import time
from CubeNanoLib import CubeNano
​
if __name__ ==  '__main__':
    bot = CubeNano(i2c_bus=1)
    while True:
        bot.set_RGB_Effect(0) # 关闭特效5秒 Turn off the effect for 5 seconds
        time.sleep(5)
        bot.set_RGB_Effect(1) # 单色呼吸灯5秒 Monochromatic breathing lamp for 5 sec
        time.sleep(5)
        bot.set_RGB_Effect(2) # 跑马灯5秒 Marquee for 5 seconds
        time.sleep(5)
        bot.set_RGB_Effect(3) # 彩虹灯5秒 Rainbow lights for 5 seconds
        time.sleep(5)
        bot.set_RGB_Effect(4) # 炫彩灯5秒 Dazzle lights for 5 seconds
        time.sleep(5)
        bot.set_RGB_Effect(5) # 流水灯5秒 Running water lamp for 5 seconds
        time.sleep(5)
        bot.set_RGB_Effect(6) # 循环呼吸灯5秒 Circulate the lamp for 5 sec
        time.sleep(5)

image-20230717222959180

Note: To terminate the run you can press Ctrl + Z

IV. Using Jupyter lab to control RGB light bar

In the Jupyter lab interface to create a new file and create the following code block, respectively, edit the following content (Fan_Test.ipynb):

1. Import the CubeNano driver library and create objects

xxxxxxxxxx
# 导入CubeNano驱动库 Import the CubeNano driver library
from CubeNanoLib import CubeNano
# 创建对象 Create an object
bot = CubeNano(i2c_bus=1)

2. Setting up RGB light effects

xxxxxxxxxx
bot.set_RGB_Effect(0) # 关闭特效 Turn off effects
xxxxxxxxxx
bot.set_RGB_Effect(1) # 单色呼吸灯 Monochrome breathing light
xxxxxxxxxx
bot.set_RGB_Effect(2) # 跑马灯 Marquee
xxxxxxxxxx
bot.set_RGB_Effect(3) # 彩虹灯 Rainbow lights
xxxxxxxxxx
bot.set_RGB_Effect(4) # 炫彩灯 Dazzling lights
xxxxxxxxxx
bot.set_RGB_Effect(5) # 流水灯 Running water lamps
xxxxxxxxxx
bot.set_RGB_Effect(6) # 循环呼吸灯 Circulation breathing lights

3. Setting the speed of RGB light effects

xxxxxxxxxx
bot.set_RGB_Speed(1) # 低速 low speed
xxxxxxxxxx
bot.set_RGB_Speed(2) # 中速 Medium speed
xxxxxxxxxx
bot.set_RGB_Speed(3) # 高速 high speed

4. Setting the RGB light effect colours

xxxxxxxxxx
bot.set_RGB_Effect(1) # 单色呼吸灯 Monochrome breathing light
xxxxxxxxxx
bot.set_RGB_Color(0) # 红色 red
xxxxxxxxxx
bot.set_RGB_Color(1) # 绿色 green
xxxxxxxxxx
bot.set_RGB_Color(2) # 蓝色 blue
xxxxxxxxxx
bot.set_RGB_Color(3) # 黄色 yellow
xxxxxxxxxx
bot.set_RGB_Color(4) # 紫色 purple
xxxxxxxxxx
bot.set_RGB_Color(5) # 青色 cyan
xxxxxxxxxx
bot.set_RGB_Color(6) # 白色 white

5. Setting individual RGB light colours

xxxxxxxxxx
bot.set_Single_Color(5,255,0,0) # RGB灯条第6个灯珠显示红色 
# RGB lights Article 6 lamp beads are displayed in red
xxxxxxxxxx
bot.set_Single_Color(255,255,255,255) # 所有RGB灯珠显示白色
# All RGB beads are shown in white

6. Deleting objects

xxxxxxxxxx
# 删除对象 Delete the object
del bot

7. Code Demo

image-20230717224006162

image-20230717224114619

8. Jupyter lab basic operation

If you find that the code runs abnormally, it is recommended that you follow the steps in the figure once, and then retest the code block.

image-20230717224225424

V. Experimental phenomena

Call the functions in the CubeNano driver library to achieve the corresponding phenomenon, in which you need to set the RGB light effects before setting the colour and speed of the RGB light effects.

For example, after executing the function "Set single RGB light colour", directly using "Set RGB light effect colour" will not take effect, you need to "Set RGB light effect 1 or 5" first. effects 1 or 5" and then "set RGB light effect colour".

(The effect of using Jupyter lab to control the RGB light bar can be seen in the demo video under this folder.)

Fan drive
Setting up boot-up

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文