Converting voltage input for Arduino to read using external ADC MCP3002

Hello,

I’m using MCP3002 ADC to convert the analog voltage input to digital for arduino but i dont know how to program it.
Can some one help me with programming the arduino to do the converstion.

I have found this code but it reads zero all the way.

// MCP3002 - Example code using Arduino UNO.
// March 17,2013
// Wiring
//    Pin 10 to /CS
//    Pin 11 to Din
//    Pin 12 to Dout
//    Pin 13 to CLK
//
// Do a conversion on both channels and write results to serial port.
//
// Include the SPI library:
#include <SPI.h>

// Set pin 10 as the slave select for A/D converter
const int slaveSelect = 10;

void setup()
{
// Initialize serial port for com to host
Serial.begin (9600);
// Set the slave select pin as an output
pinMode (slaveSelect, OUTPUT);
// Initialize SPI
SPI.begin();
SPI.setBitOrder (MSBFIRST);
}

void loop()
{
// Going to be doing a conversion on both channels (ch0,ch1)
byte conversionMSB,conversionLSB;
word chA,chB;
digitalWrite (slaveSelect,LOW);

// Communication with the device starts when /CS line brought low.
// The first '1' bit transmitted is the start bit.
// The next 3 bits define
//    Single Ended Input / Differential Input
//    Ch0 / Ch1 if single ended input or polarity if differential
//    MSBF / LSBF (Most/Least Significan Bit First)
// The returned value is ten bits long so if the bit pattern transmitted
// is placed correctly, the two most significant bits will be sent back
// with the first transfer. the rest on the second transfer.
conversionMSB = SPI.transfer (0x60);
conversionLSB = SPI.transfer (0);

chA = word (conversionMSB,conversionLSB);
digitalWrite (slaveSelect,HIGH);
Serial.print (chA,DEC);
Serial.print("  ");

Thanks for the help.

How to use this forum - please read

Hello,

I’m using MCP3002 ADC to convert the analog voltage input to digital for arduino but i dont know how to program it.
Can some one help me with programming the arduino to do the converstion.

I have found this code but it reads zero all the way.

// MCP3002 - Example code using Arduino UNO.
// March 17,2013
// Wiring
//    Pin 10 to /CS
//    Pin 11 to Din
//    Pin 12 to Dout
//    Pin 13 to CLK
//
// Do a conversion on both channels and write results to serial port.
//
// Include the SPI library:
#include <SPI.h>

// Set pin 10 as the slave select for A/D converter
const int slaveSelect = 10;

void setup()
{
// Initialize serial port for com to host
Serial.begin (9600);
// Set the slave select pin as an output
pinMode (slaveSelect, OUTPUT);
// Initialize SPI
SPI.begin();
SPI.setBitOrder (MSBFIRST);
}

void loop()
{
// Going to be doing a conversion on both channels (ch0,ch1)
byte conversionMSB,conversionLSB;
word chA,chB;
digitalWrite (slaveSelect,LOW);

// Communication with the device starts when /CS line brought low.
// The first '1' bit transmitted is the start bit.
// The next 3 bits define
//    Single Ended Input / Differential Input
//    Ch0 / Ch1 if single ended input or polarity if differential
//    MSBF / LSBF (Most/Least Significan Bit First)
// The returned value is ten bits long so if the bit pattern transmitted
// is placed correctly, the two most significant bits will be sent back
// with the first transfer. the rest on the second transfer.
conversionMSB = SPI.transfer (0x60);
conversionLSB = SPI.transfer (0);

chA = word (conversionMSB,conversionLSB);
digitalWrite (slaveSelect,HIGH);
Serial.print (chA,DEC);
Serial.print("  ");

Thanks for the help.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What model Arduino are you using?

Thanks.. Tom... :slight_smile:

@FernandoLeite, please do not cross-post. Threads merged.

Yes I know i must not cross post but it was not my objetive. I wanted to post the code with code tags and then delete the first post but could see how to do it.
Sorry

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What model Arduino are you using?

Thanks… Tom… :slight_smile:

Hi,

I’m using arduino Uno. I dont have the circuit with me but i’ve drawn a sketch wich i send as a attachment.

Hi,
OPs diagram;
ae4940702fd879bb1919c5d34836c45c02d73e43.jpg
What is the line you have written under the diagram?
I hope the gnd of the UNO and Vss of the 3002 are connected.
What voltage are you powering th e 3002?

Tom… :slight_smile:

What i wrote was that ch1 is not used and that the VSS and Vdd are the supply contacts. The supply is 5V i think and yes the grounds are connected