{"id":2764,"date":"2025-07-16T15:07:33","date_gmt":"2025-07-16T14:07:33","guid":{"rendered":"https:\/\/theroamingworkshop.cloud\/b\/?p=2764"},"modified":"2025-07-16T15:36:53","modified_gmt":"2025-07-16T14:36:53","slug":"raspberry-pi-5-fan-setup-in-ubuntu-and-status-indicator","status":"publish","type":"post","link":"https:\/\/theroamingworkshop.cloud\/b\/en\/2764\/raspberry-pi-5-fan-setup-in-ubuntu-and-status-indicator\/","title":{"rendered":"Raspberry Pi 5 fan setup in Ubuntu and status indicator"},"content":{"rendered":"\n<p>The heat arrived once again and I was feeling that my Raspberry Pi was too warm considering that it has the official built-in fan, with temperatures easily rising above 60\u00baC.<\/p>\n\n\n\n<p>Since I installed <strong>Ubuntu<\/strong> on it, the fan didn&#8217;t seem to work right, but that&#8217;s something that has been solved in the recent versions of the kernel.<\/p>\n\n\n\n<p>So here&#8217;s how you can set it up in <strong>Ubuntu<\/strong> and display it&#8217;s status.<\/p>\n\n\n\n<div id=\"menu\" style=\"padding:20px 20px 20px 20px; border-left:2px solid darkgrey;\">\n<p style=\"font-weight:bold;\">Content<\/p>\n<\/div>\n<script>\nvar text;\nvar element;\n\nfunction fillmenu(){\n\nfor (let i=0; i<window.document.getElementsByTagName(\"h2\").length; i++){\nelement = window.document.getElementsByTagName(\"h2\")[i];\ntext = \"\u25b9 \"+element.innerHTML;\nvar newelement = document.createElement(\"a\");\nnewelement.innerHTML=text;\nvar postid=window.document.getElementsByTagName(\"article\")[0].id;\nvar url = \"https:\/\/theroamingworkshop.cloud\/b\/?p=\"+postid.substr(5,postid.length)+\"#\"+element.id;\nnewelement.setAttribute(\"href\", url);\nnewelement.appendChild(document.createElement(\"br\"));\nwindow.document.getElementById(\"menu\").appendChild(newelement);\nconsole.log(text);\n}\n}\nif(window.location.href.includes(\"tag\")){\n\n}else{\nwindow.setTimeout(fillmenu,2000);\n}\n\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Fan check<\/h2>\n\n\n\n<p>First of all let's check that our fan is working correctly by managing it manually.<\/p>\n\n\n\n<p><strong>Update your system<\/strong> so you can get the latest fixes that affect the fan. My latest version is <strong>Ubuntu Linux 24.04.2<\/strong>.<\/p>\n\n\n\n<p>Now you should be able to turn on the fan manually by typing the following command in the terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 4 | sudo tee \/sys\/class\/thermal\/cooling_device0\/cur_state<\/code><\/pre>\n\n\n\n<p>A value of <kbd>4<\/kbd> will turn on the fan in it's maximum revolutions. You can change this value from 0 to 4.<\/p>\n\n\n\n<p>If the above worked correctly you will hear significant noise from your fan. Now you can turn it off again by echoing a value of 0:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 0 | sudo tee \/sys\/class\/thermal\/cooling_device0\/cur_state<\/code><\/pre>\n\n\n\n<p>So you see that altering the value in the <kbd>cur_sate<\/kbd> file manually changes the fan speed. That's exactly what the fan daemon does once it's configured, so we will monitor this value later to find out if our fan is working (returned value != 0):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/sys\/class\/thermal\/cooling_device0\/cur_state<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fan setup<\/h2>\n\n\n\n<p>The fan wasn't preconfigured in the earlier versions of the Ubuntu kernel for the Raspberry Pi. I'm not sure if it is now by default, but just check it by editing the <kbd><strong>config.txt<\/strong><\/kbd> file located in <kbd><strong>\/boot\/firmware<\/strong><\/kbd> and find out some lines similar to the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dtparam=fan_temp0=58000\ndtparam=fan_temp0_hyst=10000\ndtparam=fan_temp0_speed=200<\/code><\/pre>\n\n\n\n<p>If you cannot find them, just add them at the end of the file.<\/p>\n\n\n\n<p>You may also adjust these values freely, considering:<\/p>\n\n\n\n<p><kbd>fan_temp0=58000<\/kbd> indicates the trigger temperature that will turn on the fan<\/p>\n\n\n\n<p><kbd>fan_temp0_hyst<\/kbd> means the temperature reduction that turns off the fun (10000 below 58000 = 48000)<\/p>\n\n\n\n<p><kbd>fan_temp0_speed<\/kbd> indicates the fan speed, from 0 to 255<\/p>\n\n\n\n<p>So that's our fan setup to run at 200rpm if the temperature is above 58\u00baC and turn off if it reduces 10\u00baC (~48\u00baC).<\/p>\n\n\n\n<p>Now apply these changes by <strong>rebooting the system<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fan monitoring<\/h2>\n\n\n\n<p>I was already monitoring a series of variables from my Raspberry Pi 5 using an OLED screen, as it's explained in this other post:<\/p>\n\n\n\n<p><a href=\"https:\/\/theroamingworkshop.cloud\/b\/en\/2655\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/theroamingworkshop.cloud\/b\/en\/2655\/case-oled-display-for-raspberry-pi-with-status-panel\/<\/a><\/p>\n\n\n\n<p>Let's now add an indicator with the status of the fan!<\/p>\n\n\n\n<p>I've included a couple of lines to the python script to retreive the fan status executing the command that we saw above:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Fan ON\/OFF\ncmd = \"cat \/sys\/class\/thermal\/cooling_device0\/cur_state\"\nFan = subprocess.check_output(cmd, shell=True).decode(\"utf-8\")<\/code><\/pre>\n\n\n\n<p>Somewhere below I am reading a .png file for the fan:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fan_img=Image.open(\"~\/Documents\/OLED\/fan-icon.png\")\nfan_img = fan_img.resize((30, 30), Image.BICUBIC)<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"50\" src=\"https:\/\/theroamingworkshop.cloud\/b\/wp-content\/uploads\/2025\/07\/fan-icon.png\" alt=\"\" class=\"wp-image-2771\" style=\"width:108px;height:auto\"\/><figcaption class=\"wp-element-caption\">fan-icon.png<\/figcaption><\/figure>\n<\/div>\n\n\n<p>And right at the display stage, I would show it if the value of Fan is different to cero (fan is ON):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if int(Fan)!=0:\n    bg.paste(fan_img,(90,55))<\/code><\/pre>\n\n\n\n<p>All these changes have been updated in the Github repository for my previous display script:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/TheRoam\/RaspberryPi-SSD1351-OLED\">https:\/\/github.com\/TheRoam\/RaspberryPi-SSD1351-OLED<\/a><\/p>\n\n\n\n<p>So that's a very nice looking fan indicator for your display!<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a5cbea8b98ef&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a5cbea8b98ef\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"288\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"2790\" src=\"https:\/\/theroamingworkshop.cloud\/b\/wp-content\/uploads\/2025\/07\/FANon-1.gif\" alt=\"\" class=\"wp-image-2790\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Agrandar\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a5cbea8b9d7f&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a5cbea8b9d7f\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"288\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"2791\" src=\"https:\/\/theroamingworkshop.cloud\/b\/wp-content\/uploads\/2025\/07\/FANoff-1.gif\" alt=\"\" class=\"wp-image-2791\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Agrandar\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/figure>\n\n\n\n<p>See you next time!\ud83d\udc4b<\/p>\n\n\n\n<p>\ud83d\udc26 <code><a rel=\"noreferrer noopener\" href=\"https:\/\/twitter.com\/roamingworkshop\" target=\"_blank\">@RoamingWorkshop<\/a><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The heat arrived once again and I was feeling that my Raspberry Pi was too warm considering that it has the official built-in fan, with temperatures easily rising above 60\u00baC. Since I installed Ubuntu on it, the fan didn&#8217;t seem to work right, but that&#8217;s something that has been solved in the recent versions of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2791,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68,14],"tags":[801,803,403,401,863,809,811,813,695,815,817,819,463],"class_list":["post-2764","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electronics","category-raspi-en","tag-adafruit-en","tag-display-en","tag-electronica","tag-electronics","tag-fan","tag-pcb-en","tag-pi-5-en","tag-pi5-en","tag-python","tag-raspberry-en","tag-raspberry-pi-en","tag-raspberry-pi-5-en","tag-ubuntu","post-preview"],"_links":{"self":[{"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/posts\/2764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/comments?post=2764"}],"version-history":[{"count":30,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/posts\/2764\/revisions"}],"predecessor-version":[{"id":2808,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/posts\/2764\/revisions\/2808"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/media\/2791"}],"wp:attachment":[{"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/media?parent=2764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/categories?post=2764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroamingworkshop.cloud\/b\/wp-json\/wp\/v2\/tags?post=2764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}