<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>HiPi::Interface::MCP3008</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_mcp3004.htm"><img align=center src="back.png" BORDER=0 ALT="Previous"></A>
<A HREF="mod_interface_mcp23017.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::MCP3008</H2><p>This module provides an interface to the MCP3008 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::MCP3008->new( %params );</h5>
<pre> 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 <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 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 );
</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_mcp3004.htm"><img align=center src="back.png" BORDER=0 ALT="Previous"></A>
<A HREF="mod_interface_mcp23017.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>