I started to try to read an MCP3008 ADC using SPI bit banging with pigpio. I wrote the unattractive little script below, starting from the example in the pigpio documentation and here is a screenshot of my output.
I believe that this should read the lowest four channels of the ADC and print the output. Channels 0 to 3 are connected to +5V, GND, +5V, floating, so I expected to see values like 1023, 0, 1023, xxx where the last would be noise.
Instead I see all 1023's.
Have I done something terribly wrong?
import pigpio
import time
CE1 = 2
MISO = 3
MOSI = 4
SCLK = 17
pi = pigpio.pi()
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 10000, 3)
nums = [128 + n for n in (16, 32, 48, 64)]
while True:
print "wow!"
for num in nums:
print "num! ", num
count, data = pi.bb_spi_xfer(CE1, [1, num, 0])
print "count = ", count, data = [byte for byte in data]
value = ((data[1]&3)<<8) | data[2]
print "value = ", value
time.sleep(1)
num
already has a 128 in it already;nums = [128 + n for n in (16, 32, 48, 64)]
so would the 2nd 128 wrap it back to zero, or cause a problem because it would then be greater than 256? I don't understand what "mode" actually means. I see that it is mentioned in the pigpio documentation. Maybe I should ask a separate question on that?