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
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.
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.
xxxxxxxxxx
pip3 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.
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.
xxxxxxxxxx
pip3 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.
xxxxxxxxxx
sudo apt-get install libjpeg-dev zlib1g-dev
pip3 install setuptools --break-system-packages
pip3 install Pillow --break-system-packages
This course material provides the latest version of the CubeRaspberry Python driver library, named CubeRaspberryLib_V1.0.2
The following is a brief introduction to several methods of transferring files. You can choose the method you are familiar with for specific operations.
Choose one of the methods to transfer the CubeRaspberryLib_V1.0.2.zip file to the motherboard system.
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.
xxxxxxxxxx
unzip CubeRaspberryLib_V1.0.2.zip
cd CubeRaspberryLib
sudo 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
xxxxxxxxxx
pip3 list | grep "Cu*"
The installation is successful, as shown in the figure
The name of the CubeRaspberry driver library is CubeRaspberryLib. Use CubeRaspberryLib to import the library in the program.
xxxxxxxxxx
from CubeRaspberryLib import CubeRaspberry # Import CubeRaspberry driver library
(Python interactive interface: each statement needs to be run separately)
Enter python in the terminal to enter the interactive interface
xxxxxxxxxx
from CubeRaspberryLib import CubeRaspberry # Import CubeRaspberry driver library
bot = CubeRaspberry(i2c_bus=1) # Create an object, where 1 represents /dev/i2c-1
version = bot.get_Version() # Get the version number
print("version:",version) # Print the version number
del bot # Delete the object
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
xxxxxxxxxx
i2cdetect -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
xxxxxxxxxx
i2cdetect -y -r 1
Find the device bus with I2C address 0e and 3c. This bus is the device bus object we need to create.
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)