Contents Up Previous Next

HiPi::Interface::MCP3008

This module provides an interface to the MCP3008 analog to digital converter with SPI interface.

It uses HiPi::Device::SPI as a backend

Object Constructor and Methods

my $adc = HiPi::Interface::MCP3008->new( %params );
    Returns a new instance of the HiPi::Interface::MCP3008 class.

    Optional key => values pairs in %params and their defaults:
    The parameters are all passed through to HiPi::Device::SPI

    devicename   => '/dev/spidev0.0',
    speed        => SPI_SPEED_MHZ_1,
    bitsperword  => 8,
    delay        => 0,
    
    You probably want to specify the devicename explicitly depending
    on which cable select pin you have connected the MCP3008
    
    For SPI0_CEO_N
    my $adc = HiPi::Interface::MCP3008->new(
        devicename   => '/dev/spidev0.0',
    );

    For SPI0_CE1_N
    my $adc = HiPi::Interface::MCP3008->new(
        devicename   => '/dev/spidev0.1',
    );

    See  Raspberry Pi GPIO Pin layout for pin locations.
my $value = $adc->read( $mode );
    $mode is the seven bit mask described as the configure bits
    in the MCP3008 datasheet that determines the channel and 
    read mode for the returned value.

    For convenience the module exports the following constants that
    you can pass as a value for $mode

    MCP3008_S0         # single-ended CH0
    MCP3008_S1         # single-ended CH1
    MCP3008_S2         # single-ended CH2
    MCP3008_S3         # single-ended CH3
    MCP3008_S4         # single-ended CH4
    MCP3008_S5         # single-ended CH5
    MCP3008_S6         # single-ended CH6
    MCP3008_S7         # single-ended CH7
    MCP3008_DIFF_0_1   # differential +CH0 -CH1
    MCP3008_DIFF_1_0   # differential -CH0 +CH1
    MCP3008_DIFF_2_3   # differential +CH2 -CH3
    MCP3008_DIFF_3_2   # differential -CH2 +CH3
    MCP3008_DIFF_4_5   # differential +CH4 -CH5
    MCP3008_DIFF_5_4   # differential -CH4 +CH5
    MCP3008_DIFF_6_7   # differential +CH6 -CH7
    MCP3008_DIFF_7_6   # differential -CH6 +CH7 

    You can import these constants into your namespace with
    
    use HiPi::Interface::MCP3008 qw( :mcp );




Contents Up Previous Next


HiPi Modules Copyright © 2013 Mark Dootson