I recently posted, but my schematic changed and so did my problem.
I have this set up and on my raspberry Pi I have this code running which gets the 10-bit number from the ADC and converts it into a usable voltage for me.
#!/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 MCP3002 chip # Channel must be an integer 0-7 def ReadChannel(channel): adc = spi.xfer2([1,(8+channel)<<4,0]) data = ((adc&3) << 8) + adc return data # Function to convert data to voltage level, # rounded to specified number of decimal places. def ConvertVolts(data,places): volts = (data * 5) / float(1023) volts = round(volts,places) return volts while True: # Read the MCP3002 ADC_volts = ReadChannel(0) digital_Volts = ConvertVolts(ADC_volts,2) print digital_Volts
The problem I am having is that if I run this I expect to get a constant 3.3V reading in my program. However, I do not. I get a fluctuating reading between 4.34-4.63V. I need to establish a constant voltage because I intend to include a piezo element to detect voltage from vibrations and the signal needs to be biased to get both the pos+ and neg- voltages produced.
Can anyone explain why I don't get 3.3V, and why I don't get a constant 4.5 or near abouts reading but a fluctuating value? Thank you