frasmacon wrote: bgreat wrote:
Giving a quick look at the data sheet and your code, I see two issues.
1. You should use xfer() instead of xfer2(). xfer2() does not release the CSx line between transfers, and it is needed by the MCP3004.
2. For single ended conversion, change:
Code: Select all
r = spi.xfer2([1, (4+channel)<<4, 0])
r = spi.xfer([1, (8+channel)<<4, 0])
Thanks a lot! On a side note why does it need 8+channel?
OK, I worked out the 8+channel, and I changed the code but I still get erratic readings but I know the code works now as I tested it just feeding 3.3V into the chip and it read 1023. Could it be noise on the line, or a faulty pot. I don't trust mine as when I just hook it up to an LED, it doesn't really work that well. It's one I borrowed off my school so it wouldn't surprise me. It's 10K also, would that make a difference.
Theoretically, if I left the pin unconnected, shouldn't the readout be zero? Because for me it floats from 0 to around 270