def meas_temp(senseID,sense_type): # 12 bit number in range 0-4095 adcval=pi_adc.readadc(senseID, SPICLK, SPIMOSI, SPIMISO, SPICS) #print adcval if sense_type==36: temperature=25.0+((3.3*(adcval/4095.0))-0.75)/(0.01) # 750mV at 25degC with 10mV/degC else: temperature=25.0+((3.3*(adcval/4095.0))-0.5)/(0.02) # 500mV at 25degC with 20mV/degC return temperature
cpu_key = home_key cpu_ID = 82576 GPIO.setmode(GPIO.BCM) # setup the ADC pi_adc.adc_setup(SPICLK,SPIMISO,SPIMOSI,SPICS) # setup the Phototransistor input photo_setup(PHOTOIN) while adcmode: if adcmode>0: adcval=pi_adc.readadc(adcmode-1, SPICLK, SPIMOSI, SPIMISO, SPICS) time.sleep(avelen) temperature36=25.0+((3.3*(adcval/4095.0))-0.75)/(0.01) # 750mV at 25degC with 10mV/degC temperature37=25.0+((3.3*(adcval/4095.0))-0.5)/(0.02) # 500mV at 25degC with 20mV/degC print "adcmode on channel {:d} : {:d} {:2.2f}degC {:2.2f}degC".format(adcmode,adcval,temperature36,temperature37) else: adcval=0 for i in range(1000): #adcval+=pi_adc.readadc(-adcmode-1, SPICLK, SPIMOSI, SPIMISO, SPICS) adcval+=meastemp(-adcmode-1,36) print str(datetime.datetime.utcnow())+ " " + str(adcval/1000.0) while True: # once an hour update the stream