austnalio
Posts: 2
Joined: Thu Feb 18, 2016 9:25 pm

MCP3008 fluctuation

Thu Feb 18, 2016 10:27 pm

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?

austnalio
Posts: 2
Joined: Thu Feb 18, 2016 9:25 pm

Re: MCP3008 fluctuation

Mon Feb 22, 2016 2:22 pm

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.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7314
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: MCP3008 fluctuation

Mon Feb 22, 2016 2:34 pm

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.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
joan
Posts: 14270
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: MCP3008 fluctuation

Mon Feb 22, 2016 2:36 pm

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.

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: MCP3008 fluctuation

Tue Feb 23, 2016 2:34 pm

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)
--
Gordons projects: https://projects.drogon.net/

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: MCP3008 fluctuation

Tue Feb 23, 2016 5:21 pm

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.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Return to “Interfacing (DSI, CSI, I2C, etc.)”