sudo vim.tiny /boot/config.txt
add:
dtoverlay=dwc2, dr_mode=host
save it and reboot Raspberry Pi.
-
- At First, get the demo code from github.
cd ~
git clone https://github.com/DeskPi-Team/deskpi.git
cd ~/deskpi/drivers/c/
-
- How to compile it.
make
-
- How to run it.
sudo ./pwmFanControl
-
- How to stop it. Press "Ctrl + C"
-
- How to clean the source code directory.
make clean
This program is send the pwm signal from Raspberry Pi to the extension board via OTG serial port, which will be recognized by your Raspberry Pi as "/dev/ttyUSB0" device. so if you want to control the fan as your wish, you can modify pwmControlFan.c code and recompile it.
- In the default code, we have set 4 level for you Fan on pwm signal:
- Level 0: 0% speed-> send "pwm_000" to /dev/ttyUSB0", means to turn off the fan
- Level 1: 25% speed-> send "pwm_025" to /dev/ttyUSB0", means to set fan speed to 25%
- Level 2: 50% speed-> send "pwm_050" to /dev/ttyUSB0", means to set fan speed to 50%
- Level 3: 75% speed-> send "pwm_075" to /dev/ttyUSB0", means to set fan speed to 75%
- Level 4:100% speed-> send "pwm_100" to /dev/ttyUSB0", means to set fan speed to 100%
You can also control your fan with python script. just remember to send "pwm_xxx" to "/dev/ttyUSB0" device. xxx means the level of your fan speed. from 0-100 (integer).
- Python2.x
pip install pyserial
- Python3.x
pip3 install pyserial
cd ~
git clone https://github.com/DeskPi-Team/deskpi.git
cd ~/deskpi/drivers/python/
sudo python3 pwmControlFan.py