Is there a way to control a pi fan to turn on when my raspberry pi hits a certain temperature instead of being always on?
I understand that this question has been asked a lot, and there are guides out there involving soldering pythons and coding transistors, but the folks over at raspberry pi have released an official case fan (Nov' 2020) that can be temperature controlled by Raspbian, and simply requires setting a few preferences in the performance tab of the GUI. Link to product and how to set it up:
This fan comes with a built in 3rd cable that connects to a GPIO pin where raspbian OS can ask which GPIO pin (default 14), and tell it when to turn on and off at a set temperature (default 80C). Perfect. The wrinkle is that this is controlled through the Raspbian OS GUI, and I don't have a GUI set up for Octopi, much less know whether octopi even has the functionality to control the GPIO pin.
Now I'm a complete noob at this, being my first 3D printer, first Pi, never coded, can't speak parceltongue (python), nor understanding the development history of Octopi or Octoprint; so my questions are extended to the below:
As Raspbian OS has the functionality to temperature control the pi's cooling fan (at least from Nov 2020) does Octopi have this functionality?
If yes to Q1, can it be set without a GUI? and how would I go about doing this?
If no to Q1, is there another way that I can make this thing run? Will I need to install the full Raspbian OS, and then install octoprint over the top of that just to turn a fan on and off? I understand this is also a big undertaking.
If the above works, then I've seen people discuss using SystemCommandEditor in Octoprint for camera on/off (though I've not tried it yet). Is this something that could be used to control the pi fan (on / off / temp controlled) if the sudo commands exist?
I'm running the following:
Octoprint Version 1.5.2
Octopi Version 0.17.0
Raspberry Pi 4 Model B Rev 1.2
OctoPi should be able to do it, though it depends - the current 0.17 image is from November 2019 and the 0.18rc1 is from August 2020, so you might have to get 0.18 and then upgrade it.
Once you have done that, they say there is now an option in 'raspi-config' to enable the fan on GPIO 14 or you can configure it yourself.
Apparently you can do this yourself without updating (not sure about 0.17, might be too long ago) by adding the following to the config.txt file:
dtoverlay=gpio-fan,gpiopin=14,temp=80000
I'm hoping you're able to tell what each of those items represents
Steps I've done:
I've taken the SD card out of the Pi, put it into my Windows 10 machine. Opened Config.txt in Notepad++, and there is no line for a fan in it (as I am still on 0.17.0).
I have now added the above line that you have mentioned, and will test it in the Pi at temp=80000 (80C). I will then modify it to be at temp =10000 (10C) and see what happens. If this works I'll be super happy!
If the above doesn't work, then I will update to 0.18 and see if the line is available there.
Out of interest, how do I go about upgrading? I haven't been able to find any instructions for an upgrade, only a full replace.
To upgrade, you can backup your settings in OctoPrint, and then flash the new image, then restore the backup. Or, you could manually update the packages using sudo apt update and sudo apt upgrade, I think. Not sure if a firmware upgrade would be needed in between. Probably not.
In the config.txt for Octopi 0.17.0 there is no line as you have mentioned. I added this line in with a threshold of temp=80000 (80C) and the fan is on when the Pi is first turned on, and then shut itself off after about 5 seconds (temp was reading about 40C)
I then set the threshold of temp=20000 (20C). The fan was on when the Pi first turned on, and then it stayed on during use. So it worked!
I have now set the fan to come on at 60C, though I understand this will usually be at 80C for most people as this is when CPU throttling starts.
This line may already be included in the config.txt in the newer 0.18 release, I haven't checked.
Excellent! this has actually inspired me to dig out my old Pi fan, I didn't know it was a built in option until I saw your post. Then promptly went googling in the right places about that official fan addon...
I'm new to this Octoprint and Rpi things and I wonder when you add this line " dtoverlay=gpio-fan,gpiopin=14,temp=80000" then this means that it works by the gpiopin14.
Does this mean that I just need to connect my fan to the pin 14 and the ground or does it needs something else to work?
For now my fan is connected to the 5V and ground so this would mean that i just need to place in 1 position further on the gpio (and switch the contacts). Or do I miss something here?
The reason it works for my pi fan is that it comes with a 3 wires. One for 5V, one for Neutral, and one for the GPIO pin. It won’t work for a normal 2 wire fan as the gpio pin doesn’t give power.
I guess it should be possible with some python program but i wonder what exactly does that command "dtoverlay=gpio-fan,gpiopin=14,temp=80000" does.
Is that just: open/close the GPIO-pin 14 when the temperature reaches 80°?
So nothing else, just open/close that GPIO-pin without providing some kind of power?
But what means the "dtoverlay=gpio-fan" then?
It's a external fan that is connected (or will be connected) so how does octoprint knows that this is my fan?
its' prob a stupid question but I do not understand
dtoverlay=gpio-fan activates a small script in the Raspberry Pi OS software, that monitors the temperature and activates the fan. GPIO pins don't usually have enough current to drive a fan, you can usually damage them with anything but a tiny, likely ineffective fan. It's activating something within the OS, you are right the same could probably be achieved with a custom script - though that won't increase the amount of power supplied.
I bought the official pi case fan to try to cool the CPU. Now when I hooked up 5V and the ground the fan already started to spin. Blue (GPIO) was not connected yet! Even when blue was connected it did nothing and the fan kept spinning. Does anyone have a clue on what could be wrong?
I added the code like this tho the config.txt on the boot of the SD card.
The fan will kick in when you put just the black and red pins in, as it isn’t switched until you put the blue pin in.
It might be that at 60000 temp your machine may be running hotter than that. Try raising the temp limit to 90000 and see if it turns off (I only set 60C as my garage is frequently below 10C, and the Pi regularly ran 50C above ambient temp when encased).
So the results are in! Turns out that the GPIO 14 pin just didn't work on my pi. I tried the higher temp thing but it didn't work. Then I switched to pin 12 and this did work. So my problem is solved. I don't know how but if you have the same issue's maybe try pin 12.
Also, I set my temp limit to 75 this seems a good limit