This code has been giving me some problems:
Code: Select all
import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
def readadc(adcnum):
if ((adcnum > 7) or (adcnum < 0)):
return -1
r = spi.xfer2([1,(8+adcnum)<<4,0])
adcout = ((r[1]&3) << 8) + r[2]
return adcout
while True:
for adcInput in range(0,8):
value = readadc(adcInput)
voltage = value * 3.3
voltage /= 1024.0
tempCelsius = (voltage-0.5)*100
print "---------------------------"
print "ADC(", adcInput,")= ", value
print "---------------------------"
print "Voltage: ", voltage
print "---------------------------"
print "Temp: ", tempCelsius
time.sleep(1)"Traceback (most recent call last):
File temp.py, line 4 in <module>
spi.open(0,0)
IOError: [Errno 2] No such file or directory"
What exacly is wrong? Could it be something wrong with the sensor? Should I get a new one? How can I alter the code I do for it to print 3 to 5 values (with some 10-15 seconds between them) and stop there?
