NAME
RPi::PIGPIO - remotely control the GPIO on a RaspberryPi using the pigpiod daemon
DESCRIPTION
This module impements a client for the pigpiod daemon, and can be used to control the GPIO on a local or remote RaspberryPi
ERROR CODES
This is the list of error codes returned by various methods (exported constant and the equivalent value) PI_BAD_GPIO => PI_BAD_MODE => PI_NOT_PERMITTED =>
METHODS
connect
Connects to the pigpiod running on the given IP address/port and returns an object that will allow us to manipulate the GPIO on that Raspberry Pi
disconnect
Disconnect from the gpiod daemon.
The current object is no longer usable once we disconnect.
get_mode
Returns the mode of a given GPIO pin
Return values : 0 => PI_INPUT 1 => PI_OUTPUT 2 => PI_ALT0 3 => PI_ALT1 4 => PI_ALT2 5 => PI_ALT3 6 => PI_ALT4 7 => PI_ALT5
set_mode
Sets the GPIO mode
Usage:
$pi->set_mode(17, PI_OUTPUT);
Valid values for $mode are exported as constants and are : PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE, or PI_NOT_PERMITTED.
set_level
Sets the voltage level on a GPIO pin to HI or LOW
Note: You first must set the pin mode to PI_OUTPUT
Usage :
$pi->set_level(17, HI);
or
$pi->set_level(17, LOW);
callback
Register a method you want to be called when the level on a given pin changes
Usage : $pi->callback($gpio, $edge, $method_ref);
Params : $gpio - number of the GPIO pin we want to monitor $edge - on of RISING_EDGE, FALLING_EDGE, EITHER_EDGE $callback_method_name - *name* the method (as string) that you want to be called when an event is detected. The metod will be called with the gpio number, edge and tick as parameters
Usage :
sub process_callback {
my ($gpio, $edge, $tick) = @_;
...
};
$pi->callback(17, EITHER_EDGE, 'process_callback');
Returns the is of the callback. This ID must be used when you call callback_cancel
callback_cancel
Cancel a callback registered with callback
Usage: $pi->callback_cancel(5);
Params: $callback_id - ID of the callback you want to cancel, as returned by callback
gpio_trigger
This function sends a trigger pulse to a GPIO. The GPIO is set to level for pulseLen microseconds and then reset to not level.
Params (in this order): $gpio - number of the GPIO pin we want to monitor $length - pulse length in microseconds $level - level to use for the trigger (HI or LOW)
Usage: $pi->gpio_trigger(4,17,LOW);