Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Adafruit_BBIO.SPI import SPI
- SPI0_CS0 = "P9_17"
- SPI0_D0 = "P9_21"
- SPI0_D1 = "P9_18"
- SPI0_SCLK = "P9_22"
- spi = SPI(1, 0)
- class MCP3008:
- def __init__(self, bus = 0, device = 0):
- self.bus, self.device = bus, device
- self.spi = SPI()
- self.open()
- def open(self):
- self.spi.open(self.bus, self.device)
- def read(self, channel = 0):
- adc = self.spi.xfer2([1, (8 + channel) << 4, 0])
- data = ((adc[1] & 3) << 8) + adc[2]
- return data
- def close(self):
- self.spi.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement