Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import spidev
- import time
- import os
- spi = spidev.SpiDev()
- spi.open(0,0)
- def get_adc(adcnum):
- r = spi.xfer2([1,(8+adcnum)<<4,0])
- adcout = ((r[1]&3) << 8) + r[2]
- return adcout
- while True:
- get_adc(0) # throw away first reading as a test. didn't fix anything
- retrieve0 = get_adc(0) # get TMP36 #1
- time.sleep(1)
- get_adc(1) # throw away first reading as a test. didn't fix anything
- retrieve1 = get_adc(1) # get TMP36 #2
- time.sleep(1)
- get_adc(2) # throw away first reading as a test. didn't fix anything
- retrieve2 = get_adc(2) # get LDR #1 light level reading
- time.sleep(1)
- get_adc(3) # throw away first reading as a test. didn't fix anything
- retrieve3 = get_adc(3) # get LDR #2 light level reading
- time.sleep(1)
- #convert TMP36 #1 digital reading to Celsius temperature
- c_temp0 = (((retrieve0 * ( 3300.0 / 1024.0)) - 100.0) / 10.0) - 40.0
- c_temp0 = "%.1f" % c_temp0
- #convert TMP36 #2 digital reading to Celsius temperature
- c_temp1 = (((retrieve1 * ( 3300.0 / 1024.0)) - 100.0) / 10.0) - 40.0
- c_temp1 = "%.1f" % c_temp1
- print("TMP1:")
- print(retrieve0)
- print(c_temp0, "C")
- print("TMP2:")
- print(retrieve1)
- print(c_temp1, "C")
- print("LDR1:")
- print(retrieve2)
- print("LDR2:")
- print(retrieve3)
- time.sleep(0.5) # sleepy time...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement