Example #1
0
 def __init__(self, refresh=1, port=3, averageReading=0, runningAverage=0, averagedOver=2,  *args, **kwargs):
     super(SoundSensor, self).__init__(refresh=refresh, *args, **kwargs)
     self.upm_sensor = mic.Microphone(port)
     self.threshContext = mic.thresholdContext()
     self.threshContext.averageReading = averageReading
     self.threshContext.runningAverage = runningAverage
     self.threshContext.averagedOver = averagedOver
     self.buffer = mic.uint16Array(128)
Example #2
0
def initSound():
    global mymic
    global threshContext
    mymic = upmMicrophone.Microphone(1)
    threshContext = upmMicrophone.thresholdContext()
    threshContext.averageReading = 0
    threshContext.runningAverage = 0
    threshContext.averagedOver = 2
    print("Sound init")
Example #3
0
def initSound():
    global mymic
    global threshContext
    mymic = upmMicrophone.Microphone(1)
    threshContext = upmMicrophone.thresholdContext()
    threshContext.averageReading = 0
    threshContext.runningAverage = 0
    threshContext.averagedOver = 2
    print("Sound init")
Example #4
0
    def __init__(self):
        # Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
        self.piezo = ldt0028.LDT0028(0)

        # Create the light sensor object using AIO pin 1
        self.light = grove.GroveLight(1)

        #led on D5
        self.led = mraa.Gpio(5)
        self.led.dir(mraa.DIR_OUT)

        self.mic = upmMicrophone.Microphone(2)
        self.threshContext = upmMicrophone.thresholdContext()
        self.threshContext.averageReading = 0
        self.threshContext.runningAverage = 0
        self.threshContext.averagedOver = 2
    def getSound(self):
        myMic = upmMicrophone.Microphone(int(self.port))
        threshContext = upmMicrophone.thresholdContext()
        threshContext.averageReading = 0
        threshContext.runningAverage = 0
        threshContext.averagedOver = 2

        buffer = upmMicrophone.uint16Array(128)
        len = myMic.getSampledWindow(2, 128, buffer)
        if len:
            thresh = myMic.findThreshold(threshContext, 30, buffer, len)
            #myMic.printGraph(threshContext)
            if (thresh):
                print "Threshold is ", thresh
                self.info["soundLevel"] = str(thresh)
                del myMic
                return self.info
Example #6
0
    def __init__(self):
        self.screen = pyupm_i2clcd.Jhd1313m1(6, 0x3E, 0x62)
        self.clearScreen()

        self.light = grove.GroveLight(2)

        self.mic = upmMicrophone.Microphone(1)
        self.threshContext = upmMicrophone.thresholdContext()
        self.threshContext.averageReading = 0
        self.threshContext.runningAverage = 0
        self.threshContext.averagedOver = 2

        self.piezo = ldt0028.LDT0028(0)

        self.button = mraa.Gpio(3)
        self.button.dir(mraa.DIR_IN)

        self.buzzer = mraa.Gpio(6)
        self.buzzer.dir(mraa.DIR_OUT)
        self.buzzer.write(0)
 def getNoiseState(self):
     buffer = upmMicrophone.uint16Array(128)
     len = self.myMic.getSampledWindow(100, 128, buffer)
     
     threshContext = upmMicrophone.thresholdContext()
     threshContext.averageReading = 0
     threshContext.runningAverage = 0
     threshContext.averagedOver = 1
     
     self.thresh = self.myMic.findThreshold(threshContext, 30, buffer, len)
     
     if self.thresh<=115:
         self.state = 0
     elif self.thresh>115 and self.thresh<self.threshold-self.threshold/7:
         self.state = 1
     elif self.thresh>=self.threshold-self.threshold/7 and self.thresh<=self.threshold:
         self.state = 2
     elif self.thresh>self.threshold:
         self.state = 3
     else:
         '''Smth wrong!'''
Example #8
0
    def getNoiseState(self):
        buffer = upmMicrophone.uint16Array(128)
        len = self.myMic.getSampledWindow(100, 128, buffer)

        threshContext = upmMicrophone.thresholdContext()
        threshContext.averageReading = 0
        threshContext.runningAverage = 0
        threshContext.averagedOver = 1

        self.thresh = self.myMic.findThreshold(threshContext, 30, buffer, len)

        if self.thresh <= 115:
            self.state = 0
        elif self.thresh > 115 and self.thresh < self.threshold - self.threshold / 7:
            self.state = 1
        elif self.thresh >= self.threshold - self.threshold / 7 and self.thresh <= self.threshold:
            self.state = 2
        elif self.thresh > self.threshold:
            self.state = 3
        else:
            '''Smth wrong!'''
Example #9
0
def main():
    # Attach microphone to analog port A0
    myMic = upmMicrophone.Microphone(2)
    threshContext = upmMicrophone.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
    while (1):
        buffer = upmMicrophone.uint16Array(128)
        len = myMic.getSampledWindow(2, 128, buffer)
        if len:
            thresh = myMic.findThreshold(threshContext, 30, buffer, len)
            myMic.printGraph(threshContext)
            if (thresh):
                print("Threshold is ", thresh)

    # Delete the upmMicrophone object
    del myMic
Example #10
0
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import time
import pyupm_mic as upmMicrophone

# Attach microphone to analog port A0
myMic = upmMicrophone.Microphone(0)
threshContext = upmMicrophone.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
while (1):
    buffer = upmMicrophone.uint16Array(128)
    len = myMic.getSampledWindow(2, 128, buffer)
    if len:
        thresh = myMic.findThreshold(threshContext, 30, buffer, len)
        myMic.printGraph(threshContext)
        if (thresh):
Example #11
0
#!/usr/bin/env python

#need to clean these...
import time
import pyupm_grove as grove
import pyupm_mic as upmMicrophone 
import httplib, urllib, urllib2

#Create the temp sensor object using AIO pin 2
temp = grove.GroveTemp(2)
print temp.name()

# Attach microphone to analog port A1
myMic = upmMicrophone.Microphone(1)
threshContext = upmMicrophone.thresholdContext()
threshContext.averageReading = 0
threshContext.runningAverage = 0
threshContext.averagedOver = 2

#Stuff for HTTP posts
ip = "http://94.143.213.153/Areas"

def get_temp():
    celsius = temp.value()
    fahrenheit = celsius * 9.0/5.0 + 32.0;
    print "%d degree cel or %d degrees fahrenheit" \
        % (celsius, fahrenheit)
    return celsius

def get_sound():
    buffer = upmMicrophone.uint16Array(128)
Example #12
0
import pyupm_mic as microphone
import requests
import time
import pyupm_grove as grove

mic = microphone.Microphone(0)
light = grove.GroveLight(3)
temp = grove.GroveTemp(2)
knob= grove.GroveRotary(1)

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

values = []
average = 0
clap = False

def read_sound_sensor():
    global average, clap, values

    buffer = microphone.uint16Array(128)
    length = mic.getSampledWindow(2, 128, buffer)
    if length:
        thresh = mic.findThreshold(threshContext, 30, buffer, length)
        print thresh
        mic.printGraph(threshContext)
        if thresh:
            if average > 0 and thresh > average * 1.1 and not clap:
                print "clap"
 def initialize(self):
     self.ctx = pyupm_mic.thresholdContext()
     self.ctx.averageReading = 0
     self.ctx.runningAverage = 0
     self.ctx.averagedOver = self._sample_rate
 def initialize(self):
     self.ctx = pyupm_mic.thresholdContext()
     self.ctx.averageReading = 0
     self.ctx.runningAverage = 0
     self.ctx.averagedOver = self._sample_rate
Example #15
0
	def __init__(self,pin):
		self.soundSensor = upmMicrophone.Microphone(pin)
		self.threshContext = upmMicrophone.thresholdContext()
		self.threshContext.averageReading=0
		self.threshContext.runningAverage=0
		self.threshContext.averagedOver=2