When I initially reviewed 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 EMC2301.
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 and show you how you can control a fan connected to the IO Board, like the quiet Noctua NF-P12 pictured above with my IO Board.
If you plug a fan like that into the CM4 IO Board, it will start running full blast, 24×7. 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.
So what are my options? First of all, I could just buy an inline PWM controller, like a Noctua NA-FC1. 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.
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!
What is I2C?
I2C—or more correctly, I2C—stands for “Inter-Integrated Circuit” and is a two-wire serial communication interface used by many electronic devices for control and communications.
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 Analog Device’s I2C Primer.
Controlling the fan over I2C
You have to edit your /boot/config.txt
file to enable the i2c_vc
bus, which is bus #1. The Pi Device Tree Documentation actually recommends against touching i2c_vc
unless you need to, because you could mess up CSI camera or DSI display functionality.
Make sure the following lines exist and are uncommented in /boot/config.txt
and reboot the Pi:
# Enable I2C.
dtparam=i2c_arm=on
# Enable I2C bus 1.
dtparam=i2c_vc=on
Note: If you just enable I2C under the ‘Interfaces’ option of
raspi-config
, it will only enablei2c_arm
. To see the fan controller, you need to enablei2c_vc
as well.
Make sure the i2c-tools
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 sudo apt-get install -y i2c-tools
.
Now, check if you can see the fan controller chip on the bus, using 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
device. Test if you can turn off the fan using:
$ i2cset -y 10 0x2f 0x30 0x00
The fan should now be off. And to turn it back on:
$ i2cset -y 10 0x2f 0x30 0xff
To get the value of the fan setting, you can use:
$ i2cget -y 10 0x2f 0x30
0xff
What about setting the fan to a value between 0% (off) and 100% (full on) though? The value is hexadecimal, so 0xFF
stands for 255
, while 0x00
is 0
. Using a high-ish number should be safe, right, to set the fan to a lower speed? Well, let’s try it out.
Load more 4501
Load more 4502
Load more 4503
Load more 4504
Load more 4505
Load more 4506
Load more 4507
Load more 4508
Load more 4509
Load more 4510
Load more 4511
Load more 4512
Load more 4513
Load more 4514
Load more 4515
Load more 4516
Load more 4517
Load more 4518
Load more 4519
Load more 4520
Load more 4521
Load more 4522
Load more 4523
Load more 4524
Load more 4525
Load more 4526
Load more 4527
Load more 4528
Load more 4529
Load more 4530
Load more 4531
Load more 4532
Load more 4533
Load more 4534
Load more 4535
Load more 4536
Load more 4537
Load more 4538
Load more 4539
Load more 4540
Load more 4541
Load more 4542
Load more 4543
Load more 4544
Load more 4545
Load more 4546
Load more 4547
Load more 4548
Load more 4549
Load more 4550
Load more 4551
Load more 4552
Load more 4553
Load more 4554
Load more 4555
Load more 4556
Load more 4557
Load more 4558
Load more 4559
Load more 4560
Load more 4561
Load more 4562
Load more 4563
Load more 4564
Load more 4565
Load more 4566
Load more 4567
Load more 4568
Load more 4569
Load more 4570
Load more 4571
Load more 4572
Load more 4573
Load more 4574
Load more 4575
Load more 4576
Load more 4577
Load more 4578
Load more 4579
Load more 4580
Load more 4581
Load more 4582
Load more 4583
Load more 4584
Load more 4585
Load more 4586
Load more 4587
Load more 4588
Load more 4589
Load more 4590
Load more 4591
Load more 4592
Load more 4593
Load more 4594
Load more 4595
Load more 4596
Load more 4597
Load more 4598
Load more 4599
Load more 4600
Load more 4601
Load more 4602
Load more 4603
Load more 4604
Load more 4605
Load more 4606
Load more 4607
Load more 4608
Load more 4609
Load more 4610
Load more 4611
Load more 4612
Load more 4613
Load more 4614
Load more 4615
Load more 4616
Load more 4617
Load more 4618
Load more 4619
Load more 4620
Load more 4621
Load more 4622
Load more 4623
Load more 4624
Load more 4625
Load more 4626
Load more 4627
Load more 4628
Load more 4629
Load more 4630
Load more 4631
Load more 4632
Load more 4633
Load more 4634
Load more 4635
Load more 4636
Load more 4637
Load more 4638
Load more 4639
Load more 4640
Load more 4641
Load more 4642
Load more 4643
Load more 4644
Load more 4645
Load more 4646
Load more 4647
Load more 4648
Load more 4649
Load more 4650
Load more 4651
Load more 4652
Load more 4653
Load more 4654
Load more 4655
Load more 4656
Load more 4657
Load more 4658
Load more 4659
Load more 4660
Load more 4661
Load more 4662
Load more 4663
Load more 4664
Load more 4665
Load more 4666
Load more 4667
Load more 4668
Load more 4669
Load more 4670
Load more 4671
Load more 4672
Load more 4673
Load more 4674
Load more 4675
Load more 4676
Load more 4677
Load more 4678
Load more 4679
Load more 4680
Load more 4681
Load more 4682
Load more 4683
Load more 4684
Load more 4685
Load more 4686
Load more 4687
Load more 4688
Load more 4689
Load more 4690
Load more 4691
Load more 4692
Load more 4693
Load more 4694
Load more 4695
Load more 4696
Load more 4697
Load more 4698
Load more 4699
Load more 4700
Load more 4701
Load more 4702
Load more 4703
Load more 4704
Load more 4705
Load more 4706
Load more 4707
Load more 4708
Load more 4709
Load more 4710
Load more 4711
Load more 4712
Load more 4713
Load more 4714
Load more 4715
Load more 4716
Load more 4717
Load more 4718
Load more 4719
Load more 4720
Load more 4721
Load more 4722
Load more 4723
Load more 4724
Load more 4725
Load more 4726
Load more 4727
Load more 4728
Load more 4729
Load more 4730
Load more 4731
Load more 4732
Load more 4733
Load more 4734
Load more 4735
Load more 4736
Load more 4737
Load more 4738
Load more 4739
Load more 4740
Load more 4741
Load more 4742
Load more 4743
Load more 4744
Load more 4745
Load more 4746
Load more 4747
Load more 4748
Load more 4749
Load more 4750
Load more 4751
Load more 4752
Load more 4753
Load more 4754
Load more 4755
Load more 4756
Load more 4757
Load more 4758
Load more 4759
Load more 4760
Load more 4761
Load more 4762
Load more 4763
Load more 4764
Load more 4765
Load more 4766
Load more 4767
Load more 4768
Load more 4769
Load more 4770
Load more 4771
Load more 4772
Load more 4773
Load more 4774
Load more 4775
Load more 4776
Load more 4777
Load more 4778
Load more 4779
Load more 4780
Load more 4781
Load more 4782
Load more 4783
Load more 4784
Load more 4785
Load more 4786
Load more 4787
Load more 4788
Load more 4789
Load more 4790
Load more 4791
Load more 4792
Load more 4793
Load more 4794
Load more 4795
Load more 4796
Load more 4797
Load more 4798
Load more 4799
Load more 4800
Load more 4801
Load more 4802
Load more 4803
Load more 4804
Load more 4805
Load more 4806
Load more 4807
Load more 4808
Load more 4809
Load more 4810
Load more 4811
Load more 4812
Load more 4813
Load more 4814
Load more 4815
Load more 4816
Load more 4817
Load more 4818
Load more 4819
Load more 4820
Load more 4821
Load more 4822
Load more 4823
Load more 4824
Load more 4825
Load more 4826
Load more 4827
Load more 4828
Load more 4829
Load more 4830
Load more 4831
Load more 4832
Load more 4833
Load more 4834
Load more 4835
Load more 4836
Load more 4837
Load more 4838
Load more 4839
Load more 4840
Load more 4841
Load more 4842
Load more 4843
Load more 4844
Load more 4845
Load more 4846
Load more 4847
Load more 4848
Load more 4849
Load more 4850
Load more 4851
Load more 4852
Load more 4853
Load more 4854
Load more 4855
Load more 4856
Load more 4857
Load more 4858
Load more 4859
Load more 4860
Load more 4861
Load more 4862
Load more 4863
Load more 4864
Load more 4865
Load more 4866
Load more 4867
Load more 4868
Load more 4869
Load more 4870