Пример #1
0
Файл: mq7.py Проект: oronum/upm
def main():
    # Attach gas sensor to Analog A0
    sensor = upmGAS.MQ7(0)

    ## Exit handlers ##
    # This function stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit, including functions from sensor
    def exitHandler():
        print "Exiting"
        sys.exit(0)

    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)

    threshContext = upmGAS.thresholdContext()
    threshContext.averageReading = 0
    threshContext.runningAverage = 0
    threshContext.averagedOver = 2

    # Infinite loop, ends when script is cancelled
    # Repeatedly, take a sample every 2 microseconds;
    # find the average of 128 samples; and
    # print a running graph of asteriskss as averages
    mybuffer = upmGAS.uint16Array(128)
    while(1):
        samplelen = sensor.getSampledWindow(2, 128, mybuffer)
        if samplelen:
            thresh = sensor.findThreshold(threshContext, 30, mybuffer, samplelen)
            sensor.printGraph(threshContext, 5)
Пример #2
0
 def __init__(self, refresh=1, port=1, averageReading=0, runningAverage=0, averagedOver=2,  *args, **kwargs):
     super(GasSensor, self).__init__(refresh=refresh, *args, **kwargs)
     self.upm_sensor = gas.MQ5(port)
     self.threshContext = gas.thresholdContext()
     self.threshContext.averageReading = averageReading
     self.threshContext.runningAverage = runningAverage
     self.threshContext.averagedOver = averagedOver
     self.buffer = gas.uint16Array(128)
Пример #3
0
def fMq2():

	# From
	# https://github.com/intel-iot-devkit/upm/blob/master/examples/python/mq2.py

        thisMq2 = upmGas.MQ2(0);

	threshContext = upmGas.thresholdContext()
	threshContext.averageReading = 0
	threshContext.runningAverage = 0
	threshContext.averagedOver = 2

	thisbuffer = upmGas.uint16Array(128)

	while True:
		samplelen = thisMq2.getSampledWindow(2, 128, thisbuffer)
		if samplelen:
			thresh = thisMq2.findThreshold(threshContext, 30, thisbuffer, samplelen)
			#thisMq2.printGraph(threshContext, 5)
			if(thresh):
				print("MQ2 Threshold: ", thresh)
		time.sleep(1)
Пример #4
0
def fMq2():

    # From
    # https://github.com/intel-iot-devkit/upm/blob/master/examples/python/mq2.py

    thisMq2 = upmGas.MQ2(0)

    threshContext = upmGas.thresholdContext()
    threshContext.averageReading = 0
    threshContext.runningAverage = 0
    threshContext.averagedOver = 2

    thisbuffer = upmGas.uint16Array(128)

    while True:
        samplelen = thisMq2.getSampledWindow(2, 128, thisbuffer)
        if samplelen:
            thresh = thisMq2.findThreshold(threshContext, 30, thisbuffer,
                                           samplelen)
            #thisMq2.printGraph(threshContext, 5)
            if (thresh):
                print("MQ2 Threshold: ", thresh)
        time.sleep(1)
Пример #5
0
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from myMQ9
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)


threshContext = upmGas.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

# Infinite loop, ends when script is cancelled
# Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of dots as averages
mybuffer = upmGas.uint16Array(128)
while(1):
	samplelen = myMQ9.getSampledWindow(2, 128, mybuffer)
	if samplelen:
		thresh = myMQ9.findThreshold(threshContext, 30, mybuffer, samplelen)
		myMQ9.printGraph(threshContext, 5)
		if(thresh):
Пример #6
0
Файл: mq9.py Проект: jrvandr/upm
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
    raise SystemExit


# This function lets you run code on exit, including functions from myMQ9
def exitHandler():
    print "Exiting"
    sys.exit(0)


# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

threshContext = upmGas.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

# Infinite loop, ends when script is cancelled
# Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of dots as averages
mybuffer = upmGas.uint16Array(128)
while (1):
    samplelen = myMQ9.getSampledWindow(2, 128, mybuffer)
    if samplelen:
        thresh = myMQ9.findThreshold(threshContext, 30, mybuffer, samplelen)
        myMQ9.printGraph(threshContext, 5)
        if (thresh):
Пример #7
0
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from sensor
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)


threshContext = upmGAS.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

# Infinite loop, ends when script is cancelled
# Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of asteriskss as averages
mybuffer = upmGAS.uint16Array(128)
while(1):
	samplelen = sensor.getSampledWindow(2, 128, mybuffer)
	if samplelen:
		thresh = sensor.findThreshold(threshContext, 30, mybuffer, samplelen)
		sensor.printGraph(threshContext, 5)
#		if(thresh):
Пример #8
0
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
	raise SystemExit

# This function lets you run code on exit, including functions from sensor
def exitHandler():
	print "Exiting"
	sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)


threshContext = upmGAS.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

# Infinite loop, ends when script is cancelled
# Repeatedly, take a sample every 2 microseconds;
# find the average of 128 samples; and
# print a running graph of asteriskss as averages
mybuffer = upmGAS.uint16Array(128)
while(1):
	samplelen = sensor.getSampledWindow(2, 128, mybuffer)
	if samplelen:
		thresh = sensor.findThreshold(threshContext, 30, mybuffer, samplelen)
		sensor.printGraph(threshContext, 5)
#		if(thresh):