The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HiPi::MCP23017

VERSION

Version 0.01

SYNOPSYS

    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];

DESCRIPTION

This module provides an interface to the popular MCP23017 IO expander. (The I2C version )

METHODS

new

    my $mcp = HiPi::MCP23017->new;
    
    my $mcp = HiPi::MCP23017->new( {
        i2caddress   => 0x20,
        devicename   => '/dev/i2c-1' } );

write_register_bits

    $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'

read_register_bits

    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

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'

LICENSE

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.

License Note

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.

AUTHOR

Mark Dootson, <mdootson at cpan.org>

COPYRIGHT

Copyright (C) 2012-2013 Mark Dootson, all rights reserved.