Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Raspberry Pi wiringPi API wrapper released

by stevieb (Canon)
on Aug 16, 2016 at 19:06 UTC ( #1169852=CUFP: print w/replies, xml ) Need Help??

I was going to hold off on announcing my new WiringPi::API distribution until my larger project that depends on it is done, but since it's CPAN day, well...

The module wraps the majority of documented and undocumented functions in wiringPi.

wiringPi is a set of C libraries that allow you to muck with a Raspberry Pi, it's GPIO pins, drive LCDs and many other things.

You can import the C functions directly keeping their original names as is:

use WiringPi::API qw(:wiringPi);
...import the renamed Perl functions:
use WiringPi::API qw(:perl);
...or use the module in the normal OO way:
use WiringPi::API; my $wpi = WiringPi::API->new;

Here's but a few of the features:

  • get Pi board revision
  • do conversions for the three pin numbering schemes (wiringPi, BCM and physical)
  • change pin modes and state
  • enable/disable internal pin pull-up/down resistors
  • utilize Pulse Width Modulation (PWM) on a per-pin basis
  • set/unset pin interrupts for EDGE_FALLING, EDGE_RISING and EDGE_BOTH events. These interrupts are run in separate C threads, and call back to a user defined Perl sub as the handler
  • initialize, manipulate and write data to external LCD screens (useful for sensor data, warnings etc)

My larger project, RPi::WiringPi, which is currently in feature-freeze to give me time to finish unit tests and documentation, will take that much further, and make it much easier to do things. It should hit v1.00 (stable) within the next week. At that time, I'll make another announcement... I do have an initial basic howto written so far that covers some of the basics. Note that this distribution may not be stable until v1.00 is released.

This was also posted here.

Replies are listed 'Best First'.
Re: Raspberry Pi wiringPi API wrapper released
by jmlynesjr (Deacon) on Aug 19, 2016 at 02:25 UTC


    Nice work! Do you have any plans to implement any byte-wide I/O functions.


    There's never enough time to do it right, but always enough time to do it over...

      I do, but I'm working on getting the upper layers to work correctly. First, interrupts are failing miserably which I'll try to sort out today. Second, PWM mode doesn't work in non-root user mode, so I am going to implement software PWM for that run mode (with a user warning). Lastly, I need to rewrite the state mechanisms and cleanup routines, as I don't like when a crash happens that pins stay in an inconsistent state.

      Once all those are done, I'll add more features. I've also got a couple of other XS modules that are specific to sensors (DHT11 hygrometer for example) that I need to brush up a little.

      My goal was to get it far enough to be able to create my indoor grow operations environment control centre (which I've pretty well done), but then I thought I'd take it the whole way so that Perl has an easy-to-use implementation of wiringPi that goes beyond just the core library itself (management of components/pins, safe cleanup etc).

      fwiw, the most recent code is here. DHT11 code is RPi::DHT11::EnvControl.


        Thanks for the update. I look forward to following your progress. For speed reasons, in the chipKIT world bytewise operations are used to interface to TFT color displays.


        There's never enough time to do it right, but always enough time to do it over...

Re: Raspberry Pi wiringPi API wrapper released
by marinersk (Priest) on Sep 28, 2016 at 04:03 UTC

    Nice work. I look forward to stealing your code.

      Cheers, marinersk... have a look at RPi::WiringPi. It's another distribution I wrote that uses the API code, but it's more user-friendly (imho) than using the API directly.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1169852]
Approved by beech
Front-paged by beech
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-01-22 18:22 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.