[Jan 06] Arch Linux (20171225-1) PINE A64(+) Pinebook A64-LTS/SOPINE | [Jan 04] Linux (0.5.15-136) ROCK64 | [Jan 04] Android (20171204) ROCK64 | [Dec 22] Stretch Mate (0.5.15-136-20171222) ROCK64 | [Dec 21] openHAB 2 (v1.4) PINE A64(+) | [Dec 11] Volumio (2.315) PINE A64(+) A64-LTS/SOPINE | [Dec 11] Armbian (5.35) PINE A64(+) Pinebook A64-LTS/SOPINE | [Dec 8] OpenMediaVault (0.5.15-136) ROCK64

Getting Started | Visit the WIKI | IRC Logs | Forum Rules/Policy


Brushless Fan (5v) for Rock64 Clear Case Soft PWM Drive 2N2222
#1
Information 
See full update on post #2 below:


         


I plan to mount this 5v brushless fan under the clear Rock64 shipping case using very tiny machine screws set directly into the soft plastic ( for a little later ).  The motor leads ( red +5v,  black grnd ) are plugged into the PI-2 bus voltage pins with a 2N2222 transistor in the power lead ( collector emitter ) and with the base lead plugged into the GPIO2_C2 (82) via biasing resistor.  

The theory is that a driver script ( fan_motor.sh ) will generate a soft-pwm signal to the base of the driver transistor allowing current to flow from collector to emitter;  with greatly reduced current, heat, and noise.  I have wrapped the 2N2222 transistor in an aluminum clip ( heatsink ) to help extend the life of the transistor;  the heatsink gets warm but does it's job quite well.

The simple driver script is listed below, and is also visible in the terminal pics below:

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 pic at the far right-hand is the fan happily spinning away !  The other two pics are views of the control terminal and the commands used to control the 2N2222 transistor bias.  The code sets up a loop that monitors the control pin ( in this case gpio83 ).  gpio83 must be set HIGH to run the loop, which runs in the background.  Momentarily pulling the control pin (83) LOW causes the loop to break and the motor will stop ( the control pin is on parm $2 ).

The control loop turns gpio(82) ON|OFF using parms $3 and $4 with a slow duty cycle in this case of 75% ON, and a frequency of about 6cps;  for a brushless fan this is perfect for keeping the fan running ( very nice airflow ) but with greatly reduced current and far less noise !

The stopled.sh script is simply a three line script that pulls the control pin low for 1.5 seconds and then releases it.  This breaks the control loop effectively stopping the motor. 

Shy
marcushh777    Cool

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! )
Reply
#2
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

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
marcushh777    Cool

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! )
Reply
#3
         


The Rock64-A machine is cased in Dustin's C4Labs acrylic Zebra case ( Emerald ) .  The induction blower assembly is positioned behind the Zebra case, and the plastic insert on the power edge of the Zebra case has been removed.  Cool airflow is forced across the heatsink fins and is exhausted out the top via the gpio(s) port opening.

This is a more efficient system than the Rock64-B enclosure, as you can see by the health report(s). The fan assembly is mounted to a foam block ( very quiet ) which holds the induction blower at just the right height to match the opening.

I have been actively cooling my RPi(s) with this method for some time; its been a good system.
marcushh777    Cool

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! )
Reply
#4
Hello Mr. Mark,

I have a question about your pins..

Quote: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)


Unless I am mistaken and If I am, I apologize about this... but is not the PIN(21) --> GPIO3_A2 (SPI_RXD_M2) ? 
So, which PIN should I use for the GPIO? I am asking this because I am a newbie when it comes to electronics.
Reply
#5
I built it as suggested (although I added a 1000uF capacitor to the output to reduce the clicking noise of the on/off fan).
But checking the temperature I noticed that it is higher with the fan_motor running, because the fan_motor itself uses the CPU, raising the CPU temperature.
In idle, with the fan_motor off, the temperature of the CPU is about 40°-42°. With fan_motor on, the temperature is about 45°-47°.
I have an heat-sink on the CPU.
I have not yet tested it with a CPU load.
Reply
#6
(01-12-2018, 01:08 AM)soichiro Wrote: Hello Mr. Mark,

I have a question about your pins..

Quote: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)


Unless I am mistaken and If I am, I apologize about this... but is not the PIN(21) --> GPIO3_A2 (SPI_RXD_M2) ? 
So, which PIN should I use for the GPIO? I am asking this because I am a newbie when it comes to electronics.
mark was using pin21 on the Pi5 header not the Pi2 header.
Reply
#7
(01-15-2018, 01:59 PM)dkryder Wrote:
(01-12-2018, 01:08 AM)soichiro Wrote: Hello Mr. Mark,

I have a question about your pins..

Quote: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)


Unless I am mistaken and If I am, I apologize about this... but is not the PIN(21) --> GPIO3_A2 (SPI_RXD_M2) ? 
So, which PIN should I use for the GPIO? I am asking this because I am a newbie when it comes to electronics.
mark was using pin21 on the Pi5 header not the Pi2 header.

Ops Tongue
Dummy me ^_^. Thank you for pointing that out dkryder
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Rock64 micro-sd controller defective? soichiro 14 264 01-19-2018, 03:56 AM
Last Post: dkryder
  Rock64 RTL8812AU dongle (from store) how to get working on Android? Nelly 3 98 01-17-2018, 04:12 PM
Last Post: Luke
  pi case conversions for rock64 sandradabo00 4 365 01-11-2018, 01:56 PM
Last Post: jebivetar
  Could you create an Android Laptop out of the Rock64 LongLogStudios 4 220 01-06-2018, 08:59 PM
Last Post: Diogenes08
Tongue Will this wifi dongle work @ rock64? cheungtsw 8 594 01-03-2018, 03:08 AM
Last Post: Osiander
  Looking for advice on power supply for a rack of 4+ Rock64's fwo19 1 145 12-27-2017, 03:18 PM
Last Post: dkryder
Smile wooden case for ROCK64 killor 9 757 12-26-2017, 12:24 PM
Last Post: tllim
  Secondary power input for Rock64 through pi2 Bus nmhart322 6 220 12-18-2017, 01:56 AM
Last Post: Lamensis
  USB 3 2.5" SATA Case thewonderer 2 249 12-13-2017, 06:05 PM
Last Post: thewonderer
  Confused about the Rock64 Acrylic Case KNERD 1 218 12-12-2017, 03:34 PM
Last Post: Luke

Forum Jump:


Users browsing this thread: 1 Guest(s)