Welcome to CUBE Pi Case repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
Fan drive
Fan drive
Fan drive1. Learning objectives2. Preparation before the experiment3. Use the CubeRaspberry driver library to control the fan1. Import the CubeRaspberry driver library and create an object2. Set the fan switch3. Code demonstration4. Using Jupyter lab control fan1. Import CubeRaspberry driver library and create objects2. Turn off the fan3. Turn on the fan4. Delete the object5. Experimental Phenomenon
1. Learning objectives
- Master the Raspberry Pi fan driver
- Use the CubeRaspberry driver library to control the fan
- Control the fan through Jupyter lab
2. Preparation before the experiment
Install the Raspberry Pi chassis according to the assembly video tutorial. You can also refer to the "Raspberry Pi chassis_hardware wiring" tutorial document for installation. Here, the chassis expansion board and RGB light strip and fan hardware connections are shown.

| Chassis expansion board | 3Pin interface | 2Pin interface |
|---|---|---|
| RGB light strip | Fan |
3. Use the CubeRaspberry driver library to control the fan
1. Import the CubeRaspberry driver library and create an object
The name of the CubeRaspberry driver library is CubeRaspberryLib. Use CubeRaspberryLib to import the library in the program.
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberry
CubeRaspberryLib library functions needed to control the fan:
xxxxxxxxxxset_Fan(state) # Set the fan switch
2. Set the fan switch
| set_Fan(state) :Set the fan switch | | :---------------------------: |
| state value | Fan state |
|---|---|
| 0 | Off |
| 1 | On |
3. Code demonstration
- Turn on/off the fan (python interactive interface: each statement needs to be run separately)
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberrybot = CubeRaspberry(i2c_bus=1)bot.set_Fan(0)bot.set_Fan(1)del botexit()

xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberryif __name__ == '__main__':bot = CubeRaspberry(i2c_bus=1)bot.set_Fan(1)
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberryif __name__ == '__main__':bot = CubeRaspberry(i2c_bus=1)bot.set_Fan(0)

Note: Press Ctrl + C to terminate the run
4. Using Jupyter lab control fan
Create a new file in the Jupyter lab interface and create the following code blocks, edit the following contents respectively (Fan_Test.ipynb):
1. Import CubeRaspberry driver library and create objects
xxxxxxxxxxfrom CubeRaspberryLib import CubeRaspberrybot = CubeRaspberry(i2c_bus=1)
2. Turn off the fan
xxxxxxxxxxbot.set_Fan(0)
3. Turn on the fan
xxxxxxxxxxbot.set_Fan(1)
4. Delete the object
xxxxxxxxxxdel bot

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

5. Experimental Phenomenon
- Run the code or file related to opening the fan:
You can see that the fan in the chassis turns on the blue light and rotates

- Run the code or file related to closing the fan:
You can see that the blue light of the fan in the chassis turns off and stops rotating
