
Rpi wiringpi unit test platform board-2
stevieb9/rpi-wiringpi
Perl interface to Raspberry Pi's board, GPIO and various sensors and ICs

Perl interface to Raspberry Pi's board, GPIO and various sensors and ICs
Rpi wiringpi unit test platform board-3 is an open-source printed circuit board by stevieb9, from the stevieb9/rpi-wiringpi repository on GitHub. It is a 2-layer board of 91.4 × 67.9 mm with 28 parts on 48 nets, routed with 294 tracks and 37 vias.
Its parts include 8 connectors, 6 resistors, 4 diodes, 3 capacitors and 2 ICs. It belongs with the interfaces and adapters boards of this library.
RPi::WiringPi - Perl interface to Raspberry Pi's board, GPIO, LCDs and other various items
Please see the FAQ for full usage details.
use RPi::WiringPi;
use RPi::Const qw(:all);
my $pi = RPi::WiringPi->new;
# For the below handful of system methods, see RPi::SysInfo
my $mem_percent = $pi->mem_percent;
my $cpu_percent = $pi->cpu_percent;
my $cpu_temp = $pi->core_temp;
my $gpio_info = $pi->gpio_info;
my $raspi_conf = $pi->raspi_config;
my $net_info = $pi->network_info;
my $file_system = $pi->file_system;
my $hw_details = $pi->pi_details;
my $pi_model = $pi->pi_model;
# Pin
my $pin = $pi->pin(5);
$pin->mode(OUTPUT);
$pin->write(ON);
my $num = $pin->num;This is the root module for the RPi::WiringPi system. It interfaces to a
Raspberry Pi board, its accessories and its GPIO pins via the
wiringPi library through the Perl wrapper
WiringPi::API
module, and various other custom device specific modules.
wiringPi must be installed prior to installing/using
this module. The required minimum version is the family-wide constant
"WIRINGPI_MIN_VERSION" in RPi::Const (currently 3.18), enforced at build time by
RPi::Const::BuildCheck in each distribution's Makefile.PL - so the
minimum is defined in exactly one place.
By default we use the GPIO (Broadcom (BCM) GPIO) pin numbering scheme;
wiringPi's own (WPI) scheme is also available via setup => 'wiringpi'.
This module is essentially a 'manager' for the sub-modules (ie. components).
You can use the component modules directly, but retrieving components through
this module instead has many benefits. We maintain a registry of pins and other
data, and reset the Pi back to default settings when your program ends (on
normal exit, on an uncaught die(), and on SIGINT/SIGTERM), so components
are not left in an inconsistent state. Component modules do none of these things.
There are a basic set of constants that can be imported. See RPi::Const.
It's handy to have access to a pin mapping conversion chart. There's an
excellent pin scheme map for reference at
pinout.xyz. You can also run the pinmap
command that was installed by this module, or wiringPi's gpio readall
command.
Returns a new RPi::WiringPi object. By default we use the GPIO
(Broadcom (BCM) GPIO) pin numbering scheme; see the setup parameter below
to select wiringPi's own (WPI) numbering instead.
Parameters:
setup => $stringOptional, String: Which wiringPi setup routine (and therefore pin numbering
scheme) to initialize the board with. Matching is case-insensitive on the
first letter:
'gpio' - GPIO (BCM) numbering; the default if not sent in
'wiringpi' - WiringPi's own (WPI) numbering
'none' - Skip board setup entirely (the pin scheme remains
uninitialized; primarily for testing)Any other value will croak. Note that if another application in the process
has already run a setup routine (signalled via the RPI_PIN_MODE environment
variable), that existing scheme is honoured and this parameter is ignored.
shm_key => $stringBy default, we use the key rpiw as the shared memory segment key. You can
change this if desired. Useful for separating "groups" of Pi objects from one
another (for example, production scripts can operate at the same time as test
scripts, and both use their own shared memory pool).
fatal_exit => $boolOptional: Controls what happens when we trap a SIGINT (Ctrl-C) or SIGTERM.
In both cases we first reset the Pi hardware to a safe state. By default
(fatal_exit true), we then re-raise the signal so the program terminates as it
normally would. Set fatal_exit to false (0) to perform the cleanup and then
continue running your script (eg. for unit-test work, or to allow your own
signal handling to take over).
With multiple Pi objects in a single process, the signal is re-raised only if
every live object has fatal_exit true; any object created with
fatal_exit => 0 keeps the process running.
Note that this only affects trapped signals. Hardware cleanup on a normal exit or
on an uncaught die() always happens automatically (via the object's END/
DESTROY handling); we do not trap $SIG{__DIE__}, so a die() you catch
yourself with eval will not disturb your pins. Any $SIG{INT}/$SIG{TERM}
handler you installed before creating the object is chained to, not replaced.
rpi_register => $boolOptional: Set this value to false (0) to bypass the Pi object registration in
the meta data. This will also prevent pins from being registered as well. If set
to false, no object or pin cleanup will take place at the end of a program run.
rpi_register_pins => $boolOptional: Similar to rpi_register, but only bypasses the pin registration.
Object registration will still occur, and the object will be cleaned up after
but the pins will not. Should only be used for testing.
Returns an RPi::Accelerometer::ADXL335 object for an ADXL335 three-axis analog accelerometer, reporting acceleration in g and tilt angle in degrees.
The Pi has no analog inputs, so the sensor's three outputs go through an ADC. You build the ADC yourself (see "adc") and hand it in, along with the ADC channel each axis is wired to. All parameters are passed straight through to the driver's constructor:
adc => $objectMandatory, Object: An ADC object providing a volts() or percent() method,
such as the one returned by "adc".
x => $int
y => $int
z => $intMandatory, Integer: The ADC input channels wired to the sensor's XOUT,
YOUT and ZOUT pins.
vs => $numOptional, Number: The sensor's supply voltage, which sets the ratiometric
sensitivity and the zero-g point. Defaults to 3.3.
vref => $numOptional, Number: The ADC's full-scale reference voltage, used to scale
percent-only ADCs. Defaults to vs.
sensitivity => $num
zero_g => $hrefOptional: Override the volts-per-g sensitivity, or the per-axis zero-g voltage
({ x => ..., y => ..., z => ... }, as produced by the
driver's calibrate).
Example:
my $adc = $pi->adc(model => 'ADS1115');
my $accel = $pi->accelerometer(
adc => $adc,
x => 0,
y => 1,
z => 2,
);
my ($gx, $gy, $gz) = $accel->g; # Acceleration, in g
my ($pitch, $roll) = $accel->tilt; # Tilt, in degreesSee the linked documentation for the full method set, or the RPi::WiringPi::FAQ for usage examples.
There are two different ADCs that you can select from. The default is the ADS1x15 series:
Returns a RPi::ADC::ADS object, which allows you to read the four analog input channels on an Adafruit ADS1xxx analog to digital converter.
Parameters:
The default (no parameters) is almost always enough, but please do review the documentation in the link above for further information, and have a look at the ADC tutorial section in this distribution.
You can also use an RPi::ADC::MCP3008 ADC.
Parameters:
model => 'MCP3008'Mandatory, String. The exact quoted string above.
channel => $channelMandatory, Integer. 0 or 1 for the Pi's onboard hardware CS/SS CE0 and CE1
pins, or any GPIO number above 1 in order to use an arbitrary GPIO pin for
the CS pin, and we'll do the bit-banging of the SPI bus automatically.
Returns a RPi::BMP180 object, which allows you to return the current temperature in farenheit or celcius, along with the ability to retrieve the barometric pressure in kPa.
Parameters:
$pin_baseMandatory, Integer. The number at which to start the 'pseudo' GPIO pins used to
communicate with the sensor. Use any value above the highest-numbered physical
GPIO pin (eg. 100 or 200). See "new" in RPi::BMP180 for details.
Returns a RPi::DAC::MCP4922 object (supports all 49x2 series DACs). These chips provide analog output signals from the Pi's digital output. Please see the documentation of that module for further information on both the configuration and use of the DAC object.
Parameters:
model => 'MCP4922'Optional, String. The model of the DAC you're using. Defaults to MCP4922.
channel => 0|1Mandatory, Bool. The SPI channel to use.
cs => $pinMandatory, Integer. A valid GPIO pin that the DAC's Chip Select is connected to.
There are a handful of other parameters that aren't required. For those, please refer to the RPi::DAC::MCP4922 documentation.
Returns a RPi::DigiPot::MCP4XXXX object, which allows you to manage a digital potentiometer (only the MCP4XXXX versions are currently supported).
See the linked documentation for full documentation on usage, or the RPi::WiringPi::FAQ for usage examples.
Returns a GPSD::Parse object, allowing you to track your location.
The GPS distribution requires gpsd to be installed and running. All
parameters for the GPS can be sent in here and we'll pass them along. Please see
the link above for the full documentation on that module.
Returns an RPi::Gyro::MPU6050 object for an MPU-6050 six-axis (accelerometer + gyroscope) IMU on the I2C bus. It reads tilt angle from gravity, angular rate from the gyroscope, and die temperature, with software gyro calibration and a deadband smoothing filter.
All parameters are passed straight through to the driver's constructor; all are optional:
device => $strOptional, String: The I2C device path. Defaults to /dev/i2c-1.
addr => $intOptional, Integer: The I2C address, 0x68 (AD0 low, the default) or 0x69
(AD0 high).
accel_range => $int
gyro_range => $intOptional, Integer: The full-scale accelerometer range (2, 4, 8 or
16 g) and gyroscope range (250, 500, 1000 or 2000 deg/s). Each
defaults to the chip's most sensitive setting.
gyro_offsets => $hrefOptional, Hash Reference: Per-axis gyro zero-rate offsets ({ x => ..., y => ..., z => ... }), as produced by the driver's
calibrate_gyro.
See the linked documentation for the full method set, or the RPi::WiringPi::FAQ for usage examples.
Returns a RPi::HCSR04 ultrasonic distance measurement sensor object, allowing you to retrieve the distance from the sensor in inches, centimetres or raw data.
Parameters:
$trigMandatory, Integer: The trigger pin number, in GPIO numbering scheme.
$echoMandatory, Integer: The echo pin number, in GPIO numbering scheme.
Returns a RPi::DHT11 temperature/humidity sensor object, allows you to fetch the temperature (celcius or farenheit) as well as the current humidity level.
Parameters:
$pinMandatory, Integer: The GPIO pin the sensor is connected to.
Creates a new RPi::I2C device object which allows you to communicate with the devices on an I2C bus.
See the linked documentation for full documentation on usage, or the RPi::WiringPi::FAQ for usage examples.
Aruino note: If using I2C with an Arduino, the Pi may speak faster than the Arduino can. If this is the case, try lowering the I2C bus speed on the Pi:
dtparam=i2c_arm_baudrate=10000Returns a RPi::LCD object for an HD44780-compatible character LCD. Two wiring schemes are supported; see RPi::LCD for the display methods.
Parallel (direct GPIO) - drive the LCD's control and data lines straight from the Pi's GPIO. Send the pin configuration (BCM numbers) plus geometry:
my $lcd = $pi->lcd(
rows => 4, cols => 20, bits => 4,
rs => 5, strb => 6,
d0 => 4, d1 => 17, d2 => 27, d3 => 22,
d4 => 0, d5 => 0, d6 => 0, d7 => 0,
);I2C backpack (PCF8574) - for an LCD behind a PCF8574 I2C backpack, pass
i2c with the backpack's address instead of any pin configuration:
my $lcd = $pi->lcd(i2c => 0x27, rows => 4, cols => 20);We register the backpack's eight expander pins as virtual GPIOs (standard
wiring: P0=RS, P1=RW, P2=E, P3=backlight, P4-P7=D4-D7) and drive the panel
through the same path as a parallel LCD. The backlight comes on automatically
and can be switched with $lcd->backlight(0|1) (see "backlight" in RPi::LCD).
I2C-mode parameters: i2c (mandatory, the backpack address, an integer
0x03-0x77, e.g. 0x27 or 0x3F); rows and cols (mandatory, the panel
geometry); and pin_base (optional, integer >= 64, default 64 - the wiringPi
virtual-pin base for the expander; change it only if it collides with another
pin extension). I2C mode is 4-bit and takes no GPIO pin params.
Returns a specific RPi::OLED::SSD1306 OLED display object, allowing you to
display text, characters and shapes to the screen.
Currently, only the 128x64 size model is offered, see the
RPi::OLED::SSD1306::128_64 documentation for full usage details.
Parameters:
$modelOptional, String: The screen size of the OLED you've got. Valid options are
128x64, 128x32 and 96x16. Currently, only the 128x64 option is
valid, and it's the default if not sent in.
$i2c_addrOptional, Integer: The I2C address of your display. Defaults to 0x3C if not
sent in.
$display_splash_pageOptional, Bool: Whether to display the splash page when the display is
initialized. Defaults to true (1); send in 0 to skip it.
Returns a RPi::Pin object, mapped to a specified GPIO pin, which you can then perform operations on. See that documentation for full usage details.
Parameters:
$pin_numMandatory, Integer: The pin number to attach to.
$commentOptional, String: A label stored alongside the pin's registration (visible in the metadata store and used by the test suite). Defaults to none.
Returns an RPi::Radar::RCWL0516 object for an RCWL-0516 microwave motion
sensor, which drives its OUT pin high while it detects movement. See the
RPi::Radar::RCWL0516 documentation for full usage details.
Parameters:
pinMandatory, Integer: The BCM GPIO pin wired to the sensor's OUT terminal.
pollOptional, Float: The interval, in seconds, between reads when polling with
wait_for_motion/wait_for_clear. Defaults to 0.1.
Example:
my $radar = $pi->radar(pin => 7);
if ($radar->motion){
print "movement detected\n";
}
$radar->wait_for_motion; # block until movement
$radar->wait_for_clear(10); # then until clear, or 10s elapseCreates a new RPi::RTC::DS3231 object which provides access to the DS3231
or DS1307 real-time clock modules.
See the linked documentation for full documentation on usage, or the RPi::WiringPi::FAQ for some usage examples.
Parameters:
$i2c_addrOptional, Integer: The I2C address of the RTC module. Defaults to 0x68 for
the DS3231 unit.
Creates and returns a new EEPROM object for reading and writing to. Defaults to
an RPi::EEPROM::AT24C32 (4 KB, addresses 0-4095, default i2c address
0x57); pass chip => 'AT24C256' to get an RPi::EEPROM::AT24C256
instead (32 KB, addresses 0-32767, default i2c address 0x50).
Parameters:
chip => 'AT24C32'Optional, String. Which EEPROM device to instantiate; one of AT24C32
(the default) or AT24C256.
All remaining parameters are passed through to the selected device's
constructor. Each chip supplies its own address/device/delay defaults
(notably the differing default i2c address above), all of which you may
override:
# AT24C32 at its default 0x57
my $eeprom = $pi->eeprom;
# AT24C256 at its default 0x50
my $eeprom = $pi->eeprom(chip => 'AT24C256');
# AT24C256 at a strapped address
my $eeprom = $pi->eeprom(chip => 'AT24C256', address => 0x51);See the linked documentation for full documentation on usage, parameters or the RPi::WiringPi::FAQ for some usage examples.
Creates a new RPi::GPIOExpander::MCP23017 GPIO expander chip object. This adds an additional 16 pins across two banks (8 pins per bank).
See the linked documentation for full documentation on usage, or the RPi::WiringPi::FAQ for some usage examples.
Parameters:
$i2c_addrOptional, Integer: The I2C address of the device. Defaults to 0x20.
$expanderOptional, String: The GPIO expander device type. Defaults to MCP23017, and
currently, this is the only option available.
Creates a new RPi::Serial object which allows basic read/write access to a serial bus.
See the linked documentation for full documentation on usage, or the 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 (/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-overlayOn 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.
This method configures PWM clock and divisor to operate a typical 50Hz servo,
and returns a special RPi::Pin 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:
$pin_numMandatory, Integer: The pin number (technically, this *must* be 18 on the
Raspberry Pi 3, as that's the only hardware PWM pin.
%pwm_configOptional, Hash. This parameter should only be used if you know what you're doing and are having very specific issues.
Keys are clock with a value that coincides with the PWM clock speed. It
defaults to 192. The other key is range, the value being an integer that
sets the range of the PWM. Defaults to 2000.
Example:
my $servo = $pi->servo(18);
$servo->pwm(50); # all the way left
$servo->pwm(250); # all the way rightAllows you to access the output pins of up to four 74HC595 shift registers in series, for a total of eight new output pins per register. Numerous chains of four registers are permitted, each chain uses three GPIO pins.
Parameters:
$baseMandatory: Integer, represents the number at which you want to start
referencing the new output pins attached to the register(s). For example, if
you use 100 here, output pin 0 of the register will be 100, output
1 will be 101 etc.
$num_pinsMandatory: Integer, the number of output pins on the registers you want to use. Each register has eight outputs, so if you have a single register in use, the maximum number of additional pins would be eight.
$dataMandatory: Integer, the GPIO pin number attached to the DS pin (14) on the
shift register.
$clkMandatory: Integer, the GPIO pin number attached to the SHCP pin (11) on the
shift register.
$latchMandatory: Integer, the GPIO pin number attached to the STCP pin (12) on the
shift register.
Creates a new RPi::SPI object which allows you to communicate on the Serial Peripheral Interface (SPI) bus with attached devices.
See the linked documentation for full documentation on usage, or the RPi::WiringPi::FAQ for usage examples.
Creates a stepper motor driver object. Two drivers are supported, selected
by the model parameter:
ULN2003 (the default) - an RPi::StepperMotor object driving a
28BYJ-48 unipolar motor through a ULN2003.A4988 - an RPi::StepperMotor::A4988 object driving a bipolar
motor through an Allegro A4988 microstepping driver, with software microstep
selection and power-state control.Both drivers can run either straight off the Pi's GPIO header, or off an
RPi::GPIOExpander::MCP23017 passed as the expander param, in which case
the pin numbers name the expander's 0-15 lines instead of Pi GPIOs.
See the linked driver documentation for full usage instructions and every optional parameter. The common parameters are:
model => 'ULN2003'|'A4988'Optional, String: Which driver to build. Defaults to ULN2003 (the original
28BYJ-48 driver). Case-insensitive.
expander => $objectOptional, Object: An RPi::GPIOExpander::MCP23017 instance (see "expander"). When supplied, the motor is driven from the expander's pins rather than the Pi's own GPIO.
ULN2003 parameters
pins => $arefMandatory, Array Reference: The ULN2003 has four data pins, IN1, IN2, IN3 and IN4. Send in the GPIO pin numbers in the array reference which correlate to the driver pins in the listed order.
speed => 'half'|'full'Optional, String: By default we run in "half speed" mode. Essentially, in this mode we run through all eight steps. Send in 'full' to double the speed of the motor. We do this by skipping every other step.
delay => Float|IntOptional, Float or Int: By default, between each step, we delay by 0.01
seconds. Send in a float or integer for the number of seconds to delay each step
by. The smaller this number, the faster the motor will turn.
A4988 parameters
step => $int
dir => $intMandatory, Integer: The GPIO (or expander) pins wired to the A4988's STEP
and DIR inputs.
ms1 => $int
ms2 => $int
ms3 => $intOptional, Integer: The pins wired to the microstep-select inputs, all three together or none. With them wired, the resolution is selectable from software.
enable => $int
sleep => $int
reset => $intOptional, Integer: The pins wired to the active-low ENABLE, SLEEP and
RESET lines, enabling the matching power-state methods.
rpm => $num
steps_per_rev => $int
mode => $strOptional: The stepping speed in motor RPM (default 60), the motor's full
steps per revolution (default 200), and the initial microstep resolution
(full, half, quarter, eighth or sixteenth; default full).
Example:
my $sm = $pi->stepper_motor(
model => 'A4988',
step => 23,
dir => 24,
ms1 => 17,
ms2 => 27,
ms3 => 22,
rpm => 120,
);
$sm->cw(360); # One full turn clockwise
$sm->mode('sixteenth');
$sm->ccw(90);Returns an RPi::TFT::ST7735S object for a 1.44" 128x128 RGB TFT LCD driven by the ST7735S controller over the 4-wire SPI bus, allowing you to draw pixels, shapes and text to the screen in 16-bit colour.
See the RPi::TFT::ST7735S documentation for full usage details and every optional parameter. The common ones:
modelOptional, String: Which controller to build. Defaults to ST7735S, the only
one currently supported. Case-insensitive.
dcMandatory, Integer: The GPIO pin wired to the display's D/C (data/command)
line.
channelOptional, Integer or hashref. Default 0. The SPI channel: 0 or 1 for
the hardware chip select pins CE0/CE1, any GPIO pin above 1 to use as
the chip select instead, or a hashref of RPi::SPI bit-bang parameters.
rstOptional, Integer: The GPIO pin wired to the display's RES reset line.
blOptional, Integer: The GPIO pin wired to the display's BLK backlight line.
Example:
my $tft = $pi->tft(
dc => 25,
rst => 24,
bl => 23,
);
$tft->clear;
$tft->fill_screen(0x001F); # blue
$tft->string(6, 6, "Hello, Pi!", 0xFFFF, 0x0000);Core methods are inherited in and documented in RPi::WiringPi::Core. See that documentation for full details of each one. I've included a basic description of them here.
Returns the GPIO layout, which in essence is the Pi board revision number.
Turn the disk IO (green) LED on or off.
Turn the power (red) LED on or off.
Toggles the power led off and disk IO led on which allows external physical identification of the Pi you're running on.
Sets an internal label/name to your RPi::WiringPi Pi object.
Returns the current pin mapping scheme in use within the object.
Returns a hash reference mapping of the physical pin numbers to a pin scheme's pin numbers.
Converts a pin number from any non-GPIO (BCM) scheme to GPIO (BCM) scheme.
Converts a wiringPi pin number to GPIO pin number.
Converts a physical pin number to the GPIO pin number.
Set/get the PWM range.
Set/get the PWM mode.
Set/get the PWM clock.
Returns an array reference of all pin numbers currently registered in the system. Used primarily for cleanup functionality.
Registers a pin with the system for error checking, and proper resetting in the cleanup routines.
Removes an already registered pin.
Cleans up the entire system, resetting all pins and devices back to the state
we found them in when we initialized the system. It also releases any armed
interrupts (via WiringPi::API::stop_interrupts()) - stopping the wiringPi
ISR threads and closing the event pipe - so you don't have to do that yourself
at teardown.
Only the process that created the object performs the cleanup: in a forked child the call is a no-op, so a child can't reset pins or mutate the shared metadata on the parent's behalf when it exits.
We also include in the Pi object several hardware-type methods brought in from RPi::SysInfo. They are loaded through RPi::WiringPi::Core via inheritance. See the RPi::SysInfo documentation for full method details.
my $mem_percent = $pi->mem_percent;
my $cpu_percent = $pi->cpu_percent;
my $cpu_temp = $pi->core_temp;
my $gpio_info = $pi->gpio_info;
my $raspi_conf = $pi->raspi_config;
my $net_info = $pi->network_info;
my $file_system = $pi->file_system;
my $hw_details = $pi->pi_details;Returns the current CPU usage.
Returns the current memory usage.
Returns the current temperature of the CPU core.
Returns the current status and configuration of one, many or all of the GPIO pins.
Returns the live vcgencmd get_config values plus the non-comment directives
from the active config.txt (/boot/firmware/config.txt on Bookworm and
later, falling back to /boot/config.txt on older releases).
Returns the network configuration of the Pi, via ifconfig where the
net-tools package is installed, falling back to ip addr where it is not
(as on current Raspberry Pi OS Lite).
Returns current disk and mount information.
Returns various information on both the hardware and OS aspects of the Pi.
Returns the normalized Raspberry Pi board name (eg. Raspberry Pi 5 Model B Rev 1.1), read from the devicetree model with a /proc/cpuinfo revision-code
decode fallback. Works across the Pi 0 through 5.
Arm an interrupt on a pin with $pin->set_interrupt($edge, $callback)
(see RPi::Pin). As of WiringPi::API 3.18 the callback must be a code
reference, and it runs in your own interpreter when you service the interrupt
rather than in the wiringPi ISR thread. The following methods drive that
dispatch. See Interrupt usage in the
FAQ for a complete example.
Blocks until an edge arrives or $timeout_ms milliseconds elapse, then runs
all pending interrupt callbacks. Returns the number of callbacks dispatched.
Call it in a loop to handle interrupts:
$pi->wait_interrupts(1000) while 1;A blocking dispatch loop, so you don't have to write the
wait_interrupts ... while 1 yourself. Repeatedly dispatches and returns
the total number of events handled. It runs until $pi->stop_interrupt_loop
is called (from a callback or a signal handler) or, if you pass $max, until
that many events have been dispatched.
$pi->run_interrupt_loop; # block, dispatching, until stop_interrupt_loopParameters:
$timeout_msOptional, Integer: The per-iteration poll granularity in milliseconds (how long
each underlying wait_interrupts blocks waiting for an edge). Defaults to
1000.
$maxOptional, Integer: The maximum number of events to dispatch before returning. If
omitted, the loop only ends when $pi->stop_interrupt_loop is called.
Breaks out of run_interrupt_loop at the next iteration. Safe to call from a
callback or a signal handler.
Runs all pending interrupt callbacks without blocking, and returns the number
dispatched. Use this instead of wait_interrupts when you already block
elsewhere (eg. in your own event loop).
Releases every armed interrupt: stops the wiringPi ISR threads and closes the
event pipe. The object's cleanup calls this for you automatically, so you
only need it to disarm interrupts while the program keeps running.
Returns a hash reference describing the most recently dispatched interrupt event
- { pin, pin_bcm, edge, status, ts_us } - or undef if none has fired yet.
Because the callback only receives ($edge, $timestamp_us), this lets it (or
your main loop) recover the BCM pin and status; useful when one handler is armed
on several pins. Like auto_dispatch_interrupts, it reports a process-wide
value (the last event on any pin), so it lives on the Pi object.
Enables (1) or disables (0) async auto-dispatch for the whole process.
When enabled, $pin->set_interrupt callbacks fire automatically at Perl
safe points (via SIGIO) with no wait_interrupts/dispatch_interrupts
loop, and may touch your program's variables with no locking. The optional
$signal picks the delivery signal (default SIGIO; pass eg 'USR1' to
avoid clashing with other SIGIO users). This is a
process-global switch (it affects every armed pin), which is why it lives on the
Pi object rather than on an individual pin. A long, non-yielding C/XS call defers
the callback until it returns - use $pin->background_interrupt (see
RPi::Pin) if you need it to fire even then.
Gets (no argument) or sets the capacity of the interrupt queue - the kernel pipe
that absorbs edge bursts. On overflow the newest edges are dropped (never merged
or blocked) and counted, so raise this if a fast source outpaces your dispatch.
May be set before arming and persists across teardown. Process-wide, so it lives
on the Pi object. See interrupt_buffer in WiringPi::API for details.
Returns the running total of interrupt events dropped because the queue (see
interrupt_buffer) overflowed. A non-zero count means a source is outpacing
your dispatch - raise interrupt_buffer or dispatch more often. Process-wide,
so it lives on the Pi object. See interrupt_dropped in WiringPi::API for
details.
Handles many pins in a single background child (rather than one child per
pin via $pin->background_interrupt). Pass one array-ref spec per pin; the
returned handle adds $h->arm($pin) / $h->disarm($pin) (toggling
pins registered at creation) to the usual stop/pid/running. Because it
spans several pins it lives on the Pi object, not on a single pin. See
background_interrupts in WiringPi::API for details.
Dependency note: the per-pin $pin->background_interrupt form referenced
above requires RPi::Pin 3.1802 or greater (the version this distribution
already requires). To drive multiple pins from a single background child rather
than one child per pin, use this $pi->background_interrupts method.
Runs \&body as a hands-off background task, hiding the spawn mechanism, the
loop, and the lifecycle - the GPIO sibling of background_interrupts. By
default it forks a child (no use threads required) that runs body
repeatedly, and returns a WiringPi::API::Worker handle:
pin_mode(2, 1); # OUTPUT, once in main
my $w = $pi->worker(sub {
digital_write(2, 1); sleep 1;
digital_write(2, 0); sleep 1;
});
# ... main does its own work ...
$w->stop; # idempotentThe handle carries $w->stop (idempotent), $w->pid, and
$w->running, matching the interrupt handle. You normally need not call
stop at all: $pi->cleanup (and therefore DESTROY) automatically
stops every worker started through this method, and a forked child never reaps
the parent's workers.
\%opts mirrors WiringPi::API::worker() exactly:
once => 1 - run body a single time instead of looping.interval => $secs - pace each pass (periodic sampler/blink)
instead of letting body set its own cadence.shared => 1 - publish body's return value as a lossy latest
value; read it from the parent with $w->value.results => 1 - stream every defined return value back; drain it
with $w->read or select on $w->fh.mechanism => 'fork' | 'thread' - default fork (works on any
Perl). thread uses an ithread for shared-memory ergonomics and requires
threads to be loaded (croaks otherwise). Under thread mode, serialise
shared GPIO access yourself with WiringPi::API::pi_lock /
WiringPi::API::pi_unlock; the fork default never locks. See
RPi::WiringPi::WORKERS for the full OO threads/worker story.All argument validation happens in the low-level layer, so an invalid body,
interval, or mechanism croaks before anything is spawned. See
worker in WiringPi::API and RPi::WiringPi::WORKERS for full details.
Please see RUNNING TESTS in the FAQ.
Please read through the SETUP section in the FAQ.
Steve Bertrand, steveb@cpan.org
Copyright (C) 2016-2026 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.
| Qty | Value | Footprint | References |
|---|---|---|---|
| 4 | 330 | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P7.62mm_Horizontal | R1, R2, R3, R4 |
| 4 | MH_2.2mm_M2 | MountingHole:MountingHole_2.2mm_M2 | MH1, MH2, MH3, MH4 |
| 2 | 0.1 µF | Capacitor_THT:C_Disc_D5.0mm_W2.5mm_P2.50mm | C1, C2 |
| 2 | 4K7 | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P7.62mm_Horizontal | R5, R6 |
| 1 | 10 µF | Capacitor_THT:CP_Radial_D5.0mm_P2.50mm | C3 |
| 1 | JST_IN_PWR | Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_Vertical | J1 |
| 1 | JST_IN_SIG | Connector_JST:JST_XH_B5B-XH-A_1x05_P2.50mm_Vertical | J2 |
| 1 | JST_IO_A4_7 | Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_Vertical | J6 |
| 1 | JST_IO_B0_3 | Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_Vertical | J7 |
| 1 | JST_IO_B4_7 | Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_Vertical | J8 |
| 1 | JST_OUT_COIL | Connector_JST:JST_XH_B4B-XH-A_1x04_P2.50mm_Vertical | J5 |
| 1 | JST_OUT_PWR | Connector_JST:JST_XH_B3B-XH-A_1x03_P2.50mm_Vertical | J3 |
| 1 | JST_OUT_SW | Connector_JST:JST_XH_B2B-XH-A_1x02_P2.50mm_Vertical | J4 |
| 1 | LED_BRD_CONN | LED_THT:LED_D5.0mm | D4 |
| 1 | LED_CCW | LED_THT:LED_D5.0mm | D2 |
| 1 | LED_CENTRE | LED_THT:LED_D5.0mm | D3 |
| 1 | LED_CW | LED_THT:LED_D5.0mm | D1 |
| 1 | LED_SW | Button_Switch_THT:SW_DIP_SPSTx04_Slide_6.7x11.72mm_W7.62mm_P2.54mm_LowProfile | SW1 |
| 1 | MCP23017_0x20 | Package_DIP:DIP-28_W7.62mm | U1 |
| 1 | MCP23017_0x21 | Package_DIP:DIP-28_W7.62mm | U2 |

stevieb9/rpi-wiringpi
Perl interface to Raspberry Pi's board, GPIO and various sensors and ICs

stevieb9/rpi-wiringpi
Perl interface to Raspberry Pi's board, GPIO and various sensors and ICs

stevieb9/rpi-wiringpi
Perl interface to Raspberry Pi's board, GPIO and various sensors and ICs

joeycastillo/Sensor-Watch
A board replacement for the classic Casio F-91W wristwatch

TalismanDesign/PocketMage_PDA
An E-Ink PDA device using the ESP32 S3.

rusefi/rusefi
rusefi - GPL internal combustion engine control unit

hackclub/OnBoard
💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

asterics/esp32_mouse_keyboard
ESP32 implementation for HID over GATT Keyboard and Mouse (Bluetooth Low Energy). Including serial API for external modules (similar to Adafruit EZKey HID)


Luos-io/luos_engine
Open-source and real-time orchestrator for cyber-physical-systems, to easily design, test and deploy embedded applications and digital twins.

Chrismettal/EleLab_v2
Cheap DIY lab system for hobbyists and the tinkering folk
It measures 91.4 × 67.9 mm and has 2 copper layers, 1.6 mm thick.
28 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
From the stevieb9/rpi-wiringpi repository on GitHub, at the commit this page was made from: the board is docs/test-platform/kicad/rpi-wiringpi-unit-test-platform-board-3/rpi-wiringpi-unit-test-platform-board-3.kicad_pcb and its schematic docs/test-platform/kicad/rpi-wiringpi-unit-test-platform-board-2/rpi-wiringpi-unit-test-platform-board-2.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Its repository states no licence, so its author keeps all rights: ask stevieb9 before reusing the design.