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 Pynq-Z1 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 import Overlay

1. Illustrate playing a pre-defined melody

In [2]:
from pynq.iop import Grove_Buzzer
from pynq.iop import PMODB
from pynq.iop import PMOD_GROVE_G1 

grove_buzzer = Grove_Buzzer(PMODB, PMOD_GROVE_G1)

2. Play a piece of music

In [3]:

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

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.iop import ARDUINO
from pynq.iop import Arduino_Analog
from pynq.iop import ARDUINO_GROVE_A1

analog1 = Arduino_Analog(ARDUINO, ARDUINO_GROVE_A1)

rounds = 200

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