HiPi::MCP23017
Version 0.01
use HiPi::Constant qw( :mcp23017 ); use HiPi::MCP23017; my $mcp = HiPi::MCP23017->new; my @bits = (0,0,0,0,0,0,0,0); # set all pins on port A as output $mcp->write_register_bits('IODIRA', @bits); # set level of all pins on port A low $mcp->write_register_bits('GPIOA', @bits); # set level of port A pin 7 high @bits = $mcp->read_register_bits('GPIOA'); $bits[7] = 1; $mcp->write_register_bits('GPIOA', @bits); # check level of port A pin 3 @bits = $mcp->read_register_bits('GPIOA'); my $val = $bits[3];
This module provides an interface to the popular MCP23017 IO expander. (The I2C version )
my $mcp = HiPi::MCP23017->new; my $mcp = HiPi::MCP23017->new( { i2caddress => 0x20, devicename => '/dev/i2c-1' } );
$mcp->write_register_bits($register, @bits);
Write an array of 8 bit values ( 0 or 1 ) to the specified register.
$bits[0] is written to register bit 0
$bits[7] is written to register bit 7
Valid values for $register are the register names:
'IODIRA', 'IPOLA', 'GPINTENA', 'DEFVALA', INTCONA', 'IOCON', 'GPPUA', 'INTFA', 'INTCAPA', 'GPIOA','OLATA', 'IODIRB', 'IPOLB', 'GPINTENB', 'DEFVALB', 'INTCONB', 'GPPUB', 'INTFB', 'INTCAPB', 'GPIOB','OLATB'
my @bits = $mcp->write_register_bits($register);
Read an array of 8 bit values ( 0 or 1 ) from the specified register.
$bits[0] is populated from register bit 0
$bits[7] is populated from register bit 7
This work is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.
I would normally release any Perl code under the Perl Artistic License but this module wraps several GPL / LGPL C libraries and I feel that the licensing of the entire distribution is simpler if the Perl code is under GPL too.
Mark Dootson, <mdootson at cpan.org>
<mdootson at cpan.org>
Copyright (C) 2012-2013 Mark Dootson, all rights reserved.
To install HiPi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HiPi
CPAN shell
perl -MCPAN -e shell install HiPi
For more information on module installation, please visit the detailed CPAN module installation guide.