07-25-2016, 06:47 AM
(This post was last modified: 09-02-2016, 11:30 PM by MarkHaysHarris777.)
The fan above is a 5v brushless 140ma fan (free standing on rubber fan mounts) capable of moving 5cfpm ; being driven by a python software PWM motor speed control driver using a PN2222 transistor to handle the current. The GPIO pin signals the transistor via 1k ohm resistor. The codes rely on the RPi.GPIO-PineA64 module from github.
I will be uploading the python codes near the bottom of this post.
The following two pics are close-in shots of the fan, and the transistor current driver:
The PN2222 transistor above can also be replaced by the 2N2222; although, the emitter collector pins are swapped-- the emitter goes to ground.
The fans ship from Jin LI , and as such take three to six weeks to ship to the U.S. Its the shipping, not Jin LI's fault. These little fans move a lot of air; however, they are also noisy. The speed control circuit quiets the fans considerably to a slight whisper, still moves the air more efficiently, and may be controlled off, or controlled by signal based on SoC temperature.
fan_motor.sh
Code:
#!/usr/bin/python
#
# fan_motor.sh
#*****************************************************************
# author: Mark H. Harris
# license: GPLv3
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MECHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENCIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#*****************************************************************
## Import the necessary header modules
from time import sleep
import signal as SIGNAL
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
## SOFTWARE PWM GPIO23 pin(16)
soft_pwm = 23
GPIO.setup(soft_pwm, GPIO.OUT)
ms_on = .016
ms_off = .004
hup_flag = False
## FUNCTION DEFINITIONS
def motor_duty_on(m_pin, t_delay):
GPIO.output(m_pin, True)
sleep(t_delay)
def motor_duty_off(m_pin, t_delay):
GPIO.output(m_pin, False)
sleep(t_delay)
def end():
GPIO.cleanup()
quit()
def ssighup(signum, frame):
global hup_flag
global ms_on
global ms_off
if (hup_flag):
ms_on = .016
hup_flag=False
else:
ms_on = .250
hup_flag=True
print(" ")
print("HUP: duty_cycle toggled value: "+str(ms_on))
SIGNAL.signal(SIGNAL.SIGHUP, ssighup)
kb_interrupt = False
while(not kb_interrupt):
try:
motor_duty_on(soft_pwm, ms_on)
motor_duty_off(soft_pwm, ms_off)
except KeyboardInterrupt:
kb_interrupt = True
print(" ")
print("motor controller ended by interrupt, bye!")
end()
The code may be signaled with a -SIGHUP which when received by the speed controller code will toggle the duty cycle of the soft PWM. from 80% to 100%. A second HUP will toggle the duty cycle back to 80%, or slow speed.
There will be a follow-on post with some more pics, as well a simple schematic.
edit: I changed the default soft-pwm pin to GPIO23, pin(16).
marcushh777