Advertisement
schuetz

tmp36Test

Apr 26th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import spidev
  2. import time
  3.  
  4. spi = spidev.SpiDev()
  5. spi.open(0,0)
  6.  
  7. def readadc(adcnum):
  8.         if adcnum > 3 or adcnum <0:
  9.                 return -1
  10.         r = spi.xfer2([1,8+adcnum << 4,0])
  11.         adcout = ((r[1]&3)<<8)+r[2]
  12.         return adcout
  13.  
  14. while True:
  15.         tempAdcVal = readadc(0)
  16.         volts = ((tempAdcVal*3.3)/1024.0)
  17.         temp = (volts-0.5)*100
  18.         print ("%4d/1023 => %5.3f V => %2.0f C" %(tempAdcVal,volts,round(temp)))
  19.         time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement