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
I was finally able to work on this Fan's project and I was wondering if someone could tell me if I connected everything in the right way since I have no experience whatsoever in electronics.

https://drive.google.com/open?id=0B3iAYb...JOMmdwYTJF

https://drive.google.com/open?id=0B3iAYb...Y5UmpSWFd3

https://drive.google.com/open?id=0B3iAYb...hRSlRRbWVv

https://drive.google.com/open?id=0B3iAYb...JvQTlhU1Rj

Now my question is... Where do I connect the green cable that is supposed to go to GPIO (Software pwm)? I am thinking to connect it to the gpio89 Pi P5+ bus GPIO2_D1 pin(21) but is already occupied by a jumper wire cable that goes from gpio89 to gpio83.

I am lost to be honest Sad
  Reply
#8
(10-28-2018, 08:37 PM)soichiro Wrote: I was finally able to work on this Fan's project and I was wondering if someone could tell me if I connected everything in the right way since I have no experience whatsoever in electronics.

https://drive.google.com/open?id=0B3iAYb...JOMmdwYTJF

https://drive.google.com/open?id=0B3iAYb...Y5UmpSWFd3

https://drive.google.com/open?id=0B3iAYb...hRSlRRbWVv

https://drive.google.com/open?id=0B3iAYb...JvQTlhU1Rj

Now my question is... Where do I connect the green cable that is supposed to go to GPIO (Software pwm)? I am thinking to connect it to the gpio89 Pi P5+ bus  GPIO2_D1  pin(21) but is already occupied by a jumper wire cable that goes from gpio89 to gpio83.

I am lost to be honest Sad

Hi Soichiro,

Did you manage to get your fan working?
Since I bought my rock64 2 years ago I haven't invested in proper cooling and struggle regularly to keep heat below 60 celsius.
I would appreciate if you could share you latest setup and hw you used?

thanks
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are HW design files available for ROCK64? irenek 3 6,185 12-11-2023, 09:31 PM
Last Post: tllim
  Rock64 is unreliable after 3 years of service - power problem? ReleaseTheGeese 0 607 11-23-2023, 05:05 AM
Last Post: ReleaseTheGeese
  Rock64 PoE compatbility with Pi4 Hatt recent Single Board Computer offering from PINE kharak 1 1,492 04-26-2023, 11:38 PM
Last Post: tllim
  Case for the rock64 that supports the POE hat. o1CRiMSON1o 0 862 03-21-2023, 03:48 PM
Last Post: o1CRiMSON1o
Brick Rock64 usb2.0 Power Control Floating GPIO Tutorial Files & Notes MarkHaysHarris777 6 14,500 01-15-2023, 10:36 AM
Last Post: ds00
  rock64 totally brick dakobg 2 2,309 11-07-2022, 05:45 PM
Last Post: olivercfc
  3D-Printable Button Pegs for the ROCK64 Aluminium Case CounterPillow 2 4,057 08-04-2022, 01:31 AM
Last Post: Vicky Weimann PhD
  Where can I find the ROCK64 POE HAT Zoz 2 3,324 06-08-2022, 12:44 AM
Last Post: Zoz
Smile wooden case for ROCK64 killor 13 18,397 03-04-2022, 06:56 AM
Last Post: killor
  1wire DS18b20 on Rock64? mypineme 6 8,209 09-28-2021, 03:07 PM
Last Post: TRS-80

Forum Jump:


Users browsing this thread: 1 Guest(s)