RPi-WiringPi

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


See the linked documentation for full documentation on usage, or the
[RPi::WiringPi::FAQ](https://metacpan.org/pod/RPi%3A%3AWiringPi%3A%3AFAQ) for usage examples.

NOTE: On the Pi 3 and Pi 4, Bluetooth occupies the primary UART, leaving the
header pins (14, 15) on the mini-UART (`/dev/ttyS0`). To put the full PL011
UART back on the header you must disable Bluetooth in the
`/boot/firmware/config.txt` file (`/boot/config.txt` on releases before
Bookworm):

    dtoverlay=pi3-disable-bt-overlay

On the Pi 5, Bluetooth has its own dedicated UART, so no `disable-bt` overlay
is needed; simply enable the header UART (`/dev/ttyAMA0`) with `enable_uart=1`.

## servo($pin\_num)

This method configures PWM clock and divisor to operate a typical 50Hz servo,
and returns a special [RPi::Pin](https://metacpan.org/pod/RPi%3A%3APin) object. These servos have a `left` pulse of
`50`, a `centre` pulse of `150` and a `right` pulse of `250`. On exit of
the program (or a crash), we automatically clean everything up properly.

Parameters:

lib/RPi/WiringPi.pm  view on Meta::CPAN

 
See the linked documentation for full documentation on usage, or the
L<RPi::WiringPi::FAQ> for usage examples.
 
NOTE: On the Pi 3 and Pi 4, Bluetooth occupies the primary UART, leaving the
header pins (14, 15) on the mini-UART (C</dev/ttyS0>). To put the full PL011
UART back on the header you must disable Bluetooth in the
C</boot/firmware/config.txt> file (C</boot/config.txt> on releases before
Bookworm):

    dtoverlay=pi3-disable-bt-overlay

On the Pi 5, Bluetooth has its own dedicated UART, so no C<disable-bt> overlay
is needed; simply enable the header UART (C</dev/ttyAMA0>) with C<enable_uart=1>.

=head2 servo($pin_num)
 
This method configures PWM clock and divisor to operate a typical 50Hz servo,
and returns a special L<RPi::Pin> object. These servos have a C<left> pulse of
C<50>, a C<centre> pulse of C<150> and a C<right> pulse of C<250>. On exit of
the program (or a crash), we automatically clean everything up properly.
 
Parameters:

lib/RPi/WiringPi/FAQ.pod  view on Meta::CPAN

in C<raspi-config>, under C<Interface Options -E<gt> Serial Port>, answer B<no>
to the login shell and B<yes> to the serial hardware.

B<Raspberry Pi 3 / 4 (and Zero W):> the on-board Bluetooth modem is wired to the
primary PL011 UART, leaving GPIO 14/15 on the inferior, baud-unstable mini-UART
(C</dev/ttyS0>). To move the good UART onto the header pins you must disable
Bluetooth. Edit C</boot/firmware/config.txt> (C</boot/config.txt> on releases
before Bookworm) and add:

    enable_uart=1
    dtoverlay=disable-bt

With that overlay the header serial port becomes C</dev/ttyAMA0>.

B<Raspberry Pi 5:> Bluetooth has its B<own dedicated UART> and is B<not> shared
with the GPIO 14/15 pins, so there is nothing to disable. Just enable the header
UART in C</boot/firmware/config.txt>:

    enable_uart=1

The header serial port is C</dev/ttyAMA0>. (Note that on the Pi 5 C</dev/serial0>
maps to the separate 3-pin debug-UART connector, B<not> the header pins.)

lib/RPi/WiringPi/FAQ.pod  view on Meta::CPAN

    audio_pwm_mode=514
    config_hdmi_boost=5
    core_freq=250
    desired_osc_freq=0x36ee80
    ...
    dtparam=i2c_arm=on
    dtparam=spi=on
    dtparam=audio=on
    enable_uart=1
    dtparam=i2c_arm_baudrate=10000
    dtoverlay=pi3-disable-bt-overlay
    dtoverlay=spi-bcm2835

=head3 Network configuration information

    say $pi->network_info;

This method returns the output of C<ifconfig> where the C<net-tools> package is
installed, falling back to C<ip addr> where it is not (as on current Raspberry
Pi OS Lite). Both forms carry the interface C<inet>/C<inet6> addresses.

=head3 File system information

lib/RPi/WiringPi/FAQ.pod  view on Meta::CPAN

interface using the L<RPi::Serial> library. See that documentation for full
usage information.

=head2 Note

On the Raspberry Pi 3 and 4, Bluetooth shares the primary UART with GPIO pins
14/15, so you must disable it. Add to C</boot/firmware/config.txt>
(C</boot/config.txt> on releases before Bookworm) and reboot:

    enable_uart=1
    dtoverlay=disable-bt

On the Raspberry Pi 5, Bluetooth has its own dedicated UART and does B<not>
share the header pins, so no overlay is needed - C<enable_uart=1> alone
suffices. See L</Serial configuration> for the full procedure.

=head2 Usage

    my $dev  = "/dev/ttyAMA0";   # Pi 5, and Pi 3/4 once Bluetooth is disabled
    my $baud = 115200;

    my $ser = $pi->serial($dev, $baud);

    $ser->putc(5);

lib/RPi/WiringPi/FAQ.pod  view on Meta::CPAN


These tests will skip by default otherwise.

Note that you must enable serial in C<raspi-config> and disable "terminal over
serial", then reboot. On the Pi 3/4 you must also free the header UART from
Bluetooth; on the Pi 5 that is unnecessary (Bluetooth has its own UART). Add the
appropriate lines to C</boot/firmware/config.txt> (C</boot/config.txt> on
releases before Bookworm):

    enable_uart=1
    dtoverlay=disable-bt    # Pi 3 / 4 only; neither needed nor used on the Pi 5

The loopback test talks to C</dev/ttyAMA0> (the header UART on the Pi 5, and on
the Pi 3/4 once Bluetooth is disabled).

=head3 BMP Barometric Pressure Sensor Testing

To test the temperature and barometric pressure from the BMPx80 sensors:

    export RPI_BMP=1

t/404-sysinfo_raspi_config.t  view on Meta::CPAN

use Test::More;

rpi_running_test(__FILE__);

my $pi = RPi::WiringPi->new(label => 't/404-sysinfo_raspi_config.t', shm_key => 'rpit');

like $pi->raspi_config, qr/core_freq/, "method includes vcgencmd data ok";

# config.txt is resolved by RPi::SysInfo (/boot/firmware/config.txt on Bookworm+,
# /boot/config.txt on older). Every Pi config.txt carries at least one dtparam=
# or dtoverlay= directive, and comment lines are stripped.

like
    $pi->raspi_config,
    qr/^dt(?:param|overlay)=/m,
    "...and config.txt directives are included";

unlike $pi->raspi_config, qr/^\s*#/m, "...and config.txt comment lines are stripped";

$pi->cleanup;

rpi_check_pin_status();
#rpi_metadata_clean();

done_testing();



( run in 1.072 second using v1.01-cache-2.11-cpan-7fcb06a456a )