def main():
    # Grove - 16x2 LCD(White on Blue) connected to I2C port
    lcd = JHD1802()

    # Grove - Moisture Sensor connected to port A0
    sensor = GroveMoistureSensor(0)

    # Grove - Buzzer connected to port PWM
    buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))

    while True:
        mois = sensor.moisture
        if 0 <= mois and mois < 300:
            level = 'dry'
        elif 300 <= mois and mois < 600:
            level = 'moist'
        else:
            level = 'wet'
            buzzer.playSound(upmBuzzer.BUZZER_DO, 200000)

        print('moisture: {}, {}'.format(mois, level))

        lcd.setCursor(0, 0)
        lcd.write('moisture: {0:>6}'.format(mois))

        lcd.setCursor(1, 0)
        lcd.write('{0:>16}'.format(level))

        time.sleep(1)
Exemplo n.º 2
0
def main():
    from grove import helper
    helper.root_check()

    print("Insert Grove-Buzzer to Grove-Base-Hat slot PWM[12 13 VCC GND]")

    # Grove Base Hat for Raspberry Pi
    #   PWM JST SLOT - PWM[12 13 VCC GND]
    pin = 12
    #
    # Create the buzzer object using RaspberryPi GPIO12
    mraa_pin = getGpioLookup("GPIO%02d" % pin)
    buzzer = upmBuzzer.Buzzer(mraa_pin)

    chords = [upmBuzzer.BUZZER_DO, upmBuzzer.BUZZER_RE, upmBuzzer.BUZZER_MI,
              upmBuzzer.BUZZER_FA, upmBuzzer.BUZZER_SOL, upmBuzzer.BUZZER_LA,
              upmBuzzer.BUZZER_SI];

    # Print sensor name
    print(buzzer.name())

    # Play sound (DO, RE, MI, etc.), pausing for 0.1 seconds between notes
    for chord_ind in range (0,7):
        # play each note for a half second
        print(buzzer.playSound(chords[chord_ind], 500000))
        time.sleep(0.1)

    print("exiting application")

    # Delete the buzzer object
    del buzzer
Exemplo n.º 3
0
def main():
    # Create the buzzer object using GPIO pin 5
    buzzer = upmBuzzer.Buzzer(5)
    buzzer.setVolume(0.25)

    buzzer.playSound(Fs6, 200000)
    buzzer.playSound(Fs6, 200000)
    buzzer.playSound(D6, 200000)
    buzzer.playSound(B5, 400000)
    buzzer.playSound(B5, 400000)
    buzzer.playSound(E6, 400000)
    buzzer.playSound(E6, 400000)
    buzzer.playSound(E6, 200000)
    buzzer.playSound(Gs6, 200000)
    buzzer.playSound(Gs6, 200000)
    buzzer.playSound(A6, 200000)
    buzzer.playSound(B6, 200000)
    buzzer.playSound(A6, 200000)
    buzzer.playSound(A6, 200000)
    buzzer.playSound(A6, 200000)
    buzzer.playSound(E6, 400000)
    buzzer.playSound(D6, 400000)
    buzzer.playSound(Fs6, 400000)
    buzzer.playSound(Fs6, 400000)

    time.sleep(1)
    buzzer.stopSound()

    del buzzer
def main():
    # Grove - Buzzer connected to PWM port
    buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))

    CHORDS = [
        upmBuzzer.BUZZER_DO, upmBuzzer.BUZZER_RE, upmBuzzer.BUZZER_MI,
        upmBuzzer.BUZZER_FA, upmBuzzer.BUZZER_SOL, upmBuzzer.BUZZER_LA,
        upmBuzzer.BUZZER_SI
    ]
    for i in range(0, len(CHORDS)):
        buzzer.playSound(CHORDS[i], 500000)
        time.sleep(0.1)

    del buzzer
    print('application exiting...')
def main():
    from grove import helper
    from grove.helper import helper
    helper.root_check()
    from grove.helper import SlotHelper
    sh = SlotHelper(SlotHelper.GPIO)
    butt_pin = sh.argv2pin()

    press = GroveLedButton(butt_pin)
    print "button assigned"

    #   PWM JST SLOT - PWM[12 13 VCC GND]
    buzz_pin = 12
    #
    # Create the buzzer object using RaspberryPi GPIO12
    mraa_pin = getGpioLookup("GPIO%02d" % buzz_pin)
    buzzer = upmBuzzer.Buzzer(mraa_pin)
    print "buzzer assigned"

    # define a customized event handle your self
    def cust_on_event(index, event, tm):
        print "event with code {}, time {}".format(event, tm)
        press.led.brightness = press.led.MAX_BRIGHT
        if event & Button.EV_SINGLE_CLICK:
            press.led.light(True)
            print(buzzer.playSound(upmBuzzer.BUZZER_DO, 500000))
            print "turn on  LED"
        elif event & Button.EV_DOUBLE_CLICK:
            press.led.blink()
            print(buzzer.playSound(upmBuzzer.BUZZER_DO, 250000))
            print "blink    LED"
        elif event & Button.EV_LONG_PRESS:
            press.led.light(False)
            print(buzzer.playSound(upmBuzzer.BUZZER_SI, 500000))
            print "turn off LED"

    press.on_event = cust_on_event

    i = 0
    while True:
        print "time = {}".format(i)
        i += 1
        time.sleep(1)
Exemplo n.º 6
0
def main():
    # Grove - LED Button connected to port D5
    button = GroveLedButton(5)

    # Grove - Buzzer connected to PWM port
    buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))

    def on_event(index, event, tm):
        if event & Button.EV_SINGLE_CLICK:
            print('single click')
            button.led.light(True)
            buzzer.playSound(upmBuzzer.BUZZER_DO, 500000)

        elif event & Button.EV_LONG_PRESS:
            print('long press')
            button.led.light(False)
            buzzer.playSound(upmBuzzer.BUZZER_DO, 1000000)

    button.on_event = on_event

    while True:
        time.sleep(1)
Exemplo n.º 7
0
def main():
    # Create the buzzer object using GPIO pin 5
    buzzer = upmBuzzer.Buzzer(6)

    chords = [
        upmBuzzer.BUZZER_DO, upmBuzzer.BUZZER_RE, upmBuzzer.BUZZER_MI,
        upmBuzzer.BUZZER_FA, upmBuzzer.BUZZER_SOL, upmBuzzer.BUZZER_LA,
        upmBuzzer.BUZZER_SI
    ]

    # Print sensor name
    print(buzzer.name())

    # Play sound (DO, RE, MI, etc.), pausing for 0.1 seconds between notes
    for chord_ind in range(0, 7):
        # play each note for a half second
        print(buzzer.playSound(chords[2], 500000))
        time.sleep(0.1)

    print("exiting application")

    # Delete the buzzer object
    del buzzer
butt_pin = 5
press = led_button.GroveLedButton(butt_pin)
print("button = pin 5")
# the default behavior of led is
#   single click - on
#   double click - blink
#   long press   - off

#   PWM JST SLOT - PWM[12 13 VCC GND]
buzz_pin = 12
#
print("buzzer = pin 12")
# Create the buzzer object using RaspberryPi GPIO12
mraa_pin = getGpioLookup("GPIO%02d" % buzz_pin)
print("pin acquired: {}".format(mraa_pin))
buzzer = upmBuzzer.Buzzer(mraa_pin)
print("buzzer assigned")

# Print sensor name
print("buzzer is: {}".format(buzzer.name()))

#set led off
press.led.light(False)


# define a customized event handle for button (press.led controls led)
def cust_on_event(index, event, tm):
    print("event with code {}, time {}".format(event, tm))
    press.led.brightness = press.led.MAX_BRIGHT
    if event & Button.EV_SINGLE_CLICK:
        press.led.light(True)
Exemplo n.º 9
0
Curso IoT 2017 - IFSP Piracicaba
'''

import time
import mraa
from upm import pyupm_buzzer as upmBuzzer


def desliga_buzzer(pino):
    x = mraa.Gpio(pino)
    x.dir(mraa.DIR_OUT)
    x.write(0)


pino_buzzer = 5
buzzer = upmBuzzer.Buzzer(pino_buzzer)
buzzer.setVolume(0.1)

n = 6
c = 261 * n
d = 294 * n
e = 329 * n
f = 349 * n
g = 391 * n
gS = 415 * n
a = 440 * n
aS = 455 * n
b = 466 * n
cH = 523 * n
cSH = 554 * n
dH = 587 * n
Exemplo n.º 10
0
import time
from upm import pyupm_buzzer as upmBuzzer

#Inicializa buzzer en 6
buzzer = upmBuzzer.Buzzer(6)
buzzer.stopSound()
buzzer.setVolume(0.05)

buzzer.playSound(upmBuzzer.BUZZER_RE, 900000)
time.sleep(0.1)
buzzer.playSound(upmBuzzer.BUZZER_RE, 130000)
time.sleep(0.1)
buzzer.playSound(upmBuzzer.BUZZER_SOL, 130000)
time.sleep(0.1)
buzzer.playSound(upmBuzzer.BUZZER_RE, 130000)
time.sleep(0.1)
buzzer.playSound(upmBuzzer.BUZZER_SI, 500000)
time.sleep(0.1)
Exemplo n.º 11
0
def io_setup():
    """
    io_setup: I/O setup for GPIO and Grove sensors
    Red, Green, Blue LEDs are initialized with PWM pins, period = PWM_PER us
    Rotary encoder, sound, temperature, and light sensors
    JHD1313M1 I2C display driver

    @return device_list: (list) list of all created mraa/upm objects
    Example usage: io_setup()
    """
    
    global red_led, green_led, blue_led
    global rotary_enc, sound_sensor, temp_sensor, light_sensor
    global lcd, buzzer

    devices = {}


    red_led = mraa.Pwm(RED_PIN)
    green_led = mraa.Pwm(GREEN_PIN)
    blue_led = mraa.Pwm(BLUE_PIN)

    # PWM_PER = 500 us == 2 kHz freq.
    red_led.period_us(PWM_PER)
    green_led.period_us(PWM_PER)
    blue_led.period_us(PWM_PER)

    # enable PWM and turn off LEDs
    red_led.enable(True)
    red_led.write(0)
    green_led.enable(True)
    green_led.write(0)
    blue_led.enable(True)
    blue_led.write(0)

    devices["redLED"] = red_led
    devices["greenLED"] = green_led
    devices["blueLED"] = blue_led

    # I2C addresses: 0x3E (LCD_ADDRESS), 0x62 (RGB_ADDRESS)
    lcd = groveLCD.Jhd1313m1(0, 0x3E, 0x62)
    lcd.clear()
    lcd.backlightOn()
    lcd.setColor(255, 255, 255)
    devices["lcd"] = lcd

    rotary_enc = grove.GroveRotary(ROT_PIN)
    sound_sensor = mraa.Aio(SOUND_PIN)
    temp_sensor = grove.GroveTemp(TEMP_PIN)
    light_sensor = grove.GroveLight(LIGHT_PIN)

    devices["rot"] = rotary_enc
    devices["sound"] = sound_sensor
    devices["temp"] = temp_sensor
    devices["light"] = light_sensor

    buzzer = groveBuzzer.Buzzer(BUZZ_PIN)
    buzzer.stopSound()
    buzzer.setVolume(0.125)
    devices["buzz"] = buzzer

    return devices