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.
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.
Then I designed a simple support using the remaining GPIO pins, 3D printed it and voilà !
The model I created can be downloaded here : 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.
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
Enjoy !