Skip to content

Latest commit

 

History

History

drivers

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Control Your Fan througn PWM signal via Serial port(OTG)

Configure /boot/config.txt to enbale otg function.

sudo vim.tiny /boot/config.txt 

add:

dtoverlay=dwc2, dr_mode=host

save it and reboot Raspberry Pi.

C Language

    1. At First, get the demo code from github.
cd ~
git clone https://github.com/DeskPi-Team/deskpi.git
cd ~/deskpi/drivers/c/
    1. How to compile it.
make 
    1. How to run it.
sudo ./pwmFanControl
    1. How to stop it. Press "Ctrl + C"
    1. How to clean the source code directory.
make clean

How to change speed of the fan.

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%

Python

How to control fan through PWM signal via serial port.

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).

1. Install pyserial library.

  • Python2.x
pip install pyserial 
  • Python3.x
pip3 install pyserial

2. Get the demo code from github and execute it.

cd ~
git clone https://github.com/DeskPi-Team/deskpi.git
cd ~/deskpi/drivers/python/
sudo python3 pwmControlFan.py

Job Done.