def loop():
    while True:
        tmp36_data = readadc.readadc(tmp36_adc, readadc.PINS.SPICLK,
                                     readadc.PINS.SPIMOSI,
                                     readadc.PINS.SPIMISO, readadc.PINS.SPICS)

        tmp36_millivolts = tmp36_data * (3300.0 / 1024.0)

        # 10 mv per degree
        temp_C = ((tmp36_millivolts - 100.0) / 10.0) - 40.0
        # convert celsius to fahrenheit
        temp_F = (temp_C * 9.0 / 5.0) + 32
        # remove decimal point from millivolts
        tmp36_millivolts = "%d" % tmp36_millivolts
        # show only one decimal place for temprature and voltage readings
        temp_C = "%.1f" % temp_C
        temp_F = "%.1f" % temp_F

        photo_data = readadc.readadc(photo_adc, readadc.PINS.SPICLK,
                                     readadc.PINS.SPIMOSI,
                                     readadc.PINS.SPIMISO, readadc.PINS.SPICS)

        photo_millivolts = photo_data * (100.0 / 1024.0)

        print "Current temperature: %sC, %sF; light: %f" % (temp_C, temp_F,
                                                            photo_millivolts)

        time.sleep(0.5)
示例#2
0
def loop():
    while True:
        tmp36_data = readadc.readadc(tmp36_adc,
                              readadc.PINS.SPICLK,
                              readadc.PINS.SPIMOSI,
                              readadc.PINS.SPIMISO,
                              readadc.PINS.SPICS)
        
        tmp36_millivolts = tmp36_data * (3300.0/1024.0)
        
        # 10 mv per degree
        temp_C = ((tmp36_millivolts - 100.0) / 10.0) - 40.0
        # convert celsius to fahrenheit
        temp_F = (temp_C * 9.0 / 5.0) + 32
        # remove decimal point from millivolts
        tmp36_millivolts = "%d" % tmp36_millivolts
        # show only one decimal place for temprature and voltage readings
        temp_C = "%.1f" % temp_C
        temp_F = "%.1f" % temp_F
        
        photo_data = readadc.readadc(photo_adc,
                            readadc.PINS.SPICLK,
                            readadc.PINS.SPIMOSI,
                            readadc.PINS.SPIMISO,
                            readadc.PINS.SPICS)
        
        photo_millivolts = photo_data * (100.0/1024.0)
        
        
        print "Current temperature: %sC, %sF; light: %f" % (temp_C, temp_F, photo_millivolts)
        
        time.sleep(0.5)
示例#3
0
    def read(self, n_counts=2000):

        self.temp_C_arr = np.zeros(n_counts)
        self.temp_F_arr = np.zeros(n_counts)

        for n in range(n_counts):

            sensor_data = readadc.readadc(self.sensor_pin, readadc.PINS.SPICLK,
                                          readadc.PINS.SPIMOSI,
                                          readadc.PINS.SPIMISO,
                                          readadc.PINS.SPICS)

            millivolts = sensor_data * (3300.0 / 1024.0)
            # 10 mv per degree
            temp_C = ((millivolts - 100.0) / 10.0) - 40.0
            # convert celsius to fahrenheit
            temp_F = (temp_C * 9.0 / 5.0) + 32
            # remove decimal point from millivolts
            millivolts = "%d" % millivolts
            # add to array for averaging
            self.temp_C_arr[n] = temp_C
            self.temp_F_arr[n] = temp_F
            time.sleep(0.001)

        self.temp_F = np.mean(self.temp_F_arr)
        self.temp_C = np.mean(self.temp_C_arr)
示例#4
0
def get_intensity(adc_pin):
    photo_data = readadc.readadc(adc_pin,
                            readadc.PINS.SPICLK,
                            readadc.PINS.SPIMOSI,
                            readadc.PINS.SPIMISO,
                            readadc.PINS.SPICS)
        
    # convert light intensity value to 1-100
    photo_millivolts = photo_data * (3300.0/1024.0)
    light_value = (photo_millivolts * (100.0/3300.0))
    return light_value
def read_temperature():
    sensor_data = readadc.readadc(SENSOR_PIN, readadc.PINS.SPICLK,
                                  readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO,
                                  readadc.PINS.SPICS)

    millivolts = (sensor_data) * (3300.0 / 1024.0)
    temp_C = ((millivolts - 100.0) / 10.0) - 40.0

    # write the data to plotly
    print("mV: %d \t Temp: %.1f" % (millivolts, temp_C))

    return temp_C
def read_temperature():
    sensor_data = readadc.readadc(SENSOR_PIN,
                                  readadc.PINS.SPICLK,
                                  readadc.PINS.SPIMOSI,
                                  readadc.PINS.SPIMISO,
                                  readadc.PINS.SPICS)

    millivolts = (sensor_data) * (3300.0 / 1024.0)
    temp_C = ((millivolts - 100.0) / 10.0) - 40.0

    # write the data to plotly
    print("mV: %d \t Temp: %.1f" % (millivolts, temp_C) )

    return temp_C
示例#7
0
def getTemp(sensor_pin):
        sensor_data = readadc.readadc(sensor_pin,
                                  readadc.PINS.SPICLK,
                                  readadc.PINS.SPIMOSI,
                                  readadc.PINS.SPIMISO,
                                  readadc.PINS.SPICS)

        millivolts = sensor_data * (3300.0 / 1023.0)

        # 10 mv per degree
        tempC = ((millivolts - 100.0) / 10.0) - 40.0

        # remove decimal point from millivolts
        millivolts = "%d" % millivolts
    
        # show only one decimal place for temprature and voltage readings
        tempC = "%.1f" % tempC

        return tempC
示例#8
0
def get_temp(adc_pin):
    tmp36_data = readadc.readadc(adc_pin,
                              readadc.PINS.SPICLK,
                              readadc.PINS.SPIMOSI,
                              readadc.PINS.SPIMISO,
                              readadc.PINS.SPICS)
        
    tmp36_millivolts = tmp36_data * (3300.0/1024.0)
        
    # 10 mv per degree
    temp_C = ((tmp36_millivolts - 100.0) / 10.0) - 40.0
    # convert celsius to fahrenheit
    temp_F = (temp_C * 9.0 / 5.0) + 32
    # remove decimal point from millivolts
    tmp36_millivolts = "%d" % tmp36_millivolts
    # show only one decimal place for temprature and voltage readings
    temp_C = "%.1f" % temp_C
    temp_F = "%.1f" % temp_F
    
    return temp_F
#         }
#     }], filename='Raspberry Pi Streaming Example Values')

# print "View your streaming graph here: ", url

# temperature sensor middle pin connected channel 0 of mcp3008
sensor_pin = 0
readadc.initialize()

# stream = py.Stream(plotly_user_config['plotly_streaming_tokens'][0])
# stream.open()

#the main sensor reading and plotting loop
while True:
    sensor_data = readadc.readadc(sensor_pin, readadc.PINS.SPICLK,
                                  readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO,
                                  readadc.PINS.SPICS)

    millivolts = sensor_data * (3300.0 / 1024.0)
    # 10 mv per degree
    temp_C = ((millivolts - 100.0) / 10.0) - 40.0
    # convert celsius to fahrenheit
    temp_F = (temp_C * 9.0 / 5.0) + 32
    # remove decimal point from millivolts
    millivolts = "%d" % millivolts
    # show only one decimal place for temprature and voltage readings
    temp_C = "%.1f" % temp_C
    temp_F = "%.1f" % temp_F

    print('millivolts = {}'.format(millivolts))
    print('temprature (F) = {}'.format(temp_F))
示例#10
0
文件: beat.py 项目: quasibdjord/raspi
stream = py.Stream(plotly_user_config['stream_ids'][0])
stream.open()
THRESH=512
bpmstream = py.Stream(plotly_user_config['stream_ids'][1])
bpmstream.open()
#pulse detection
pulse = False

bar = np.array([])
big = np.array([])
GPIO.setup(13, GPIO.OUT)

while True:
	sensor_data = readadc.readadc(sensor_pin,
                                  readadc.PINS.SPICLK,
                                  readadc.PINS.SPIMOSI,
                                  readadc.PINS.SPIMISO,
                                  readadc.PINS.SPICS)
	#print sensor_data	
#	draw the equivalent number of points in an attempt to draw a vertical pulse sensing graph
	for i in range(sensor_data / 100):
		print ".",
		#detect beats
	if (sensor_data > THRESH):
		if (pulse == False):
			pulse = True
			print "Beat"
			bar = np.append(bar,1)
		else:
			#print ""
			bar = np.append(bar,0)
import time
import readadc

# temperature sensor middle pin connected channel 0 of mcp3008
photocell_pin = 1
readadc.initialize()

#the main sensor reading and plotting loop
while True:
    sensor_data = readadc.readadc(photocell_pin,
                                  readadc.PINS.SPICLK,
                                  readadc.PINS.SPIMOSI,
                                  readadc.PINS.SPIMISO,
                                  readadc.PINS.SPICS)

	photocell = sensor_data
	photocell = 1023 - photocell

    time.sleep(0.5)
示例#12
0
#import datetime

with open('/home/pi/workspace/bitcoin-miner/mysql_config.json') as config_file:
    conf = json.load(config_file)

# Sensors connected to channel 0 and 4 of mcp3008
temp_sensor_pin = 0
volt_sensor_pin = 4
readadc.initialize()


#the main sensor reading and plotting loop
while True:

	# voltage
	volt_sensor_data = readadc.readadc(volt_sensor_pin, readadc.PINS.SPICLK, readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO, readadc.PINS.SPICS)
	# convert data to millivolt
	millivolts = volt_sensor_data * (3300.0 / 1024.0)
	# convert volts to original input
	millivolts = millivolts * 4.5 + 280
	# convert millivolts to volts
	volts = millivolts / 1000
	# remove decimal point from millivolts // this is only used for debug
	millivolts = "%d" % millivolts
	# show only one decimal place for voltage readings
	volts = "%.1f" % volts

	# temperature
	temp_sensor_data = readadc.readadc(temp_sensor_pin, readadc.PINS.SPICLK, readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO, readadc.PINS.SPICS)
	# convert data to millivolt
	temp_millivolts = temp_sensor_data * (3300.0 / 1024.0)