Louder Piezo w/alternating pins. How is it done? (Please remind me)

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mrrmay
 
Posts: 42
Joined: Sun Mar 28, 2021 11:51 am

Louder Piezo w/alternating pins. How is it done? (Please remind me)

Post by mrrmay »

I can't find the code where I can make a piezo louder by alternating the HIGH and LOW states of the pins. In my setup the piezo is on a KB2040 using pins A1 and A3. In this code `buzzer0` makes the tone and `buzzer1` is LOW.

How was it that I could alternate the pins to make it louder?

Code: Select all

import pwmio

# Create piezo buzzer PWM output.
buzzer0 = pwmio.PWMOut(board.A1, variable_frequency=True)
buzzer1= pwmio.PWMOut(board.A3, variable_frequency=True)

# Make sound for 3 seconds
for i in range(3):
    buzzer0.frequency = 440
    buzzer0.duty_cycle = 2**15  

    buzzer1.frequency = 440
    buzzer1.duty_cycle = 0
    
    time.sleep(1)


User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Louder Piezo w/alternating pins. How is it done? (Please remind me)

Post by mikeysklar »

There is a pretty good discussion on why the volume is low and what you can do (use an H-Bridge L293D) to boost volume to max.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”