08-31-2017, 02:40 AM
(This post was last modified: 08-31-2017, 03:00 AM by MarkHaysHarris777.)
Greetings,
In this photo blog I'm going to put it all together ( this Rock64 cased fan design has been a while in the design and organizing phases! ).
All of the scripts are included in this post to actually make the software pwm 5v brushless fan function. I have included updated schematic|block-diagram and have included instructions (tutorial style) for reproducing the experiments.
Theory
The concept is simple; a script activates a gpio mux line ( cyclic ON|OFF ) which in turn drives the base of an NPN driver transistor; the driver transistor handles the current for the 5v brushless fan -- turning the fan motor ON|OFF many times each minute with a duty-cycle which reduces the fan's current draw, and reduces the fan's noise, while still providing good air flow. In addition, the script can be more complicated ( should you desire ) to speed or slow the fan motor based on the thermal condition in the sysfs !
Preparation and Electronics ( schematic | block-diagram )
The schematic|block-diagram above is a rework of my schematic from the PineA64+ forum of the same topic. The concept is precisely the same; the only differences are the language ( bash script vs python ) and the details of which pin controls the duty cycle and which pin(s) control the process. ie., in this example the process is controlled via gpio pin, not signaling via the OS.
You may use either a PN2222, or a 2N2222 transistor. Notice the transistor is placed in the black lead ( negative ) of the motor assembly ( pay attention to the emitter | collector designations on your transistor datasheet! ).
Don't forget the base biasing ( current limiting ) 1K ohm resistor; a common mistake.
The pics above detail the finished prototype; the only difference here between the prototype and the completed project is that the completed project will have internal wiring ( including the transistor heatsink, cable, and biasing resistor ).
There are several things to notice in the pic top left; my fan projects ( active SBC cooling ) all use heatsinks on the driver transistor. This keeps the cost low, while still improving the life of the transistor. Commercial ones are available, but I made this one from inexpensive brushed aluminum from a jewelry hobby store.
Notice the hole in the top cover over the SoC heatsink. The inductor blower fan evacuates the case hundreds of times per minute, and the entry point for that airflow is directly over the heatsink fins. To accomplish this the other openings in the case need to be minimized ( note the temporary gpio cover , taped index card with hole punches ).
The fan is mounted on the bottom of the case which is not only more aesthetic (IMHO) but its also quieter when placed there ( from experience! ). The finished project will deviate from this prototype by adding a foam-slit cover for the gpio(s) and by adding a lite surgical gauze filter for the airflow entry point; this also helps to keep the board and the fan blades clean and quiet.
Please note the green loop of wire on the gpio PI-2 bus; this wire runs from gpio89 to gpio83, and is used to signal the fan_motor.sh control loop when to break. gpio89 is held high; when gpio89 pulls gpio83 low, the control loop breaks and the fan_motor.sh script exits ( of course the fan motor then stops spinning ).
The induction blower fan is seen in this pic (above) mounted on the bottom case of the Rock64 clear shipping case. Again, the final will have internal wiring. The fan blades are quite powerful even at lower soft-pwm speeds. The induction blower assembly evacuates the case air exhausting it out across the bottom under the case ( virtually silently ).
This required a considerable amount of dremel work ( don't forget eye protection and filter mask while breathing ).
I mounted the blower assembly with two small machine screws ( M2 ) cut to proper length with a dremel cutter wheel. The holes in the bottom case are just a tiny bit smaller than 2mm, so that the threads of the M2 metric screws bite into the plastic housing without any other hardware ( like washers, nuts, etc ).
It took four weeks to get these Gdt fans from Shenzhen, so order early !
Wrap-up , Health Monitor, and Scripts (codes)
The pic above shows the prototype ( lower right foreground ); note the fan assembly position -- it is important to have the mounting 'feet' (M3 stilts) long enough that the fan assembly clears the table top; otherwise, the noise from the fan will be transmitted to the table ( not good ). The final project will have little rubber footies on the M3 bolt tops which will further reduce what little noisy vibration might be left over.
On the Samsung display ( background ) you will notice some Rock64_health.sh readouts. My idle temps with this setup ( 1200 Mhz ) are in the mid 30 ℃ , and even loaded most times the temps are in the high 30 ℃ to low 40 ℃.
Below I'm listing the three scripts that I use to control this fan motor. PIN-setup.sh is used to export and setup all of my gpio(s) to user space. This script is generic and does the setup for ALL of my projects. In other words, I only setup pins once after I log on; each subsequent script ( including fan_motor.sh ) relies on the PIN-setup.sh. Also, the stopfan.sh script MUST be run BEFORE running the fan_motor.sh script. stopfan.sh pulls gpio30 low and then releases it-- setting gpio89 HIGH. gpio89 MUST be HIGH or the fan_motor.sh script will not run more than one cycle! Finally , fan_motor.sh is where the software pwm magic happens.
Note: a jumper wire MUST run from gpio89 to gpio83 ! Failure to do this will cause loss of control over your fan motor.
Here are the scripts, followed by usage :
PIN-setup.sh
Don't forget to make the script executable with : chmod 0754 PIN-setup.sh
Run the PIN-setup.sh script as root:
sudo -i
PIN-setup.sh
stopfan.sh
Run the above script with :
sudo stopfan.sh
Its important that this script is run AFTER the PIN-setup.sh, and BEFORE the fan_motor.sh ! gpio89 must be held HIGH or the fan_motor.sh script will not start !
fan_motor.sh
The script fan_motor.sh is generic in the sense that all of its critical values are passed in as parameters. It basically sets up a controlled forever loop that activates the soft pwm gpio line ON|OFF until the control pin is pulled low-- stopfan.sh does that job.
Run fan_motor.sh as root in the background with :
sudo -i
fan_motor.sh 82 83 .088 .022 &
Just a quick note about the pins:
gpio82 is Pi P5+ bus GPIO2_C2 pin(4)
gpio83 is Pi P5+ bus GPIO2_C3 pin(6)
gpio89 is Pi P5+ bus GPIO2_D1 pin(21)
The fan motor and transistor assembly plugs into the PI-2 bus pin(4 +5v) and pin(6 gnd).
In this photo blog I'm going to put it all together ( this Rock64 cased fan design has been a while in the design and organizing phases! ).
All of the scripts are included in this post to actually make the software pwm 5v brushless fan function. I have included updated schematic|block-diagram and have included instructions (tutorial style) for reproducing the experiments.
Theory
The concept is simple; a script activates a gpio mux line ( cyclic ON|OFF ) which in turn drives the base of an NPN driver transistor; the driver transistor handles the current for the 5v brushless fan -- turning the fan motor ON|OFF many times each minute with a duty-cycle which reduces the fan's current draw, and reduces the fan's noise, while still providing good air flow. In addition, the script can be more complicated ( should you desire ) to speed or slow the fan motor based on the thermal condition in the sysfs !
Preparation and Electronics ( schematic | block-diagram )
The schematic|block-diagram above is a rework of my schematic from the PineA64+ forum of the same topic. The concept is precisely the same; the only differences are the language ( bash script vs python ) and the details of which pin controls the duty cycle and which pin(s) control the process. ie., in this example the process is controlled via gpio pin, not signaling via the OS.
You may use either a PN2222, or a 2N2222 transistor. Notice the transistor is placed in the black lead ( negative ) of the motor assembly ( pay attention to the emitter | collector designations on your transistor datasheet! ).
Don't forget the base biasing ( current limiting ) 1K ohm resistor; a common mistake.
The pics above detail the finished prototype; the only difference here between the prototype and the completed project is that the completed project will have internal wiring ( including the transistor heatsink, cable, and biasing resistor ).
There are several things to notice in the pic top left; my fan projects ( active SBC cooling ) all use heatsinks on the driver transistor. This keeps the cost low, while still improving the life of the transistor. Commercial ones are available, but I made this one from inexpensive brushed aluminum from a jewelry hobby store.
Notice the hole in the top cover over the SoC heatsink. The inductor blower fan evacuates the case hundreds of times per minute, and the entry point for that airflow is directly over the heatsink fins. To accomplish this the other openings in the case need to be minimized ( note the temporary gpio cover , taped index card with hole punches ).
The fan is mounted on the bottom of the case which is not only more aesthetic (IMHO) but its also quieter when placed there ( from experience! ). The finished project will deviate from this prototype by adding a foam-slit cover for the gpio(s) and by adding a lite surgical gauze filter for the airflow entry point; this also helps to keep the board and the fan blades clean and quiet.
Please note the green loop of wire on the gpio PI-2 bus; this wire runs from gpio89 to gpio83, and is used to signal the fan_motor.sh control loop when to break. gpio89 is held high; when gpio89 pulls gpio83 low, the control loop breaks and the fan_motor.sh script exits ( of course the fan motor then stops spinning ).
The induction blower fan is seen in this pic (above) mounted on the bottom case of the Rock64 clear shipping case. Again, the final will have internal wiring. The fan blades are quite powerful even at lower soft-pwm speeds. The induction blower assembly evacuates the case air exhausting it out across the bottom under the case ( virtually silently ).
This required a considerable amount of dremel work ( don't forget eye protection and filter mask while breathing ).
I mounted the blower assembly with two small machine screws ( M2 ) cut to proper length with a dremel cutter wheel. The holes in the bottom case are just a tiny bit smaller than 2mm, so that the threads of the M2 metric screws bite into the plastic housing without any other hardware ( like washers, nuts, etc ).
It took four weeks to get these Gdt fans from Shenzhen, so order early !
Wrap-up , Health Monitor, and Scripts (codes)
The pic above shows the prototype ( lower right foreground ); note the fan assembly position -- it is important to have the mounting 'feet' (M3 stilts) long enough that the fan assembly clears the table top; otherwise, the noise from the fan will be transmitted to the table ( not good ). The final project will have little rubber footies on the M3 bolt tops which will further reduce what little noisy vibration might be left over.
On the Samsung display ( background ) you will notice some Rock64_health.sh readouts. My idle temps with this setup ( 1200 Mhz ) are in the mid 30 ℃ , and even loaded most times the temps are in the high 30 ℃ to low 40 ℃.
Below I'm listing the three scripts that I use to control this fan motor. PIN-setup.sh is used to export and setup all of my gpio(s) to user space. This script is generic and does the setup for ALL of my projects. In other words, I only setup pins once after I log on; each subsequent script ( including fan_motor.sh ) relies on the PIN-setup.sh. Also, the stopfan.sh script MUST be run BEFORE running the fan_motor.sh script. stopfan.sh pulls gpio30 low and then releases it-- setting gpio89 HIGH. gpio89 MUST be HIGH or the fan_motor.sh script will not run more than one cycle! Finally , fan_motor.sh is where the software pwm magic happens.
Note: a jumper wire MUST run from gpio89 to gpio83 ! Failure to do this will cause loss of control over your fan motor.
Here are the scripts, followed by usage :
PIN-setup.sh
Code:
#!/bin/sh
echo 83 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio83/direction
echo 82 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio82/direction
echo 100 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio100/direction
echo 101 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio101/direction
echo 102 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio102/direction
echo 103 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio103/direction
echo 88 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio88/direction
echo 89 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio89/direction
Don't forget to make the script executable with : chmod 0754 PIN-setup.sh
Run the PIN-setup.sh script as root:
sudo -i
PIN-setup.sh
stopfan.sh
Code:
#!/bin/sh
echo 0 > /sys/class/gpio/gpio89/value
sleep 1.25
echo 1 > /sys/class/gpio/gpio89/value
Run the above script with :
sudo stopfan.sh
Its important that this script is run AFTER the PIN-setup.sh, and BEFORE the fan_motor.sh ! gpio89 must be held HIGH or the fan_motor.sh script will not start !
fan_motor.sh
Code:
#!/bin/sh
# sudo ./fan_motor.sh pwm_pin# ctrl_pin# time_ON time_OFF &
while [ `cat /sys/class/gpio/gpio$2/value` -gt 0 ]; do
echo 1 > /sys/class/gpio/gpio$1/value
sleep $3
echo 0 > /sys/class/gpio/gpio$1/value
sleep $4
done
echo 0 > /sys/class/gpio/gpio$1/value
The script fan_motor.sh is generic in the sense that all of its critical values are passed in as parameters. It basically sets up a controlled forever loop that activates the soft pwm gpio line ON|OFF until the control pin is pulled low-- stopfan.sh does that job.
Run fan_motor.sh as root in the background with :
sudo -i
fan_motor.sh 82 83 .088 .022 &
Just a quick note about the pins:
gpio82 is Pi P5+ bus GPIO2_C2 pin(4)
gpio83 is Pi P5+ bus GPIO2_C3 pin(6)
gpio89 is Pi P5+ bus GPIO2_D1 pin(21)
The fan motor and transistor assembly plugs into the PI-2 bus pin(4 +5v) and pin(6 gnd).
![Shy Shy](https://forum.pine64.org/images/smilies/shy.png)
marcushh777
please join us for a chat @ irc.pine64.xyz:6667 or ssl irc.pine64.xyz:6697
( I regret that I am not able to respond to personal messages; let's meet on irc! )
![Cool Cool](https://forum.pine64.org/images/smilies/cool.png)
please join us for a chat @ irc.pine64.xyz:6667 or ssl irc.pine64.xyz:6697
( I regret that I am not able to respond to personal messages; let's meet on irc! )