Welcome to CUBE Pi Case repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
Install driver library
Install driver library
Install driver library1. Introduction2. Install dependent libraries1. smbus library2. Adafruit_SSD1306 library3. Python driver library file4. Transfer files to the motherboard system5. Driver library installation6. Import library fileVII. Check the firmware version number1. Check the version number2. bot = CubeRaspberry(i2c_bus=1)8. API Introduction
1. Introduction
After installing the CubeRaspberry driver library, you can call the corresponding API function to control the RGB lights and fan peripherals.
You can also follow the steps below to update the driver library!
Please refer to the following steps to install the driver library. Here, we take the installation of version V1.0.2 as an example.
Note: The CubeRaspberry chassis will automatically turn on the RGB lighting effect and fan when it is powered on.
2. Install dependent libraries
1. smbus library
The installation of the CubeRaspberry driver library requires the import of the time library and the smbus library. The time library comes with Python and does not need to be installed by yourself. You can install the smbus library by entering the following command in the terminal.
xxxxxxxxxxpip3 install smbus
Python smbus library functions are used to access serial I2C devices. Smbus library functions can be used to read and write I2C device information.
2. Adafruit_SSD1306 library
Since OLED display also requires related dependent libraries, we can install the required dependent libraries at the same time. Enter the following command in the terminal to install the Adafruit_SSD1306 library.
xxxxxxxxxxpip3 install Adafruit_SSD1306 --break-system-packages
The python Adafruit_SSD1306 library is used to control the data display of our OLED display.
Note: If the OLED display tutorial prompts that the PIL library is missing, you can take the following solution.
xxxxxxxxxxsudo apt-get install libjpeg-dev zlib1g-devpip3 install setuptools --break-system-packagespip3 install Pillow --break-system-packages
3. Python driver library file
This course material provides the latest version of the CubeRaspberry Python driver library, named CubeRaspberryLib_V1.0.2

4. Transfer files to the motherboard system
The following is a brief introduction to several methods of transferring files. You can choose the method you are familiar with for specific operations.
- VNC remote login to transfer files
- WinSCP to transfer files
- Online file transfer: such as WeChat file transfer assistant web version, etc.
Choose one of the methods to transfer the CubeRaspberryLib_V1.0.2.zip file to the motherboard system.
5. Driver library installation
Open the terminal in the folder directory where the compressed package is located and enter the following command:
The purpose of this command is to decompress and enter the setup.py directory to run the installation command. You don’t have to worry about whether the version number is consistent.
xxxxxxxxxxunzip CubeRaspberryLib_V1.0.2.zipcd CubeRaspberryLibsudo python3 setup.py install

If you see the installation version number at the end, it means the installation is successful. This command will overwrite the previously installed CubeRaspberryLib driver library.
You can also use the following command to confirm whether the library is installed successfully
xxxxxxxxxxpip3 list | grep "Cu*"
The installation is successful, as shown in the figure

6. Import library file
The name of the CubeRaspberry driver library is CubeRaspberryLib. Use CubeRaspberryLib to import the library in the program.
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberry # Import CubeRaspberry driver library
VII. Check the firmware version number
1. Check the version number
(Python interactive interface: each statement needs to be run separately)
Enter python in the terminal to enter the interactive interface
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberry # Import CubeRaspberry driver librarybot = CubeRaspberry(i2c_bus=1) # Create an object, where 1 represents /dev/i2c-1version = bot.get_Version() # Get the version numberprint("version:",version) # Print the version numberdel bot # Delete the object

2. bot = CubeRaspberry(i2c_bus=1)
Using the smbus library function, we need to create an object, where the 1 in i2c_bus=1 represents i2c - 1. The I2C device we are currently using is mounted on this device bus.
We can query the bus and address of the specific device through the following steps.
Query the I2C bus
xxxxxxxxxxi2cdetect -l
All the lists displayed by the system need to be queried. We need to find the bus where the two devices are mounted.
Query I2C devices
xxxxxxxxxxi2cdetect -y -r 1
Find the device bus with I2C address 0e and 3c. This bus is the device bus object we need to create.

8. API Introduction
The following is an introduction to the API of the CubeRaspberry driver library. The function usage and parameter content will be introduced in the control course later.
xHelp on CubeRaspberry in module CubeRaspberryLib.CubeRaspberryLib object:class CubeRaspberry(builtins.object)| # V1.0.1|| Methods defined here:|| __del__(self)|| __init__(self, i2c_bus=7, delay=0.002, debug=False)| Initialize self. See help(type(self)) for accurate signature.|| get_Version(self)| # 获取固件版本号| # Obtain the firmware version number|| set_Fan(self, state)| # 控制风扇 start=0 关闭风扇 start=1 打开风扇| # control Fan start=0 close start=1 open|| set_RGB_Color(self, color)| # 设置RGB灯特效颜色 0-6:| # 0红色,1绿色,2蓝色,3黄色,4紫色,5青色,6白色| # Set RGB light effect color 0-6:| # 0 red, 1 green, 2 blue, 3 yellow, 4 purple, 5 cyan, 6 white|| set_RGB_Effect(self, effect)| # 控制RGB灯特效: 0关闭特效,1呼吸灯,2跑马灯,3彩虹灯,4炫彩灯,5流水灯,6循环呼吸灯| # Control RGB light effect:| # 0 off effect, 1 breathing light, 2 marquee light,3 rainbow light| # 4 dazzling lights, 5 running water lights,6 Circulation breathing lights|| set_RGB_Speed(self, speed)| # 设置RGB灯特效速度 1-3:1低速,2中速,3高速| # Set RGB light effect speed 1-3:1 low speed, 2 medium speed, 3 high speed|| set_Single_Color(self, index, r, g, b)| # 设置单个RGB灯颜色| # Set the individual RGB light color| # index表示灯珠序号0-13,index=255表示控制所有灯;| # r代表红色,g代表绿色,b代表蓝色| # index indicates the serial number of the lamp bead 0-13, index=255 means to control all lamps;| # r stands for red, g stands for green, and b stands for blue|| ----------------------------------------------------------------------| Data descriptors defined here:|| __dict__| dictionary for instance variables (if defined)|| __weakref__| list of weak references to the object (if defined)(END)