Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PWM Fan on Nanopi M4 ??

Featured Replies

i found a running task on friendlyelec desktop called "pwm fan"

 

But i found no more informations how to connect a pwm fan to the Nanopi M4

 

Which pins are needed to connect ?

 

Can i use a normal 5V Fan or is a special Fan needed ?

 

Anyone aware of this ?

Indeed there is a PH.2.0 connector on the hat and also on the SATA hat but there is not much info on this except that is driven by pwmchip1 (exposed on the 20pin header) and regulated by a P channel MOSFET, maybe FA should add some data about the compatible fans for the people less skiled in electronics.

friendly desktop has service pwm-fan.  it runs   which I've found works fine under armbian.  you can edit the temps at which fan turns on in the script

 

all assuming you have the nvme hat

Edited by justin.wills
added requirement of nvme hat

On 1/11/2020 at 1:09 PM, justin.wills said:

friendly desktop has service pwm-fan.  it runs   which I've found works fine under armbian.  you can edit the temps at which fan turns on in the script

 

all assuming you have the nvme hat

 

Hi, I would like to try this scipt, could you please point me to where to find this? 

 

 

I'm confused about how this 2-pin fan header does PWM fan control. It sounds to me like the PWM pin just completely turns the power on/off to the 2-pin socket. But I just want to use standard 4-pin PWM fans with this board. Sounds like that would require extra hacking on the linked post (and an extra pin if monitoring fan RPM is desired). Is that correct?

 

I may for the time being just buy a couple $5 4-pin PWM fan controllers with a temp sensor off Amazon, and worry about this later. Kinda wish they'd made it easy to support standard 4-pin 12V PWM fans, even with just a physical connector.

On 1/19/2020 at 5:29 AM, mar0ni said:

Hi, I would like to try this scipt, could you please point me to where to find this? 

 

 

I just copied the pwm-fan.service and associated script from the friendly distro.  can't remember the name, rk3399-something, but it is defined in the service file

On 1/13/2020 at 4:13 AM, Igor said:

AHA!   thats where the min/max frequency is set.  I did notice that it no longer scales back to 408.  I'll have a play with that

On 1/21/2020 at 1:12 AM, justin.wills said:

I just copied the pwm-fan.service and associated script from the friendly distro.

Hi Justin, thank you for the hint, worked like a charm for me also.

 

Attached the service file and bash script.

pwm-fan.tar.bz2

On 1/26/2020 at 7:09 AM, mar0ni said:

Hi Justin, thank you for the hint, worked like a charm for me also.

 

Attached the service file and bash script.

 

 

I have found that the default service doesn't allow systemd to finish loading.  so I have modified the service file to use Type=simple and User=root

 

Quote

[Unit]
Description=pwm-fan
After=rc.local.service

[Service]
Type=simple
User=root
KillMode=control-group
WorkingDirectory=/tmp
ExecStart=/usr/bin/start-rk3399-pwm-fan.sh 


[Install]
WantedBy=multi-user.target
Alias=pwm-fan.service
 

 

Slightly improved and simplified script (still room for improvement, I guess).

 

#!/bin/bash

if [ ! -d /sys/class/pwm/pwmchip1/pwm0 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/export
fi
sleep 1
while [ ! -d /sys/class/pwm/pwmchip1/pwm0 ];
do
    sleep 1
done
ISENABLE=`cat /sys/class/pwm/pwmchip1/pwm0/enable`
if [ $ISENABLE -eq 1 ]; then
    echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
fi
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

# max speed run 5s
echo 0 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
sleep 5
echo 49994 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

declare -a CpuTemps=(75000 63000 58000 52000 48000 0)
declare -a PwmDutyCycles=(25000 37000 48300 49250 49300 49994)

while true
do
	temp=$(cat /sys/class/thermal/thermal_zone0/temp)
	for i in 0 1 2 3 4 5; do
		if [ $temp -gt ${CpuTemps[$i]} ]; then
			DUTY=${PwmDutyCycles[$i]}
			echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle";
			#echo "temp: $temp, target: ${CpuTemps[$i]}, duty: $DUTY"
			break		
		fi
	done
	sleep 2s;
done

 

Hello mar0ni,

I'm trying your last script with a NanoPiM4v2, but bash gives me the following error:

/usr/bin/start-rk3399-pwm-fan-v2.sh: line 33: echo: write error: Invalid argument

But I can't find the problem in your code.

Any idea ?

 

EDIT:

I had to add quotes around the file path:

echo $DUTY > "/sys/class/pwm/pwmchip1/pwm0/duty_cycle";

It's working great now !

Hello all, 

 

I've just bought my nanopc t4 and I'm trying to run the script but I got the following:

 

echo 0 > /sys/class/pwm/pwmchip1/export  echo: write error: Device or resource busy

 

then

 

+ sleep 1
+ '[' '!' -d /sys/class/pwm/pwmchip1/pwm0 ']'
+ sleep 1
+ '[' '!' -d /sys/class/pwm/pwmchip1/pwm0 ']'
+ sleep 1
+ '[' '!' -d /sys/class/pwm/pwmchip1/pwm0 ']'
+ sleep 1
 

 

Can you help me?

 

Many thanks.

 

Hi Igor, 

 

Thanks for your answer, and my apologies if I'm not doing things properly :)

 

This is the url with the output

 

http://ix.io/2fds

 

Regards

 

 

I'm unable now to boot from MicroSD and  flash other Arabian version on the EMMC memory... It's quite desperate because always boot from EMMC

27 minutes ago, i5Js said:

I'm unable now to boot from MicroSD and  flash other Arabian version on the EMMC memory... It's quite desperate because always boot from EMMC

eMMC has boot priority on RK3399. So, You need to temporarily disable it byt pressing "boot" button and kept it pressed for few second while pressing "reset" button ...

Hi

 

Thanks for your answer, do you know how many secs? Because it’s imposible!!

 

Thanks.

Ufff this is insane, now says:

mount: no such device

Failed to mount /dev/mmcblk1p2 as root file system. (This I gues is still EMMC)

(initramfs)

Buster server with kernel 4.4 I’ll reflash the sd card again and give it a second chance.

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.