Native PHP extension for sending PWM signals based on PHP-CPP and the great Pigpiod library on RaspberryPi.
Please make sure you installed the PHP-CPP library (guide) + pigpio (Guide). Clone and compile the source code:
git clone https://github.com/Volantus/berry-spi
cd berry-spi
make
sudo make install
PWM signals are managed by class PwmSender
.
use Volantus\BerryPwm\PwmSender;
$sender = new PwmSender();
Sets the pulse width to 1600 microseconds on GPIO pin 14:
$sender->setPulseWidth(14, 1500);
Duty cycle is controlled by setting a integer value out of a valid range. Default range: 255
The range may be modified by using $sender->setRange()
method.
Example: Setting duty cycle to 150 out of 255 => ~59% on GPIO pin 14:
$sender->setDutyCycle(14, 150);
Range of duty cycle may be modified for gaining more precision. Note: The real range used internally depends on the frequency and sample size, s. official Pigpiod documentation for more details.
Example: Setting range to 1024 on GPIO pin 14:
$sender->setRange(14, 1024);
Set the frequency (in Hz) of the PWM to be used on the GPIO. The selectable frequencies depend upon the sample rate, s. official Pigpiod documentation for more details.
Example: Setting frequency to 250 Hz on GPIO pin 14:
$sender->setFrequency(14, 250);
All configurable values may be read as well.
Reading different kind of values of GPIO pin 14:
$sender->getPulseWidth(14);
$sender->getDutyCycle(14);
$sender->getRange(14);
$sender->getFrequency(14);