douxun2023 2015-02-09 16:31
浏览 155
已采纳

Raspberry Pi GPIO:通过控制台命令更改占空比

After implementing a python-script that changes duty-cycle for a LED like in this example:

http://raspi.tv/2013/rpi-gpio-0-5-2a-now-has-software-pwm-how-to-use-it

I would like to change duty-cycle in the shell or console, what commands and in what order do they have to be keyed in?

I've done little research so far that brought me to a similar example done with python like in the link above. I also know how to execute console-commands in PHP.

My intention is to take advantage of console-commands to control the brightness of a LED that is triggered by a AJAX To PHP Request. I do not want to execute a python-script in PHP because of right-privileges on Apache2-Server having to be adjusted.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • doushi4633 2018-11-15 21:36
    关注

    In the meanwhile there is the possibility of directly sending PWM signals with PHP using the php-pigpio library, which is an interface for the Pigpio daemon

    Pulse width:

    Sending an PWM signal with a pulse width of 1500 microseconds on GPIO pin 15:

    use Volantus\Pigpio\Client;
    use Volantus\Pigpio\PWM\PwmSender;
    
    $client = new Client();
    $sender = new PwmSender($client);
    $sender->setPulseWidth(15, 1500);
    

    Duty cycle:

    Of if you prefer the duty cycle / range mode (as in your own example):

    Setting the range to 1024:

    $sender->setRange(15, 1024);
    

    Sending a signal of 50%:

    $sender->setDutyCycle(15, 512);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!