Jump to content

PWM Fan on Nanopi M4 ??


perlian

Recommended Posts

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

which I've found works fine under armbian.


In case you find a wish to implement it:

 

script location:
https://github.com/armbian/build/tree/master/packages/bsp/rk3399
install hooks:
https://github.com/armbian/build/blob/master/config/sources/families/include/rockchip64_common.inc

Link to comment
Share on other sites

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? 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 ...

Link to comment
Share on other sites

1 hour ago, i5Js said:

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

I don't think so, because eMMC is /dev/mmcblk2 ...

 

But /dev/mmcblk1p2 means second partition, where ususally Armbian have a single partition.

What image are you using ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines