定制 dept-of-scrapyard-robotics/system-fans 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dept-of-scrapyard-robotics/system-fans

最新稳定版本:0.1.1

Composer 安装命令:

composer require dept-of-scrapyard-robotics/system-fans

包简介

ScrapyardIO Framework extension library that enabled PWM and GPIO Control of Fans on Linux

README 文档

README

Control your PWM or GPIO-driven SystemFans on your Embedded Linux enabled Device.

Requirements

Tested Devices

  • Raspberry Pi 4 and 4
  • Raspberry Pi Zero 2W
  • Jetson Orin Nano

To Be Tested

  • Arduino Uno Q
  • BananaPi
  • OrangePi
  • BigTreeTech Pi4B

Installation

After installing Zephir, the Scrapyard LinuxSystem extension, and the ScrapyardIO package you can install the framework via composer:

composer require dept-of-scrapyard-robotics/system-fans

Usage

GPIO Fans

GPIO Fans are fans with 3-pins -

  • (+) Voltage - 5V, 12V or 24V usually
  • (-) Ground
  • Data

When you plug the data pin into an available GPIO pin, you can turn the on at Full Speed or shut it off completely.

use ScrapyardIO\Actuation\SystemFans\Adapters\GPIOFanAdapter;

// On RPi 4, 5 and Zero2, the main PWM Chip is 4. This fan is plugged into GPIO 6 which maps to 
// physical pin 31.
$fan = (new GPIOFanAdapter())->chip(4)->line(6);


// Turn on the fan
$fan->motorOn();

// Turn off the fan
$fan->motorOff();

PWM Fans

PWM Fans are fans with 3, sometimes 4-pins -

  • (+) Voltage - 5V, 12V or 24V usually
  • (-) Ground
  • Data
  • (Optional) Tachometer (like Noctua fans)

When you plug the data pin into an available PWM-controlled pin, you can do various things to the fan

  • Toggle On/off
  • Set the speed
use ScrapyardIO\Actuation\SystemFans\Adapters\PWMFanAdapter;

// This fan is plugged into PWMChip 0 broadcasting on Channel 0 which maps to
// physical pin 32 on an RPi 4, 5 and Zero2
$fan = (new PWMFanAdapter())->chip(0)->channel(0);

// Sets the speed to 80% and turns the fan on
$fan->speed(80)->on();

$fan->off()

Using a Tachometer

If the systems fan plugged into PWM also contains a 4th Pin, you can plug that pin into an available GPIO pin and set it as an input to read the fan's spinning RPMs.

use ScrapyardIO\Actuation\SystemFans\Adapters\PWMFanAdapter;

// This fan is plugged into PWMChip 0 broadcasting on Channel 0 which maps to
// physical pin 32 on an RPi 4, 5 and Zero2

// On RPi 4, 5 and Zero2, the main PWM Chip is 4. This tachometer is plugged into GPIO 6 which maps to 
// physical pin 31.

$noctua_fan = (new PWMFanAdapter())->chip(0)->channel(0)->tach(4, 6);

// Blocks by default for 2 seconds, and sets PPR to 2
$rpm = $noctua_fan->rpm();

Extending

You can build you own fan implementation which will give you PWM access to

  • Set the oscillation frequency
use ScrapyardIO\Actuation\SystemFans\Adapters\SystemFanAdapter;
use ScrapyardIO\Actuation\SystemFans\Concerns\PWMFanMotor;

class CustomFan extends SystemFanAdapter
{
    use PWMFanMotor;
    
    public function getOscillationFrequency(): int
    {
        return $this->fan_motor_pwm()->frequency();
    }
}

Credits

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-30