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.

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);

Finally it was not as hard as I thought it would be. Despite the fact that Raspberry-PI B+ has got a lot of PIN's it has only got one PIN (GPIO 18 = Pin 12) PWM can be controlled via console by. These are the commands to control Duty Cycle for GPIO-Pin 18:

  1. Tell PIN 18 to be an Output-PIN for PWM:

    gpio -1 mode 12 pwm
    

    or

    gpio -g mode 18 pwm
    
  2. PWM has got a range between 0-1023

    0 switches a LED off:

    gpio -1 pwm 12 0
    

    or

    gpio -g pwm 18 0
    

    1023 makes LED to emit max brightness:

    gpio -1 pwm 12 1023
    

    or

    gpio -g pwm 18 1023
    

Deeply interesting that you do not have to tell the PIN on what frequency it should use PWM and my LED does not even flicker.

Hopes it helps someone out there.