NESpi GPIO controlled FAN

Want to show off your own project? Want to keep a build log of it? Post it here!
Post Reply
User avatar
woans
Posts: 15
Joined: Fri Aug 18, 2017 4:52 pm
Been thanked: 9 times

NESpi GPIO controlled FAN

Post by woans » Sun Aug 27, 2017 1:05 pm

Hi !

I would like to share a mini project I made with a Raspberry Pi 3 : a NESpi. Cool and simple project, however, the temp are reaching really high values easily with the emulators... Had to make the air flow a little bit, but I don't want to be noisy all the time.

Image

So, I orderered a 5V 25mm fan, got a SMD transistor freshly desoldered from another random device and I resolder wires to allow a GPIO pin to drive (simple ON/OFF drive) the FAN.

Image

Then I designed a simple support using the remaining GPIO pins, 3D printed it and voilà !

Image

The model I created can be downloaded here :
printable-3d-models.zip
(488.55 KiB) Downloaded 244 times
The version I printed is an alpha version :) had to manually cut it to make it fit. Please note that I'm also using pure copper mini heatsinks.

Image

Image

Image

The code I used to make it work is inspired from this webpage, but I had to make some small mods.

I used GPIO 21 instead of 18 and chanded the way the strings are represented :

Code: Select all

#!/usr/bin/env python3
# Author: Edoardo Paolo Scalafiotti <edoardo849@gmail.com>
import os
from time import sleep
import signal
import sys
import RPi.GPIO as GPIO
pin = 21 # The pin ID, edit here to change it
maxTMP = 40 # The maximum temperature in Celsius after which we trigger the fan
def setup():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.OUT)
    GPIO.setwarnings(False)
    return()
def getCPUtemperature():
    res = os.popen('vcgencmd measure_temp').readline()
    temp =(res.replace("temp=","").replace("'C\n",""))
    #print("temp is {0}".format(temp)) #Uncomment here for testing
    return temp
def fanON():
    setPin(True)
    return()
def fanOFF():
    setPin(False)
    return()
def getTEMP():
    CPU_temp = float(getCPUtemperature())
    if CPU_temp>maxTMP:
        fanON()
    else:
        fanOFF()
    return()
def setPin(mode): # A little redundant function but useful if you want to add logging
    GPIO.output(pin, mode)
    return()
try:
    setup() 
    while True:
        getTEMP()
    sleep(5) # Read the temperature every 5 sec, increase or decrease this limit if you want
except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt 
    GPIO.cleanup() # resets all GPIO ports used by this program
And for the startup script, the original tutorial is missing the chmod +x command and some other tweaks.

Enjoy !

User avatar
DoggieWokkie
Posts: 27
Joined: Thu Sep 29, 2016 9:41 am
Has thanked: 38 times
Been thanked: 4 times

Re: NESpi GPIO controlled FAN

Post by DoggieWokkie » Fri Nov 10, 2017 5:17 pm

Thank you for this, it was exactly what I needed!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest