Giuseppe Parrello

 

Embedded Buzzer


Introduction

With this project we will manage a buzzer, using the FTDI FT232H development board (of which there is a dedicated page on this site) and the NXP PCA9685 development board (of which there is a dedicated page on this site).

 

Connection

This buzzer must be connected to the NXP PCA9685 development board. The connection connectors are listed below:

Image Board FT232H Board PCA9685 Buzzer

FT232H - PCA9685 - BUZZER

AD0 SCL ------
AD1 + AD2 SDA ------
+5V VCC ------
GND GND ------
------ Channel 0 - PWM SIG
+5V ------ VCC
------ Channel 0 - GND GND

 

Python code

To manage this buzzer, the presence of the "PCA9685_FTDI" library is required.
The following Python code example plays the buzzer using different frequencies (with the same PWM), then it plays the buzzer using a range of PWM:

# Simple demo of of the PCA9685 PWM servo/LED controller library.
import time

# Import the PCA9685 module.
import pca9685_ftdi

# Initialise the PCA9685 using the default address (0x40).
pwm = pca9685_ftdi.PCA9685_FTDI()

# Configure min and max pulse lengths
SERVOMIN   = 0     # This is the 'minimum' pulse length count (out of 4096)
SERVOMAX   = 4095  # This is the 'maximum' pulse length count (out of 4096)
FREQ_STEP  = 25
PWM_STEP   = 20

# our channel # counter
channel = 0

print('\nPlaying buzzer on channel 0, press Ctrl-C to quit...')

try:

    print("\nSetting several frequencies with the same PWM...")
    for pulselen in range(5, SERVOMAX, FREQ_STEP):
        pwm.set_pwm_freq(pulselen)
        pwm.setPWM(channel, 0, 50)

    time.sleep(0.5)

    print("\nDrive buzzer using setPWM()")
    for pulselen in range(SERVOMIN, SERVOMAX, PWM_STEP):
        pwm.setPWM(channel, 0, pulselen)

    time.sleep(0.5)

    print("\nDrive buzzer using setPWM() - Reverse Mode")
    for pulselen in range(SERVOMAX, SERVOMIN, -PWM_STEP):
        pwm.setPWM(channel, 0, pulselen)

    pwm.set_all_pwm(0, 0)
    pwm.close()

except KeyboardInterrupt:
    # Capture keyboard ^C to exit the program
    print('\nYou terminated the program. The program ends!')
    pwm.set_all_pwm(0, 0)
    pwm.close()