Controlling PWM followers with the Raspberry Pi CM4 IO Board’s EMC2301

Controlling PWM followers with the Raspberry Pi CM4 IO Board’s EMC2301

Once I initially reviewed the Compute Module 4 IO Board, I briefly talked about there is a 4-pin fan connector. It is linked to the Pi's I2C bus utilizing just a little PWM chip, the EMC2301.

However wait... what's I2C, what's PWM, and what's so particular a couple of 4-pin fan connector? I am glad you requested—this submit will reply that and present you how one can management a fan linked to the IO Board, just like the quiet Noctua NF-P12 pictured above with my IO Board.

In the event you plug a fan like that into the CM4 IO Board, it can begin operating full blast, 24x7. In the event you want that a lot cooling, that is nice, however numerous instances, I do not thoughts my Pi's CPU getting hotter if it means I can run the fan silent more often than not.

So what are my choices? To start with, I might simply purchase an inline PWM controller, like a Noctua NA-FC1. It lets me flip up and down the fan velocity with just a little dial. But it surely would not know the temperature of my Pi, so it may't improve airflow for larger temperatures or flip off the fan when it is beneath a sure temperature.

EMC2301 Fan controller on Raspberry Pi CM4 IO Board

The higher possibility is to make use of the built-in PWM fan controller on the IO Board (pictured above). And to try this, we'll want to make use of the Raspberry Pi's I2C bus!

What's I2C?

I2C—or extra appropriately, I2C—stands for "Inter-Built-in Circuit" and is a two-wire serial communication interface utilized by many digital units for management and communications.

I am not going to cowl it intimately right here, however should you get into any extra superior electronics initiatives with Arduino, Raspberry Pi, or different microcontrollers or PCs, you will most likely encounter it. To be taught the fundamentals of the protocol, I like to recommend Analog Device's I2C Primer.

Controlling the fan over I2C

It's a must to edit your /boot/config.txt file to allow the i2c_vc bus, which is bus #1. The Pi Device Tree Documentation truly recommends in opposition to touching i2c_vc until you'll want to, since you might mess up CSI digicam or DSI show performance.

Be sure that the next traces exist and are uncommented in /boot/config.txt and reboot the Pi:

# Allow I2C.
dtparam=i2c_arm=on
# Allow I2C bus 1.
dtparam=i2c_vc=on

Observe: In the event you simply allow I2C beneath the 'Interfaces' possibility of raspi-config, it can solely allow i2c_arm. To see the fan controller, you'll want to allow i2c_vc as effectively.

Be sure that the i2c-tools bundle is put in in your system; whether it is, the next instructions ought to work straightaway. If not, you have to to put in the bundle with sudo apt-get set up -y i2c-tools.

Now, test should you can see the fan controller chip on the bus, utilizing i2cdetect -y 10:

$ 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: -- -- -- -- -- -- -- --

The fan is the 2f gadget. Take a look at should you can flip off the fan utilizing:

$ i2cset -y 10 0x2f 0x30 0x00

The fan ought to now be off. And to show it again on:

$ i2cset -y 10 0x2f 0x30 0xff

To get the worth of the fan setting, you need to use:

$ i2cget -y 10 0x2f 0x30
0xff

What about setting the fan to a worth between 0% (off) and 100% (full on) although? The worth is hexadecimal, so 0xFF stands for 255, whereas 0x00 is 0. Utilizing a high-ish quantity needs to be secure, proper, to set the fan to a decrease velocity? Effectively, let's strive it out.

First, set the fan velocity to 'off':

$ i2cset -y 10 0x2f 0x30 0x00

Watch for the fan to spin down fully, then set the fan to 100 (or 0x64 in hex):

$ i2cset -y 10 0x2f 0x30 0x64

In the event you do that, you will discover the fan comes again on, however hopefully at a way more nice velocity. On one in every of my Noctua followers, 100/255 equates to about 40% velocity, or 1200 rpm, and it is practically silent.

Now that we will management the fan over I2C, we might write up a script to set fan speeds based mostly on CPU temperatures manually, however there are a couple of different methods to regulate the fan speeds.

Observe: The 'Fan' efficiency possibility inside raspi-config presently has no impact on the operation of a fan by the EMC2301 chip.

Can I exploit Linux lm-sensors and fancontrol?

Sadly, the usual approach of controlling fan speeds based mostly on sensor information on commonest PC {hardware} would not appear to be supported on the CM4 IO Board's I2C chip.

If I set up lm-sensors and fancontrol (following this guide), then I run sudo sensors-detect, I get again the message:

Sorry, no sensors have been detected.
Both your system has no sensors, or they don't seem to be supported, or
they're linked to an I2C or SMBus adapter that isn't
supported. In the event you discover out what chips are in your board, test
https://hwmon.wiki.kernel.org/device_support_status for driver standing.

It did discover 'shoppers' on the I2C bus at 0x51 and 0x2f, however it could not establish them. And once I ran sudo pwmconfig, I acquired the message:

/usr/sbin/pwmconfig: There aren't any pwm-capable sensor modules put in

So it appears like that is out of the operating, sadly. There is a really old patch for Linux so as to add the fan controller to the Linux supply tree, however for some cause it by no means acquired labored on past early phases. There's additionally a difficulty discussing the IO Board fan controller within the Raspberry Pi Linux kernel challenge, in case you need to subscribe and see the most recent updates.

The cm4io-fan driver

GitHub person neg2led is sustaining an open supply CM4 IO Board Fan controller driver, which is the subsequent neatest thing. This driver relies on Traverse Applied sciences' EMC2301 hwmon driver.

To put in it, I made certain I had I2C enabled as written above, and ran the next:

# Set up the Raspberry Pi kernel headers, so the supply construct works.
sudo apt set up raspberrypi-kernel-headers

# Set up DKMS, to make updating the driving force simpler.
sudo apt set up dkms

# Get the URL (tar.gz) of the most recent launch: https://github.com/neg2led/cm4io-fan/releases
wget https://github.com/neg2led/cm4io-fan/archive/refs/tags/0.1.1.tar.gz

# Broaden the contents of the obtain into your /usr/src listing.
sudo tar -xzvf 0.1.1.tar.gz -C /usr/src/

# Construct/set up the driving force with DKMS.
sudo dkms set up cm4io-fan/0.1.1

At this level, the driving force needs to be put in and can work after a reboot, when you configure it.

Observe: This driver has been examined and works on 64-bit Pi OS, however I do not know if anybody's examined it on 32-bit Pi OS but. Let me know if you will get it working there!

Configuring the driving force

Configuration may be finished within the /boot/config.txt file. Add a line like the next:

# Management fan speeds.
dtoverlay=cm4io-fan,minrpm=1000,maxrpm=3000

This is able to set the fan to remain on not less than at 1000 rpm always, and it could go as much as 3000 rpm as soon as the Pi's SoC reaches the maxtemp, which by default is 5500 in millicelcius (55°C).

You possibly can override different choices reminiscent of temperature thresholds utilizing the driver's config options.

Driver issues

Evidently the driving force might have a couple of bugs nonetheless, and it might simply be points with sure PWM followers, or a bug within the software program itself, I am not fairly certain.

In the event you encounter points, test if the issue you hit is already documented within the cm4io-fan issue queue.

Fundamental Temperature-controlled fan script

As a closing possibility you could possibly write your personal temperature-controlled fan script, which checks the present temperature, and boosts the fan velocity accordingly. It is nowhere close to as absolutely featured as the driving force above, however it might work in a pinch:

Conclusion

There are a couple of alternative ways to work together with the EMC2301 fan controller on the Raspberry Pi Compute Module 4 IO Board (and some different CM4 boards I've examined, just like the Seaberry), however the cm4io-fan driver appears essentially the most promising.

Hopefully you've got realized just a little about I2C on this submit, too—I do know I've realized a bit extra about it, how PWM followers work, and even why tuning issues like fan curves are vital!



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *