I just bought a small fan for the raspberry pi. However I only want it to run after it exceeds a certain temperature.
Is it possible to do this either as a python script or C program. As if so how do I use the GPIO pins on either of these languages?
Re: Automatic Cooling Fan on Pi
You can get cpu temperature with the device virtual filesystem, like this (python) :
then test temperature and trigger your fan (think about hysteresis so the fan does not flicker on/off around the threshold temp)
Code: Select all
try:
tfile = open('/sys/class/thermal/thermal_zone0/temp')
t = tfile.read()
temperature = float(t)/1000
tfile.close()
except:
pass
Re: Automatic Cooling Fan on Pi
If you have never used the gpio with python a good starting point would be the physical computing with python guide on raspberrypi.org
https://projects.raspberrypi.org/en/pro ... -computing
if you just want help with connecting your fan to the gpio there are plenty of examples on the web and on this very forum.
https://www.google.com/search?q=connect ... =firefox-b
https://projects.raspberrypi.org/en/pro ... -computing
if you just want help with connecting your fan to the gpio there are plenty of examples on the web and on this very forum.
https://www.google.com/search?q=connect ... =firefox-b
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported
The use of crystal balls & mind reading are not supported
-
- Raspberry Pi Engineer & Forum Moderator
- Posts: 12848
- Joined: Wed Dec 04, 2013 11:27 am
- Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
Re: Automatic Cooling Fan on Pi
Why not let the kernel do it for you? There's already the required device driver and DT overlay available.
https://github.com/raspberrypi/linux/bl ... EADME#L571
Add:
to /boot/config.txt and gpio 12 should become active when the processor hits 55degC.
Use a standard transistor drive to connect the GPIO to the fan.
https://github.com/raspberrypi/linux/bl ... EADME#L571
Add:
Code: Select all
dtoverlay=gpio-fan,gpiopin=12,temp=55000
Use a standard transistor drive to connect the GPIO to the fan.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.