Grove Buzzer v1.2

This example shows how to use the Grove Buzzer v1.2.

A Grover Buzzer, and PYNQ Grove Adapter are required.

To set up the board for this notebook, the PYNQ Grove Adapter is connected to PMODB and the Grove Buzzer is connected to G1 on the PYNQ Grove Adapter.


In [1]:
from pynq.overlays.base import BaseOverlay
base = BaseOverlay("base.bit")

1. Illustrate playing a pre-defined melody


In [2]:
from pynq.lib.pmod import Grove_Buzzer
from pynq.lib.pmod import PMOD_GROVE_G1 

grove_buzzer = Grove_Buzzer(base.PMODB,PMOD_GROVE_G1)

2. Play a piece of music


In [3]:
grove_buzzer.play_melody()

3. Generate a tone of desired period and for a desired number of times

The tone_period is in microseconds and the 50% duty cycle will be generated for the given tone_period


In [4]:
# Play a tone
tone_period = 1200
num_cycles = 500
grove_buzzer.play_tone(tone_period,num_cycles)

4. Controlling the tone

This example will use a grove potentiometer to control the tone of the sound. Plug the potentiometer into A1 group on the shield.


In [5]:
from pynq.lib.arduino import Arduino_Analog
from pynq.lib.arduino import ARDUINO_GROVE_A1


analog1 = Arduino_Analog(base.ARDUINO,ARDUINO_GROVE_A1)

rounds = 200

for i in range(rounds):
    tone_period = int(analog1.read_raw()[0]/5)
    num_cycles = 500
    grove_buzzer.play_tone(tone_period,50)