NAME

RPi::WiringPi::Util - Utility methods for RPi::WiringPi Raspberry Pi interface

DESCRIPTION

This module contains various utilities for RPi::WiringPi that don't necessarily fit anywhere else. It is a base class, and is not designed to be used independently.

METHODS

gpio_layout()

Returns the GPIO layout which indicates the board revision number.

pin_scheme([$scheme])

Returns the current pin mapping in use. Returns 0 for wiringPi scheme, 1 for GPIO, 2 for System GPIO, 3 for physical board and -1 if a scheme has not yet been configured (ie. one of the setup*() methods has not yet been called).

If using RPi::WiringPi::Constant, these map out to:

0  => RPI_MODE_WPI
1  => RPI_MODE_GPIO
2  => RPI_MODE_GPIO_SYS # unused in RPi::WiringPi
3  => RPI_MODE_PHYS
-1 => RPI_MODE_UNINIT

pin_map($scheme)

Returns a hash reference in the following format:

$map => {
    phys_pin_num => pin_num,
    ...
};

If no scheme is in place or one isn't sent in, return will be an empty hash reference.

Parameters:

$scheme

Optional: By default, we'll check if you've already run a setup routine, and if so, we'll use the scheme currently in use. If one is not in use and no $scheme has been sent in, we'll return an empty hash reference, otherwise if a scheme is sent in, the return will be:

For 'wiringPi' scheme:

$map = {
    phys_pin_num => wiringPi_pin_num,
    ....
};

For 'GPIO' scheme:

$map = {
    phys_pin_num => gpio_pin_num,
    ...
};

pin_to_gpio($pin, [$scheme])

Dynamically converts the specified pin from the specified scheme (RPI_MODE_WPI (wiringPi), or RPI_MODE_PHYS (physical board numbering scheme) to the GPIO number format.

If $scheme is not sent in, we'll attempt to fetch the scheme currently in use and use that.

Example:

my $num = pin_to_gpio(6, RPI_MODE_WPI);

That will understand the pin number 6 to be the wiringPi representation, and will return the GPIO representation.

wpi_to_gpio($pin_num)

Converts a pin number from wiringPi notation to GPIO notation.

Parameters:

$pin_num

Mandatory: The wiringPi representation of a pin number.

phys_to_gpio($pin_num)

Converts a pin number as physically documented on the Raspberry Pi board itself to GPIO notation, and returns it.

Parameters:

$pin_num

Mandatory: The pin number printed on the physical Pi board.

pwm_range($range)

Changes the range of Pulse Width Modulation (PWM). The default is 0 through 1023.

Parameters:

$range

Mandatory: An integer specifying the high-end of the range. The range always starts at 0. Eg: if $range is 359, if you incremented PWM by 1 every second, you'd rotate a step motor one complete rotation in exactly one minute.

export_pin($pin_num)

Exports a pin. Only needed if using the setup_sys() initialization method.

Pin number must be the GPIO pin number representation.

unexport_pin($pin_num)

Unexports a pin. Only needed if using the setup_sys() initialization method.

Pin number must be the GPIO pin number representation.

registered_pins()

Returns an array reference where each element is the GPIO pin number of each currently registerd pin.

register_pin($pin_obj)

Registers a pin within the system for error checking, and proper resetting of the pins in use when required.

Parameters:

$pin_obj

Mandatory: An object instance of RPi::WiringPi::Pin class.

unregister_pin($pin_obj)

Removes an already registered pin from the registry. This method shouldn't be used in the normal course of operation, but is available for convenience anyhow.

Parameters:

$pin_obj

Mandatory: An object instance of RPi::WiringPi::Pin class.

cleanup()

Resets all registered pins back to default settings as they were before your program started. It's important that this method be called in each application.

ENVIRONMENT VARIABLES

There are certain environment variables available to aid in testing on non-Raspberry Pi boards.

NO_BOARD

Set to true, will bypass the wiringPi board checks. False will re-enable them.

PI_BOARD

Useful only for unit testing. Tells us that we're on Pi hardware.

AUTHOR

Steve Bertrand, <steveb@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Steve Bertrand

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.