Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Blogs > drask
User Name


Rate this Entry

WiringPi-Perl example

Posted 08-12-2013 at 10:11 PM by drask
Updated 08-16-2013 at 02:11 PM by drask

This is a Raspberry Pi project I did a few months ago and meant to post somewhere. There is a Perl interface to the WiringPi module. It's available from Unfortunately it doesn't come with any examples, but the WiringPi module comes with some nice examples. Unfortunately they are all written in C and it can take some trial and error to translate and I never found any translations of the examples online, or any WiringPi-Perl specific examples.

Here is my version of test1.c translated to Perl (flashes a series of 8 LEDs back and forth like Knight Rider's grill or a 1970's Cylon eyeball, a button allows you to speed up the action):

use wiringpi;
use constant {


print("Raspberry Pi wiringPi test program\n");
if( wiringpi::wiringPiSetup()==-1 ){
	die 1;

for( my $pin=0;$pin<8;++$pin ){



my $inc=0;

while( 1==1 ){
	my( $pin,$state,$duration )=@{$data[$inc]};
	if( $pin+$state+$duration==27 ){
	if( wiringpi::digitalRead(8)==LOW ){
		wiringpi::delay( $duration*100 );

# this just turns off all the LEDs when you exit the script
sub safe_exit{
	for( my $pin=0;$pin<8;++$pin ){
	exit 1;
Unfortunately, you have to run this as root, which seems to common to all WiringPi versions. After compiling the C code, you can suid the program and just run it directly as a normal user, so you can compile it and then let your kids run it, but working in Perl is fun.

I'll attach a link to a schematic in the next couple of days, since I felt like the original script could have used one (the schematic is the same for both test1.c and I'm using a Pi Cobbler from Adafruit to connect the Pi to my breadboard, which has made test wiring much easier for me.
Posted in Uncategorized
Views 3310 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 02:02 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration