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 4 => PI_ALT0 5 => PI_ALT1 6 => PI_ALT2 7 => PI_ALT3 3 => PI_ALT4 2 => PI_ALT5

in/out/pwm/clock/up/down/tri

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.

write

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->write(17, HI);
or 
$pi->write(17, LOW);

read

Gets the voltage level on a GPIO

Note: You first must set the pin mode to PI_INPUT

Usage :

$pi->read(17);
or 
$pi->read(17);

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 - coderef to the method 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');

cancel_callback

Cancels a callback for the given GPIO

Usage: $pi->cancel_callback($gpio);

Params: $gpio - gpio for which you want to cancel the 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);

Sends a command to the pigiod daemon and waits for a response

send_command_on_socket

Same as send_command but allows you to specify the socket you want to use

The pourpose of this is to allow you to use the send_command functionality on secondary connections used to monitor changes on GPIO

Params: =over indentlevel =item 1. socket - Instance of IO::Socket::INET =item 2. command - code of the command you want to send (see package constants) =item 3. param1 - first parameter (usualy the GPIO) =item 4. param2 - second parameter - optional - usualy the level to which to set the GPIO (HI/LOW) =back

start_callback_thread

Starts a secondary thread used to monitor user specified GPIOs for changes

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 400:

Unknown directive: =h1

Around line 404:

Unknown directive: =h2

Around line 408:

=over should be: '=over' or '=over positive_number'

Around line 421:

You forgot a '=back' before '=head2'