Contents Up Previous Next

HiPi::Interface::MCP3004

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

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

Object Constructor and Methods

my $adc = HiPi::Interface::MCP3004->new( %params );
    Returns a new instance of the HiPi::Interface::MCP3004 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 MCP3004
    
    For SPI0_CEO_N
    my $adc = HiPi::Interface::MCP3004->new(
        devicename   => '/dev/spidev0.0',
    );

    For SPI0_CE1_N
    my $adc = HiPi::Interface::MCP3004->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 MCP3004 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

    MCP3004_S0         # single-ended CH0
    MCP3004_S1         # single-ended CH1
    MCP3004_S2         # single-ended CH2
    MCP3004_S3         # single-ended CH3
    MCP3004_DIFF_0_1   # differential +CH0 -CH1
    MCP3004_DIFF_1_0   # differential -CH0 +CH1
    MCP3004_DIFF_2_3   # differential +CH2 -CH3
    MCP3004_DIFF_3_2   # differential -CH2 +CH3

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




Contents Up Previous Next


HiPi Modules Copyright © 2013 Mark Dootson