HiPi
Perl Modules for Raspberry Pi
Version 0.92 - released 28 March 2024

HiPi::Device::GPIO::Pin

Provides an alternate wrapper for methods of the HiPi::Device::GPIO module.

use HiPi qw( :rpi );
use HiPi::Device::GPIO;
             
my $device = HiPi::Device::GPIO->new;
my $pin = $device->get_pin( RPI_PIN_11 );
$pin->value( RPI_HIGH );

Methods

Get or set the pin level

$pin->value( 1 );
my $level = $pin->value;

Get or set the current pin mode ( RPI_MODE_OUTPUT or RPI_MODE_INPUT )

$pin->mode( RPI_MODE_OUTPUT );
my $mode = $pin->mode;

Set or remove the internal Pull Up or Pull Down resistor on the pin. Uses constants:

RPI_PUD_OFF
RPI_PUD_DOWN
RPI_PUD_UP
$pin->set_pud( RPI_PUD_UP );

On the BCM2711 based Raspberry Pi 4 you can retrieve the current pull up / down setting for a gpio pin. Returns one of the constants:

RPI_PUD_OFF
RPI_PUD_DOWN
RPI_PUD_UP
RPI_PUD_UNSET

For BCM2835/6/7 based Raspberry Pi's this method will always return RPI_PUD_UNSET

use HiPi qw( :rpi );
...
my $setting = $pin->get_pud();

Return descriptive text for the current pin function ( 'INPUT' or 'OUTPUT' )

my $description = $pin->get_function();

Get or set the active low status of the pin ( 1 or 0 )

$pin->active_low( 1 );
my $inverse = $pin->active_low;

Get or set the pin state change or changes that you want to produce interrupts. Can be one of the following constants:

RPI_INT_NONE       
RPI_INT_FALL           
RPI_INT_RISE        
RPI_INT_BOTH
$pin->interrupt( RPI_INT_RISE );
my $int = $pin->interrupt;

To watch for interrupts you must epoll or poll the filepath returned by this method.

my $filepath = $pin->get_interrupt_filepath()