0
\$\begingroup\$

I have a Raspberry Pi connected to an MCP3002. It's power and Vref is taken from the Pi's 3.3V

I also took a two 1M resistors to form a voltage divider on the 5V connection to create 2.5V. Then on the pi I test the voltage using this code http://www.raspberrypi-spy.co.uk/2013/10/analogue-sensors-on-the-raspberry-pi-using-an-mcp3008/ but without the temperature conversion.

However, when I connect the voltage divider up to the ADC I get 0.7-0.75V

    #!/usr/bin/python

import spidev
import time
import os

# Open SPI bus
spi = spidev.SpiDev()
spi.open(0,0)

# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data

# Function to convert data to voltage level,
# rounded to specified number of decimal places.
def ConvertVolts(data,places):
  volts = (data * 3.3) / float(1023)
  volts = round(volts,places)
  return volts

while True:

  # Read the light sensor data
  ADC_volts = ReadChannel(0)
  digital_Volts = ConvertVolts(ADC_volts,2)
  print digital_Volts

schematic

simulate this circuit – Schematic created using CircuitLab

I've been doing this all morning, I recently put this back together, and it worked. I am planning on using this to connect a piezo but I need to bias the signal with to centralize it. Is it a problem with the code, or my set up.

\$\endgroup\$
  • 5
    \$\begingroup\$ What is the CH0 input impedance of a RaPi input line? What is the leakage bias current from that pin? 1 Mohm resistors are pretty big not to be upset by a CPU input. \$\endgroup\$ – Andy aka Oct 1 '15 at 14:33
  • \$\begingroup\$ I don't know, How do I find this information out? \$\endgroup\$ – JamesDonnelly Oct 1 '15 at 15:09
  • \$\begingroup\$ We presume the 5V -Ve is also connected to the Gnd of the MCP3002? \$\endgroup\$ – Icy Oct 1 '15 at 15:12
  • \$\begingroup\$ The RaPi is powering the ADC with the 3.3V and is also used as the input to the ADC via a voltage divider. \$\endgroup\$ – JamesDonnelly Oct 1 '15 at 15:19
  • \$\begingroup\$ The schematic is now exactly how it is wired up \$\endgroup\$ – JamesDonnelly Oct 1 '15 at 15:36
1
\$\begingroup\$

The MCP3002 datasheet says:

Ideally, the impedance of the signal source should be near zero. This is achievable with an operational amplifier such as the MCP601 which has a closed loop output impedance of tens of ohms. The adverse affects of higher source impedances are shown in Figure 4-2.

The maximum source impedance plotted in that graph is 10KOhm. You are using way above that (megohms). The datasheet quote above also says how you can fix that.

\$\endgroup\$
  • \$\begingroup\$ Can you explain that for me? If I just changed the 1M to 100Ohms would that also fix it. I do have the mcp601 to use. \$\endgroup\$ – JamesDonnelly Oct 1 '15 at 17:30
  • \$\begingroup\$ @JamesDonnelly: Assuming your "Raspberry Pi Cobbler" (whatever that is) can output the current that would flow thought 200Ohm (to GND), yes it would work. \$\endgroup\$ – Fizz Oct 1 '15 at 17:34
  • \$\begingroup\$ @RespawnedFluff Sidenote: the Raspberry Pi Cobbler is just a little breakout board to make the RPis gpio header more breadboard friendly. It makes use of a ribbon cable. goo.gl/nwcPnr \$\endgroup\$ – Funkyguy Oct 1 '15 at 18:00
  • \$\begingroup\$ @Funkyguy: if I got this right, you're just connecting that CH0 divider to the power supply (via the Cobbler). Those 200ohms will pull 25mA at 5V, which if they come straight from the power supply line on the RPi board should be no problem (unless you've already maxed out your power supply, which seems unlikely). For better results a buffer opamp (as they suggest) is preferable, but just to test if the thing/idea works, the 2x100Ohm divider should be safe/fine. \$\endgroup\$ – Fizz Oct 2 '15 at 5:14
  • \$\begingroup\$ I've looked it up and each pin should not exceed 16mA and 51mA overall. So I need to ensure I stay below 16mA I need an overall resistance of 333 or more, is that correct? I've now connected the ADC and MCP601 to the 5V supply from my RPi. And using a voltage divider of two 330ohm from my 5V supply to the MCP601 I get readings of 4.99V (through the python program) and when I connect the 3.3V rail to the MCP601 through a 330ohm resistor I get readings of 3.85-4.12V fluctuating. can you explain what is happening? I'm new to this but it just doesn't make sense. MCP601 is configured to buffer. \$\endgroup\$ – JamesDonnelly Oct 2 '15 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.