Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import spidev
- import time
- spi = spidev.SpiDev()
- spi.open(0,0)
- def readadc(adcnum):
- # read SPI data from MCP3004 chip, 4 possible adcs (0 thru 3)
- if adcnum >3 or adcnum < 0:
- return-1
- r = spi.xfer2([1,8+adcnum <<4,0])
- adcout = ((r[1] &3) <<8)+r[2]
- return adcout
- while True:
- value=readadc(2)
- volts=(value*3.3)/1024
- print("%4d/1023 => %5.3f V" % (value, volts))
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement