Using MCP3208 with Arduino DUE

Hello there!

This is my first time posting here, please forgive me if I forget stuff.
I got a problem using the ADC MCP3208 with Arduino Due.

I want to read out a flexsensor using a voltage divider and the said ADC. It is kinda working, but the value really is shaking a lot and makes it almost impossible to read out a good value.

Now I read that you can add coupling capacitators. To be honest I am quite bad at electronics and don’t get (not even with the mcp datasheet) how to use it properly. Does somebody have any suggestions or maybe layouts I can use as an orientation?

I am not using a library, the code I use to read out the ADC is this:

#include <SPI.h>
#define _CS_PIN_ 52 //Pin 10 defined as the CS Pin.
void setup()
{
  Serial.begin(115200); //Initalize the Serial Port to print the Analog Readings from MCP3208 onto teh Terminal.
  pinMode(_CS_PIN_,OUTPUT); //Pin 10 acting as OUTPUT as CS is a OUTPUT Pin. 
  digitalWrite(_CS_PIN_,HIGH);
  SPI.begin(); //Intialize SPI PORT
  SPI.setClockDivider(52, 84);


}

void loop()
{

     Serial.println(readADC(4)); //Reads Cahnnel 0 From MCP3208 and Prints the Value. Change it If u want t o read Other Cahnnel.
     delay(2000); //Delay
}

uint16_t readADC(int channel)
{
  uint16_t output;
  byte channelBits = channel<<6;

 //if(channel>3)
 
  //Select ADC
  digitalWrite(_CS_PIN_, LOW); //Select the Connected MCP3208 by pulling _CS_PIN_ LOW.
  if(channel>3)
    SPI.transfer(B00000111); //Defines Single mode of Operation for the ADC. D2=1 Start Bit. D1=1 Sinfgle Ended Mode D0=0 For Channel 0-3. 1 For Channel 4-7
  else
    SPI.transfer(B00000110);

  byte msb = SPI.transfer(channelBits); //Transfers 2nd Byte from MCU to MCP3208 which returns  MSB of the read data. 
  byte lsb = SPI.transfer(0x00);//Transfers 3rd Byte from MCU to MCP3208 which returns  LSB of the read data. 
 
  digitalWrite(_CS_PIN_,HIGH); //Deselect the Connected MCP3208 by pulling _CS_PIN_ HIGH.
 
  
  msb = msb & B00001111; // Make all 4 Higher bits of the MSB 0 as 12 Bit Resolution is provided by MCP3208
  
  output = msb<<8 | lsb; //Combine MSB with LSB to form the 12 Bit Analog read  Value.

  return output; //Output Value
}

I didn’t make it myself, I got it from here: MCP3208_Arduino/MCP3208_With_Arduino.ino at master · oksbwn/MCP3208_Arduino · GitHub

This is a part of my current layout. I am powering (VDD) the MCP with 5V from the SPI Pin header, NOT 3.3V.

Would be very happy if maybe somebody has got a few suggestions!

Not coupling capacitors but decoupling capacitors. All chips must have a 0.1uF ceramic capacitor between the power and ground.

Connecting the analog and digital grounds together on the chip is not as good as taking them to different ground pins on the Arduino.

Also a capacitor from the input to the analogue ground close to the chip will help.

If you are using a Solderless bread board then you will get noise in the readings.

Hello Mike,

thank you sooo much for your fast reply!
I just wanna do it right this time, so I hope it is okay to ask if I did it the right way this time.
This is my layout now.

Do I need a capacitator between EVERY input and ground or can I just use one? Also, I used a 10uF ceramic one, is that appropiate?

Also, is it okay to short VDD and VREF? I have read some different opinions about that.

Connect the capacitors in the inputs to the analogue ground not the digital one. You should have them on every input you use for this application. It will slow down the signal but as you are only using a flex sensor the signal will be very solw in electronic terms.

A ceramic capacitor of 10uF is rare are you sure it is a ceramic one? You can get them in surface mount but they are expensive.

Otherwise OK.

Alright! Thank you very very much Mike, you've been a huge help!
I tested it on a breadbord and it works perfectly now.

A ceramic capacitor of 10uF is rare are you sure it is a ceramic one? You can get them in surface mount but they are expensive.

11p (exc VAT) for 10uF 25V in qty's of 5 or more at Farnell - not that expensive in real terms (yes, quite a bit
more that some SMT caps)