MPC3008 CODING

I have breadboarded an MPC3008 to an Arduino UNO.
I am reading a Potentiometer on CH0.
Here is the code:
#include <MCP3XXX.h>
MCP3008 adc;
void setup()
{
Serial.begin(9600);
// Use the default SPI hardware interface.
adc.begin();
// Or use custom pins to use a software SPI interface.
adc.begin(SS, MOSI, MISO, SCK);
}
void loop()
{
for (size_t i = 0; i < adc.numChannels(); ++i)
{
Serial.print(adc.analogRead(i));
if (i == adc.numChannels() - 1)
{
Serial.println();
}
else
{
Serial.print(",");
}
}
delay(10);
}
Here is the Schematic: Attached

I am getting no reading on Ch0. I have checked the wiring over several times and it is correct (and makes sense). I have put Ch0 to +5V and still no reading. I have changed out the MCP3008 twice with no change.

Can anyone see what might be the problem.
Output: 0's across all channels

Well, 13 is SCK, so you seem to have some wiring issues right off the bat.
13 is clock,
12 is MISO (connect to device's Dout
11 is MOSI (connect to device's Din)
and D10 for chip select.

You should also have a 0.1uF capacitor on the devices Vcc pin, to Gnd.

I'm not familiar with that library.
I just wrote my own code to cycle thru the 8 addresses on a MCP3208, which is a 12 bit ADC.

int baseADCaddress = 0x0600; // 600, 640, 680, 6C0, 700, 740, 780, 7C0

  // Elapsed time check for ADC and Switch reading
  if (millis()>=previousMillis){

    previousMillis = previousMillis + 5; // set for next 5 mS interval

    // read ADC with 3 byte transfer
    PORTB = PORTB & B11111011;  // ADC_SS, LOW
    // ADCaddress = 0x0600, 640, 680, 6C0, 700, 740, 780, 7C0
    dummyADC = SPI.transfer (highByte(ADCaddress));  // 0x06, 0x07 out, read in dummy data
    highADC = SPI.transfer (lowByte(ADCaddress));    // 0x00, 0x40, 0x80, 0xC0, read in upper 4 bits
    lowADC = SPI.transfer (0);              // dummy 0 byte out , read in lower 8 bits
    PORTB = PORTB | B00000100; // ADC_SS, HIGH

    // send the data out

    Serial.write (ADCsyncbyte);      // syncbyte = B00110011, 0x33
    // bits 4-3-2 = 0 when switch pressed. Invert them.  Leave bits 1-0 alone. No bits 7-6. Bit 5 not used.
    Serial.write (PINC ^ B0011100);   // 3 switches on Port C, make them 1 if 0 (1 EXOR 1 = 0, 0 EXOR 1 = 1, 0 EXOR 0 = 0
    Serial.write (address_count);    // find way to put this in top nibble of next command?
    Serial.write (highADC & 0x0F);   // send it out
    Serial.write (lowADC);           // send it out
    
    // prep address_count for next pass. Used to create ADC select, DAC select
    address_count = address_count +1;  // 0 to 7, pass to Rx for DAC sync
    if (address_count == 8){ 
      address_count = 0;
    }  // reset if hit all 8

    ADCaddress = baseADCaddress + (address_count * 0x40); // update for next ADC pass

  } // end 5mS test

The bytes were sent to another device, which put them back together. You can change the Serial.write()s I used to Serial.print()s and manipulate the data as needed.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.