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):
- 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:
- tempAdcVal = readadc(0)
- volts = ((tempAdcVal*3.3)/1024.0)
- temp = (volts-0.5)*100
- print ("%4d/1023 => %5.3f V => %2.0f C" %(tempAdcVal,volts,round(temp)))
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement