02-14-2017, 04:45 PM
(This post was last modified: 02-14-2017, 04:49 PM by martinayotte.)
I don't have any MCP3008, but according to the specs, looking specifically to section No.6, it is explain how to deal with 8 bits SPI.
In summary, you should do a transfer of 3 bytes and you will read 3 bytes. The bytes sent should be [0x01, 0x80, 0x00] for example for getting single-ended conversion of the channel 0.
The 3 read bytes should be [0x00, 0x03, 0xFF] if the voltage input is at the maximum, assuming there is a pull-down on MISO, otherwise left floating, some more bits can become HIGH in the fist 2 bytes.
For code, it should looks like :
In summary, you should do a transfer of 3 bytes and you will read 3 bytes. The bytes sent should be [0x01, 0x80, 0x00] for example for getting single-ended conversion of the channel 0.
The 3 read bytes should be [0x00, 0x03, 0xFF] if the voltage input is at the maximum, assuming there is a pull-down on MISO, otherwise left floating, some more bits can become HIGH in the fist 2 bytes.
For code, it should looks like :
Code:
from pyA20 import spi
spi.open("/dev/spidev0.0")
data = spi.xfer([0x01, 0x80, 0x00], 3)
print data