Skip to content

Instantly share code, notes, and snippets.

@khanh101
Created July 26, 2023 10:10
Show Gist options
  • Save khanh101/177b0d6aa123c8ea15a54df40fb1d693 to your computer and use it in GitHub Desktop.
Save khanh101/177b0d6aa123c8ea15a54df40fb1d693 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<meta name="Generator" content="Drupal 9 (https://www.drupal.org)" />
<meta name="MobileOptimized" content="width" />
<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>var ct_check_js_val = '0481cb40e3eec18991bf4a01f5376955';var drupal_ac_antibot_cookie_value = '0075a04c093efa8f1070e676dc07b8c264c977ef63aad754f882bcddfb4e8c0b';var ct_use_cookies = 0;var ct_capture_buffer = 0;</script>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#333333" />
<link rel="icon" href="/themes/jeffgeerling/favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="canonical" href="https://www.jeffgeerling.com/blog/2021/controlling-pwm-fans-raspberry-pi-cm4-io-boards-emc2301" />
<link rel="shortlink" href="https://www.jeffgeerling.com/node/3148" />
<title>Controlling PWM fans with the Raspberry Pi CM4 IO Board&#039;s EMC2301 | Jeff Geerling</title>
<link rel="stylesheet" media="all" href="/sites/default/files/css/css_DfIk0kDE_97QqZBJr5TF4iiP6Rt7nG3gWSu-Jh5AKCY.css" />
<link rel="stylesheet" media="all" href="/sites/default/files/css/css_ZBWyM8s3S0pfOm6p8i1d1HLz7OBAH06A009SlDZzYM0.css" />
</head>
<body class="path-node page-node-type-blog-post">
<a href="#main-content" class="visually-hidden focusable skip-link">
Skip to main content
</a>
<div class="dialog-off-canvas-main-canvas" data-off-canvas-main-canvas>
<div class="layout-container">
<header role="banner">
<div class="region region-header">
<div id="block-jeffgeerling-branding" class="block block-system block-system-branding-block">
<div class="block-content">
<div class="site-name">
<strong>
<a href="/" title="Home" rel="home">Jeff Geerling</a>
</strong>
</div>
</div>
</div>
<nav role="navigation" aria-labelledby="block-mainmenu-menu" id="block-mainmenu" class="block block-menu navigation menu--main">
<h2 class="visually-hidden" id="block-mainmenu-menu">Main menu</h2>
<ul class="menu">
<li class="menu-item">
<a href="/blog" data-drupal-link-system-path="blog">Blog</a>
</li>
<li class="menu-item">
<a href="/projects" data-drupal-link-system-path="projects">Projects</a>
</li>
<li class="menu-item">
<a href="/about" data-drupal-link-system-path="node/1">About</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="region region-highlighted">
<div data-drupal-messages-fallback class="hidden"></div>
</div>
<main role="main">
<a id="main-content" tabindex="-1"></a>
<div class="layout-content">
<div class="region region-content">
<div id="block-jeffgeerling-page-title" class="block block-core block-page-title-block">
<div class="block-content">
<h1 class="page-title"><span class="field field--name-title field--type-string field--label-hidden">Controlling PWM fans with the Raspberry Pi CM4 IO Board&#039;s EMC2301</span>
</h1>
</div>
</div>
<div id="block-jeffgeerling-system-main" class="block block-system block-system-main-block">
<div class="block-content">
<article role="article" class="node node--type-blog-post node--promoted node--view-mode-full">
<header>
</header>
<footer class="node__meta">
<article class="profile">
</article>
<div class="node__submitted">
<span class="field field--name-created field--type-created field--label-hidden">November 22, 2021</span>
</div>
</footer>
<div class="node__content">
<div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><img src="/sites/default/files/images/noctua-pwm-fan-120mm-raspberry-pi-cm4-io-board.jpeg" alt="Noctua 120mm PWM fan connected to Raspberry Pi CM4 IO Board" width="700" height="454" class="insert-image"></p>
<p>When I initially <a href="/blog/2020/raspberry-pi-compute-module-4-review">reviewed</a> the Compute Module 4 IO Board, I briefly mentioned there's a 4-pin fan connector. It's connected to the Pi's I2C bus using a little PWM chip, the <a href="https://www.microchip.com/wwwproducts/en/EMC2301">EMC2301</a>.</p>
<p>But wait... what's I2C, what's PWM, and what's so special about a 4-pin fan connector? I'm glad you asked—this post will answer that <em>and</em> show you how you can control a fan connected to the IO Board, like the quiet <a href="https://amzn.to/3xboRGg">Noctua NF-P12</a> pictured above with my IO Board.</p>
<p>If you plug a fan like that into the CM4 IO Board, it will start running full blast, 24x7. If you need that much cooling, that's great, but a lot of times, I don't mind my Pi's CPU getting warmer if it means I can run the fan silent most of the time.</p>
<blockquote>
<p><strong>2022-05 Update</strong>: Recently, a driver for the EMC2301 fan controller was <a href="https://github.com/raspberrypi/linux/pull/5026">merged into Raspberry Pi's Linux fork</a>, so it will appear in the next release of Raspberry Pi OS.</p>
<p>Once that's done, all you'd need to do (if running Pi OS) is add the following line to your <code>/boot/config.txt</code> file:</p>
<pre><code>dtoverlay=i2c-fan,emc2301,i2c_csi_dsi
</code></pre>
<p>See <a href="https://github.com/raspberrypi/linux/issues/4632#issuecomment-1122687644">this comment on GitHub</a> for more details, and how to control PWM speeds and trigger temperatures.</p>
</blockquote>
<p>So what are my options? First of all, I could just buy an inline PWM controller, like a <a href="https://amzn.to/3HGSap3">Noctua NA-FC1</a>. It lets me turn up and down the fan speed with a little dial. But it doesn't know the temperature of my Pi, so it can't increase airflow for higher temperatures or turn off the fan when it's under a certain temperature.</p>
<p><img src="/sites/default/files/images/emc2301-fan-controller-raspberry-pi-io-board.jpeg" alt="EMC2301 Fan controller on Raspberry Pi CM4 IO Board" width="600" height="371" class="insert-image"></p>
<p>The better option is to use the built-in PWM fan controller on the IO Board (pictured above). And to do that, we're going to need to use the Raspberry Pi's I2C bus!</p>
<h2>What is I2C?</h2>
<p>I2C—or more correctly, I<sup>2</sup>C—stands for "Inter-Integrated Circuit" and is a two-wire serial communication interface used by many electronic devices for control and communications.</p>
<p>I'm not going to cover it in detail here, but if you get into any more advanced electronics projects with Arduino, Raspberry Pi, or other microcontrollers or PCs, you'll probably encounter it. To learn the basics of the protocol, I recommend <a href="https://www.analog.com/en/technical-articles/i2c-primer-what-is-i2c-part-1.html">Analog Device's I<sup>2</sup>C Primer</a>.</p>
<h2>Controlling the fan over I<sup>2</sup>C</h2>
<p>You have to edit your <code>/boot/config.txt</code> file to enable the <code>i2c_vc</code> bus, which is bus #1. The <a href="https://www.raspberrypi.org/documentation/configuration/device-tree.md">Pi Device Tree Documentation</a> actually recommends against touching <code>i2c_vc</code> unless you need to, because you could mess up CSI camera or DSI display functionality.</p>
<p>Make sure the following lines exist and are uncommented in <code>/boot/config.txt</code> and reboot the Pi:</p>
<pre><code># Enable I2C.
dtparam=i2c_arm=on
# Enable I2C bus 1.
dtparam=i2c_vc=on
</code></pre>
<blockquote>
<p><strong>Note</strong>: If you just enable I<sup>2</sup>C under the 'Interfaces' option of <code>raspi-config</code>, it will only enable <code>i2c_arm</code>. To see the fan controller, you need to enable <code>i2c_vc</code> as well.</p>
</blockquote>
<p>Make sure the <code>i2c-tools</code> package is installed on your system; if it is, the following commands should work straightaway. If not, you will need to install the package with <code>sudo apt-get install -y i2c-tools</code>.</p>
<p>Now, check if you can see the fan controller chip on the bus, using <code>i2cdetect -y 10</code>:</p>
<pre><code>$ i2cdetect -y 10
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- 0c -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2f
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
</code></pre>
<p>The fan is the <code>2f</code> device. Test if you can turn off the fan using:</p>
<pre><code>$ i2cset -y 10 0x2f 0x30 0x00
</code></pre>
<p>The fan should now be off. And to turn it back on:</p>
<pre><code>$ i2cset -y 10 0x2f 0x30 0xff
</code></pre>
<p>To <em>get</em> the value of the fan setting, you can use:</p>
<pre><code>$ i2cget -y 10 0x2f 0x30
0xff
</code></pre>
<p>What about setting the fan to a value between 0% (off) and 100% (full on) though? The value is hexadecimal, so <code>0xFF</code> stands for <code>255</code>, while <code>0x00</code> is <code>0</code>. Using a high-ish number should be safe, right, to set the fan to a lower speed? Well, let's try it out.</p>
<p>First, set the fan speed to 'off':</p>
<pre><code>$ i2cset -y 10 0x2f 0x30 0x00
</code></pre>
<p>Wait for the fan to spin down entirely, then set the fan to <code>100</code> (or <code>0x64</code> in hex):</p>
<pre><code>$ i2cset -y 10 0x2f 0x30 0x64
</code></pre>
<p>If you do this, you'll notice the fan comes back on, but hopefully at a much more pleasant speed. On one of my Noctua fans, 100/255 equates to about 40% speed, or 1200 rpm, and it's nearly silent.</p>
<p>Now that we can control the fan over I<sup>2</sup>C, we could write up a script to set fan speeds based on CPU temperatures manually, but there are a few other ways to control the fan speeds.</p>
<blockquote>
<p>Note: The 'Fan' performance option inside <code>raspi-config</code> currently has no effect on the operation of a fan through the EMC2301 chip.</p>
</blockquote>
<h2>Can I use Linux <code>lm-sensors</code> and <code>fancontrol</code>?</h2>
<p>Unfortunately, the standard way of controlling fan speeds based on sensor data on most common PC hardware doesn't seem to be supported on the CM4 IO Board's I<sup>2</sup>C chip.</p>
<p>If I install <code>lm-sensors</code> and <code>fancontrol</code> (following <a href="https://askubuntu.com/a/46135">this guide</a>), then I run <code>sudo sensors-detect</code>, I get back the message:</p>
<pre><code>Sorry, no sensors were detected.
Either your system has no sensors, or they are not supported, or
they are connected to an I2C or SMBus adapter that is not
supported. If you find out what chips are on your board, check
https://hwmon.wiki.kernel.org/device_support_status for driver status.
</code></pre>
<p>It did find 'clients' on the I<sup>2</sup>C bus at <code>0x51</code> and <code>0x2f</code>, but it couldn't identify them. And when I ran <code>sudo pwmconfig</code>, I got the message:</p>
<pre><code>/usr/sbin/pwmconfig: There are no pwm-capable sensor modules installed
</code></pre>
<p>So it looks like that's out of the running, unfortunately. There's a <a href="http://lkml.iu.edu/hypermail/linux/kernel/1306.1/02473.html">really old patch</a> for Linux to add the fan controller to the Linux source tree, but for some reason it never got worked on beyond early stages. There's also an issue discussing the <a href="https://github.com/raspberrypi/linux/issues/4632">IO Board fan controller</a> in the Raspberry Pi Linux kernel project, in case you want to subscribe and see the latest updates.</p>
<blockquote>
<p>Dec 2021 update: It looks like there's a <a href="https://lore.kernel.org/all/20200928104326.40386-1-biwen.li@oss.nxp.com/">newer patch here</a> and a new <a href="https://gitlab.traverse.com.au/ls1088firmware/traverse-sensors/-/commit/1cdec49171ebafcf32b347e7701224144de8620b">firmware driver</a> that some folks at Pine64 have been working on.</p>
</blockquote>
<h2>The <code>cm4io-fan</code> driver</h2>
<p>GitHub user <a href="https://github.com/neg2led">neg2led</a> is maintaining an open source CM4 IO Board Fan controller driver, which is the next best thing. This driver is based on Traverse Technologies' EMC2301 hwmon driver.</p>
<p>To install it, I made sure I had I<sup>2</sup>C enabled as written above, and ran the following:</p>
<pre><code># Install the Raspberry Pi kernel headers, so the source build works.
sudo apt install raspberrypi-kernel-headers
# Install DKMS, to make updating the driver easier.
sudo apt install dkms
# Get the URL (tar.gz) of the latest release: https://github.com/neg2led/cm4io-fan/releases
wget https://github.com/neg2led/cm4io-fan/archive/refs/tags/0.1.1.tar.gz
# Expand the contents of the download into your /usr/src directory.
sudo tar -xzvf 0.1.1.tar.gz -C /usr/src/
# Build/install the driver with DKMS.
sudo dkms install cm4io-fan/0.1.1
</code></pre>
<p>At this point, the driver should be installed and will work after a reboot, once you configure it.</p>
<blockquote>
<p><strong>Note</strong>: I've only tested the driver on 64-bit Pi OS, but other users have reported it successfully compiles and works on 32-bit Pi OS as well.</p>
</blockquote>
<h3>Configuring the driver</h3>
<p>Configuration can be done in the <code>/boot/config.txt</code> file. Add a line like the following:</p>
<pre><code># Control fan speeds.
dtoverlay=cm4io-fan,minrpm=1000,maxrpm=3000
</code></pre>
<p>This would set the fan to stay on at least at 1000 rpm at all times, and it would go up to 3000 rpm once the Pi's SoC reaches the <code>maxtemp</code>, which by default is <code>5500</code> in millicelcius (55°C).</p>
<p>You can override other options such as temperature thresholds using <a href="https://github.com/neg2led/cm4io-fan#config-options">the driver's config options</a>.</p>
<p>You can also check the current fan speed with the following command:</p>
<pre><code>$ cat /sys/class/hwmon/hwmon2/fan1_input
2146
</code></pre>
<h3>Driver problems</h3>
<p>The driver seems to work better on some CM4 boards than others, and may also have issues with certain PWM fans. One of the issues I encountered seems to be related to a potential bug in the reference design on the official IO Board.</p>
<p>If you encounter issues, check if the problem you hit is already documented in the <a href="https://github.com/neg2led/cm4io-fan/issues">cm4io-fan issue queue</a>.</p>
<h2>Basic Temperature-controlled fan script</h2>
<p>As a final option you could write your own <a href="https://gist.github.com/geerlingguy/9c9c78463c0e3d9f4a23152912930821">temperature-controlled fan script</a>, which checks the current temperature, and boosts the fan speed accordingly. It's nowhere near as fully featured as the driver above, but it could work in a pinch:</p>
<script src="https://gist.github.com/geerlingguy/9c9c78463c0e3d9f4a23152912930821.js"></script>
<h2>Conclusion</h2>
<p>There are a few different ways to interact with the EMC2301 fan controller on the Raspberry Pi Compute Module 4 IO Board (and a few other <a href="https://pipci.jeffgeerling.com/boards_cm">CM4 boards</a> I've tested, like the <a href="https://pipci.jeffgeerling.com/boards_cm">Seaberry</a>), but the cm4io-fan driver seems the most promising.</p>
<p>Hopefully you've learned a little about I<sup>2</sup>C in this post, too—I know I've learned a bit more about it, how PWM fans work, and even why tuning things like fan curves are important!</p></div>
<div class="region region-node-bottom">
<div class="views-element-container block block-views block-views-blockrelated-content-block-1" id="block-related-content--2">
<h2>Further reading</h2>
<div class="block-content">
<div><div class="view view-related-content view-id-related_content view-display-id-block_1 js-view-dom-id-b7b2803698d340bb80d7d5869b1d3a3f7e89d21d76699b7e35c7897a4284c087">
<div class="view-content">
<div class="item-list">
<ul>
<li><div class="views-field views-field-title"><span class="field-content"><a href="/blog/2021/mirkopc-full-featured-raspberry-pi-desktop-computer" hreflang="en">MirkoPC - a full-featured Raspberry Pi desktop computer</a></span></div></li>
<li><div class="views-field views-field-title"><span class="field-content"><a href="/blog/2020/overclocking-raspberry-pi-compute-module-4" hreflang="en">Overclocking the Raspberry Pi Compute Module 4</a></span></div></li>
<li><div class="views-field views-field-title"><span class="field-content"><a href="/blog/2022/gaming-1080p-and-120-hz-on-raspberry-pi-4" hreflang="en">Gaming at 1080p and 120 Hz on a Raspberry Pi 4</a></span></div></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="field field--name-field-tags field--type-entity-reference field--label-hidden field__items">
<div class="field__item"><a href="/tags/raspberry-pi" hreflang="en">raspberry pi</a></div>
<div class="field__item"><a href="/tags/compute-module" hreflang="en">compute module</a></div>
<div class="field__item"><a href="/tags/cm4" hreflang="en">cm4</a></div>
<div class="field__item"><a href="/tags/io-board" hreflang="en">io board</a></div>
<div class="field__item"><a href="/tags/script" hreflang="en">script</a></div>
<div class="field__item"><a href="/tags/fan" hreflang="en">fan</a></div>
<div class="field__item"><a href="/tags/pwm" hreflang="en">pwm</a></div>
<div class="field__item"><a href="/tags/i2c" hreflang="en">i2c</a></div>
<div class="field__item"><a href="/tags/linux" hreflang="en">linux</a></div>
</div>
<div class="node__links">
<ul class="links inline"><li class="comment-add"><a href="/comment/reply/node/3148/comment_node_blog_post#comment-form" title="Share your thoughts and opinions.">Add new comment</a></li></ul> </div>
</div>
<div id="comments">
<section class="field field--name-comment-node-blog-post field--type-comment field--label-above comment-wrapper">
<h2 class="title">Comments</h2>
<article data-comment-user-id="0" id="comment-18044" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1637605571"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Charlie</span> – <a href="/comment/18044#comment-18044">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>I can confirm that the cm4io-fan driver builds and works great under 32-bit Pi OS.</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18044">Reply</a></li></ul>
</div>
</article>
<div class="indented">
<article data-comment-user-id="1" id="comment-18045" class="comment js-comment by-node-author">
<mark class="hidden" data-comment-timestamp="1637605579"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Jeff Geerling</span> – <a href="/comment/18045#comment-18045">1 year ago</a></p>
<p class="parent visually-hidden">In reply to <a href="/comment/18044#comment-18044" class="permalink" rel="bookmark" hreflang="en">I can confirm that the cm4io…</a> by <span>Charlie</span></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>That's awesome, thanks for confirming!</p></div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18045">Reply</a></li></ul>
</div>
</article>
</div>
<article data-comment-user-id="0" id="comment-18080" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1638215035"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Dan Pastusek</span> – <a href="/comment/18080#comment-18080">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>A bit of a tangent, but for the PiBox, we ended up skipping the EMC2301 and let the Pi provide the PWM signal directly (primarily because it was out of stock, but it also saves ~$1 on component cost)</p>
<p>The Pi has two hardware PWM channels (usually used for audio, L + R channels), and if you are ok giving up one of those, then you can drive a fan directly! Someone smarter than me figured this out and wrote the drivers for it on GitHub: <a href="https://gist.github.com/alwynallan/1c13096c4cd675f38405702e89e0c536#gistcomment-3555494">https://gist.github.com/alwynallan/1c13096c4cd675f38405702e89e0c536#gis…</a>. So after trying that, we hardwired a PWM channel to a fan header on our PCBs, and it works perfectly!</p>
<p>Also.. your latest video prompted me to donate a chunk to Peter (the author of that driver). The open source donation campaign is a fantastic idea :)</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18080">Reply</a></li></ul>
</div>
</article>
<div class="indented">
<article data-comment-user-id="1" id="comment-18081" class="comment js-comment by-node-author">
<mark class="hidden" data-comment-timestamp="1638215080"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Jeff Geerling</span> – <a href="/comment/18081#comment-18081">1 year ago</a></p>
<p class="parent visually-hidden">In reply to <a href="/comment/18080#comment-18080" class="permalink" rel="bookmark" hreflang="en">A bit of a tangent, but for…</a> by <span>Dan Pastusek</span></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><blockquote>
<p>Your latest video prompted me to donate a chunk to Peter</p>
</blockquote>
<p>That's awesome! And nice use of a feature that probably 99% of the users of the PiBox wouldn't ever even think about anyways!</p></div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18081">Reply</a></li></ul>
</div>
</article>
</div>
<article data-comment-user-id="1" id="comment-18248" class="comment js-comment by-node-author">
<mark class="hidden" data-comment-timestamp="1641323138"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Jeff Geerling</span> – <a href="/comment/18248#comment-18248">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>I also recently found out about <a href="https://github.com/dans98/cm4-pwm-fan">cm4-pwm-fan</a>, a Python script to control the PWM fan on the CM4. Looks like a nice simple utility that's in some ways easier to comprehend if you're more used to Python, and less C. But I'm not sure how much more or less CPU the Python script running in the background would take.</p></div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18248">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-18612" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1644939994"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Greg</span> – <a href="/comment/18612#comment-18612">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>I gave the cm4io-fan driver a try. It worked well for me for about a day or so but I just found it running at full speed again. Checked fan1_input and it was not at full rpm's, it was sitting around 2600. Gave the pi a reboot and it is back to running at a more quiet speed now. Guess I'll see how it goes again.</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18612">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-18721" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1646767350"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Sebastian</span> – <a href="/comment/18721#comment-18721">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>im on raspberry pi os 64 bit and it does not work for me is there a workaround ?</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/18721">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-30684" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1647787699"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Andrew</span> – <a href="/comment/30684#comment-30684">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>5500 in millicelcius (55°C)</p>
<p>Should be 55,000 millicelsius. 😉</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/30684">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-30779" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1649693798"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Derek Tattersall</span> – <a href="/comment/30779#comment-30779">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>I wrote a script, based on yours, to read the fan RPM.</p>
<pre><code>#!/bin/bash
# Equation taken from section 4.4 of the EMC2301 datasheet
# Explicitly set $PATH so i2c tools are found.
PATH=$PATH:/usr/sbin
A=$(($(($(printf '%d\n' "$((16#$(i2cget -y 10 0x2f 0x32 | sed -e 's/0x//g')))") &amp; 96)) &gt;&gt; 5))
M=$(echo "2^$A" | bc -l)
CH=$(printf '%d\n' "$((16#$(i2cget -y 10 0x2f 0x3e | sed -e 's/0x//g')))")
CL=$(printf '%d\n' "$((16#$(i2cget -y 10 0x2f 0x3f | sed -e 's/0x//g')))")
#echo $CH $CL
COUNT=$(echo "32*$CH+ $CL" | bc -l)
echo "COUNT= $COUNT, M = $M"
MULT=3932160
RPM=$(echo "$MULT*$M/$COUNT" | bc -l)
#echo $RPM' RPM'
RPMR=$(printf %.0f $(echo $RPM))
echo $RPMR' RPM'
</code></pre></div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/30779">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-30938" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1655232053"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Beo</span> – <a href="/comment/30938#comment-30938">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Awesome guide, thank you very much!<br />
I think it works very well for me, but for some reason the controller (i guess) makes a very high pitched and relatively loud noise, epecially, when the fan is spinning with low rpm.<br />
The fan itself is really quite.</p>
<p>Do you have any idea why that's the case, and if there's something i can do about it? Maybe not using the EMC2301, since it seems to be the problem?</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/30938">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-30952" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1655490471"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>ZeroOne</span> – <a href="/comment/30952#comment-30952">1 year ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Sadly does not work for me.<br />
I am running a cm4 on a Waveshare IO-BASE-B which should be able to run with cm4io-fan.</p>
<p>I believe that the problem lies in the i2c bus, as i only have i2c-1,20 and 21 but no 10.</p>
<p>Running the latest 64bit version.</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/30952">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-31103" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1660016531"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Asrfghik</span> – <a href="/comment/31103#comment-31103">11 months ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Does anyone know how to do control the fan in retropie specifically?</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/31103">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-31119" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1660406240"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Bruno</span> – <a href="/comment/31119#comment-31119">11 months ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Sorry for that question, but I'm not able to get a script getting executed at boot. (for testing I just made a script containing the following line:<br />
i2cset -y 10 0x2f 0x30 0x00<br />
so the fan should turn off at (re)boot. But it doesn't!</p>
<p>I already tried calling the script via crontab and /etc/init.d but none of these worked.</p>
<p>Ho can I get it to work?</p>
<p>Sorry again for that question, but I'm quite new to scripting on linux...</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/31119">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-31523" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1670296802"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Benjamin De Worsop</span> – <a href="/comment/31523#comment-31523">7 months ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>This was an awesome post thank you!</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/31523">Reply</a></li></ul>
</div>
</article>
<article data-comment-user-id="0" id="comment-31744" class="comment js-comment by-anonymous">
<mark class="hidden" data-comment-timestamp="1675479365"></mark>
<footer class="comment__meta">
<p class="comment__submitted"><span>Cory</span> – <a href="/comment/31744#comment-31744">5 months ago</a></p>
</footer>
<div class="content">
<div class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Hi Jeff. Thanx so much for this post. I has kept me posted on the progress on a feature I very much wanted. :)</p>
<p>See this post: <a href="https://forums.raspberrypi.com/viewtopic.php?t=337918#p2023930">https://forums.raspberrypi.com/viewtopic.php?t=337918#p2023930</a></p>
<p>That "dtparam" 3rd line option seems to be working for me. (fan stopped spinning at full speed) Sorry if I missed this in your post. I actually cant find official pi documentation if this is even there.</p>
</div>
<ul class="links inline"><li class="comment-reply"><a href="/comment/reply/node/3148/comment_node_blog_post/31744">Reply</a></li></ul>
</div>
</article>
</section>
</div>
</article>
</div>
</div>
</div>
</div>
</main>
<footer role="contentinfo">
<div class="region region-footer">
<div class="views-exposed-form block block-views block-views-exposed-filter-blocksearch-page" data-drupal-selector="views-exposed-form-search-page" id="block-exposedformsearchpage-2">
<div class="block-content">
<form action="/search" method="get" id="views-exposed-form-search-page" accept-charset="UTF-8">
<div class="form--inline clearfix">
<div class="js-form-item form-item js-form-type-textfield form-type-textfield js-form-item-search-api-fulltext form-item-search-api-fulltext">
<label for="edit-search-api-fulltext">Search</label>
<input data-drupal-selector="edit-search-api-fulltext" type="text" id="edit-search-api-fulltext" name="search_api_fulltext" value="" size="30" maxlength="128" placeholder="Enter your keywords" class="form-text" />
</div>
<div data-drupal-selector="edit-actions" class="form-actions js-form-wrapper form-wrapper" id="edit-actions"><input data-drupal-selector="edit-submit-search" type="submit" id="edit-submit-search" value="Search" class="button js-form-submit form-submit" />
</div>
</div>
</form>
</div>
</div>
<div id="block-footer" class="block block-block-content block-block-contentfd0023d1-3c23-4c7e-ae29-6b5e37e79690">
<div class="block-content">
<div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><style>
<!--/*--><![CDATA[/* ><!--*/
@media screen and (max-width: 600px) {
.family-crest {
width: 55px;
height: auto;
}
}
/*--><!]]>*/
</style><p><img src="/sites/default/files/files/geerling-family-crest.svg" height="65" width="55" alt="Geerling Family Crest" class="family-crest" /><br />
All content copyright Jeff Geerling. <a href="#top">Top of page</a>.</p>
</div>
</div>
</div>
<div id="block-fathomanalytics" class="block block-block-content block-block-content3c3ff7d8-a12f-483e-ab7f-bad9398d97ba">
<div class="block-content">
<div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
<script>
(function(f, a, t, h, o, m){
a[h]=a[h]||function(){
(a[h].q=a[h].q||[]).push(arguments)
};
o=f.createElement('script'),
m=f.getElementsByTagName('script')[0];
o.async=1; o.src=t; o.id='fathom-script';
m.parentNode.insertBefore(o,m)
})(document, window, '//analytics.midwesternmac.com/tracker.js', 'fathom');
fathom('set', 'siteId', 'UROTN');
fathom('trackPageview');
</script>
<!-- / Fathom --></div>
</div>
</div>
</div>
</footer>
</div>
</div>
<script type="application/json" data-drupal-selector="drupal-settings-json">{"path":{"baseUrl":"\/","scriptPath":null,"pathPrefix":"","currentPath":"node\/3148","currentPathIsAdmin":false,"isFront":false,"currentLanguage":"en"},"pluralDelimiter":"\u0003","suppressDeprecationErrors":true,"ajaxTrustedUrl":{"\/search":true},"user":{"uid":0,"permissionsHash":"41d4391498f4f97d37ce21e62b1457ca566b2b56d6cebe00b7abbdf99cac7d0f"}}</script>
<script src="/sites/default/files/js/js_dLpzvpwWiaMGkL1SsQsyvbHecMN5arIrYstYhg2Y3sk.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment