Page 1 of 1

MCP3008 fluctuation

Posted: Thu Feb 18, 2016 10:27 pm
by austnalio
Hi everyone,

I am using a MCP3008 chip to convert analog to digital. I followed the tutorial on Adafruit https://learn.adafruit.com/reading-a-an ... i/overview.

Everything is wired up but when I run it without anything wired into the channels, I get a random mess of numbers ranging from 0 to the max of 1023.

I can ground them out and get 0 all the time and I can apply 3.3v and get 1020-1023 the whole time. Sampling the data every second gives something like this:

Code: Select all

read:  792
read:  728
read:  270
read:  0
read:  0
read:  363
read:  798
read:  767
read:  448
read:  0
read:  0
read:  206
read:  784
read:  781
read:  585
read:  73
read:  0
read:  36
read:  569
read:  804
read:  718
read:  234
read:  0
read:  0
read:  331
read:  612
read:  796
read:  692
read:  198
read:  0
read:  0
Any Ideas what I am doing wrong?

Re: MCP3008 fluctuation

Posted: Mon Feb 22, 2016 2:22 pm
by austnalio
Don't used code from Adafruit.
Used spidev. It will worked both mcp3008/3208. I am using mcp3208.
http://jeremyblythe.blogspot.ca/2012/09 ... nputs.html
Copied the code over, changed the wiring to look just like the picture and ran it. Still getting the same random readings. I even tried a different raspberry pi and different MCP3008. Nothing is hooked up to the channel, I would think it would be 0 if that were the case. I attached a analog voltage reader to the channel and still get random numbers but higher highs and more 0s.

Re: MCP3008 fluctuation

Posted: Mon Feb 22, 2016 2:34 pm
by 6by9
If you've left the line floating, then you're going to read noise. There is normally no pull up or down on an analogue line, and the input impedances are normally very high.

Connect a potentiometer between 3.3V and 0V, and then the wiper on to your analogue input. Sweep the pot between extremes and read the values of that.
TBH I wouldn't expect the different wiring approach between Adafruit and spidev to make any difference here - it sounds like a pure electrical issue.

Re: MCP3008 fluctuation

Posted: Mon Feb 22, 2016 2:36 pm
by joan
Either the software is wrong or the hardware is wrong.

We need to see the software you are using and the wiring you are using.

A photo showing the connections actually made between the Pi, ADC, and the device you are sampling would be useful.

Re: MCP3008 fluctuation

Posted: Tue Feb 23, 2016 2:34 pm
by gordon@drogon.net
If you want another software reference point, then wiringPi supports this device. Try:

Code: Select all

  while true; do gpio -x mcp3004:100:0 aread 100 ; done
however it really needs something connected to the input to make sense - leaving it unconnected will let it wobble about all over the place..

-Gordon
(The mcp3004 and mcp3008 are essentially the same chip)

Re: MCP3008 fluctuation

Posted: Tue Feb 23, 2016 5:21 pm
by Richard-TX
Any ADC will have some fluctuations but in your case you left the line open which means that internal chip leakage or AC leakage from nearby mains will cause the ADC readings to vary all over the place. Under normal steady DC conditions the value returned will be plus or minus the least significant digit or 1 in the case of the 3008. Apply an AC signal like the leakage from your finger and the induced 50/60 hz from nearby electrical devices will cause the instantaneous readings to vary. It will depend at which point in the 50/60 hz sinewave the chip reads it.