<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>HiPi::Interface::MCP3004</title></head>
<BODY TOPMARGIN=4 BGCOLOR=#FFFFFF TEXT=#000000 VLINK=#0000CC LINK=#0000CC ALINK=#0000CC>
<FONT FACE="Arial, Lucida, Helvetica" >
<TABLE WIDTH="100%" ALIGN=CENTER CELLPADDING=1 CELLSPACING=0>
<TR>
<TD WIDTH="100%" ALIGN=CENTER>
<A HREF="contents.htm"><img align=center src="home.png" BORDER=0 ALT="Contents"></A>
<A HREF="mod_interface.htm"><img align=center src="up.png" BORDER=0 ALT="Up"></A>
<A HREF="mod_interface_htbackpackv2.htm"><img align=center src="back.png" BORDER=0 ALT="Previous"></A>
<A HREF="mod_interface_mcp3008.htm"><img align=center src="forward.png" BORDER=0 ALT="Next"></A>
</TD>
</TR>
<TR>
<TD COLSPAN=2 HEIGHT=2 BGCOLOR="#C0C0C0">
</TD>
</TR>
</TABLE>
<H2>HiPi::Interface::MCP3004</H2><p>This module provides an interface to the MCP3004 analog to digital converter with SPI interface.</p>
<p>It uses <A HREF="mod_device_spi.htm">HiPi::Device::SPI</A> as a backend</p>
<h2>Object Constructor and Methods</h2>
<h5>my $adc = HiPi::Interface::MCP3004->new( %params );</h5>
<pre> 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 <A HREF="topic_gpiopins.htm">Raspberry Pi GPIO Pin layout</A> for pin locations.</pre>
<h5>my $value = $adc->read( $mode );</h5>
<pre> $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 );
</pre>
</FONT>
<br>
<p>
<br>
<hr>
<br>
<center>
<A HREF="contents.htm"><img align=center src="home.png" BORDER=0 ALT="Contents"></A>
<A HREF="mod_interface.htm"><img align=center src="up.png" BORDER=0 ALT="Up"></A>
<A HREF="mod_interface_htbackpackv2.htm"><img align=center src="back.png" BORDER=0 ALT="Previous"></A>
<A HREF="mod_interface_mcp3008.htm"><img align=center src="forward.png" BORDER=0 ALT="Next"></A>
</center>
<HR>
<br>
<center><FONT FACE="Arial, Lucida, Helvetica" size="2" color="#000080">HiPi Modules Copyright © 2013 Mark Dootson</font></center>
</BODY></HTML>