RPi::WiringPi::Core - Core methods for RPi::WiringPi Raspberry Pi interface
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.
Besides the methods listed below, we also make available through inheritance all methods provided by RPi::SysInfo. Please see that documentation for usage details.
Returns the GPIO layout which indicates the board revision number.
This is a helper method to better help you identify which Raspberry Pi board you're currently working on, by allowing you to turn the green disk IO LED on constantly.
WARNING: This method calls system command line commands using sudo internally.
sudo
Parameters:
$tweak
Optional: Sending in a true value (eg 1) will turn the green disk activity LED on constantly (ie. no blinking on activity). Sending in a false value or omitting the parameter will restore the disk activity LED back to default state.
1
This is a helper method to better help you identify which Raspberry Pi board you're currently working on, by allowing you to turn the red power LED off.
Optional: Sending in a true value (eg: 1) will turn the red power LED off. Sending in a false value (or omitting the parameter) will restore the power LED back to default state.
This method wraps the io_led() and pwr_led() methods.
$seconds
Optional, Integer: The number of seconds to remain in "identify" state. Defaults to 5.
5
In "identify" state, the green disk I/O LED will remain on constantly, and the red power LED will stay off for the duration.
Allows you to set and retrieve a label (aka name) for your Raspberry Pi object.
$label
Optional, String: Send in a string parameter to set a label/name for your Pi object.
Return: The label/name you've previously set. If one has not been set, return will be the empty string.
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).
0
wiringPi
2
3
-1
setup*()
If using RPi::Const, 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
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.
$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:
'wiringPi'
$map = { phys_pin_num => wiringPi_pin_num, .... };
For 'GPIO' scheme:
'GPIO'
$map = { phys_pin_num => gpio_pin_num, ... };
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.
RPI_MODE_WPI
RPI_MODE_PHYS
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.
6
Converts a pin number from wiringPi notation to GPIO notation.
$pin_num
Mandatory: The wiringPi representation of a pin number.
Converts a pin number as physically documented on the Raspberry Pi board itself to GPIO notation, and returns it.
Mandatory: The pin number printed on the physical Pi board.
Changes the range of Pulse Width Modulation (PWM). The default is 0 through 1023.
1023
$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.
359
Each PWM channel can run in either Balanced or Mark-Space mode. In Balanced mode, the hardware sends a combination of clock pulses that results in an overall DATA pulses per RANGE pulses. In Mark-Space mode, the hardware sets the output HIGH for DATA clock pulses wide, followed by LOW for RANGE-DATA clock pulses.
Raspberry Pi's default mode is balanced mode.
$mode
Mandatory, Integer: 0 for Mark-Space mode, or 1 for Balanced mode. Note: If using RPi::Const, you can use PWM_MODE_MS or PWM_MODE_BAL.
PWM_MODE_MS
PWM_MODE_BAL
The PWM clock can be set to control the PWM pulse widths. The PWM clock is derived from a 19.2MHz clock. You can set any divider.
For example, say you wanted to drive a DC motor with PWM at about 1kHz, and control the speed in 1/1024 increments from 0/1023 (stopped) through to 1023/1023 (full on). In that case you might set the clock divider to be 16, and the RANGE to 1023. The pulse repetition frequency will be 1.2MHz/1024 = 1171.875Hz.
$divisor
Mandatory, Integer: An unsigned integer to set the pulse width to.
Exports a pin. Only needed if using the setup_sys() initialization method.
setup_sys()
Pin number must be the GPIO pin number representation.
GPIO
Unexports a pin. Only needed if using the setup_sys() initialization method.
Returns an array reference where each element is the GPIO pin number of each currently registerd pin.
Registers a pin within the system for error checking, and proper resetting of the pins in use when required.
$pin_obj
Mandatory: An object instance of RPi::Pin class.
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.
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.
There are certain environment variables available to aid in testing on non-Raspberry Pi boards.
Set to true, will bypass the wiringPi board checks. False will re-enable them.
Useful only for unit testing. Tells us that we're on Pi hardware.
Steve Bertrand, <steveb@cpan.org>
Copyright (C) 2016-2019 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.
To install RPi::WiringPi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RPi::WiringPi
CPAN shell
perl -MCPAN -e shell install RPi::WiringPi
For more information on module installation, please visit the detailed CPAN module installation guide.