Just tried this on the IO Expander. It provided tones louder than the built in PRESTO PIEZO buzzer. You need to calculate and adjust the period to change the tone.
Example code below:
# IO_PWM Buzzer
# Passive buzzer on IO Expander: +ve on pin 1, -ve on GND
# Tony Goodhew 25th April 2025
import time
from pimoroni_i2c import PimoroniI2C
from breakout_ioexpander import BreakoutIOExpander
'''
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
'''
PINS_PRESTO = {"sda": 40, "scl": 41}
ioe_pwm_pin = 1
# Settings to produce a 50Hz output from the 24MHz clock.
# 24,000,000 Hz / 8 = 3,000,000 Hz
# 3,000,000 Hz / 60,000 Period = 50 Hz
divider = 8
period = 60000
i2c = PimoroniI2C(**PINS_PRESTO)
ioe = BreakoutIOExpander(i2c, address=0x18)
# 50Hz
ioe.set_pwm_period(period)
ioe.set_pwm_control(divider)
ioe.set_mode(ioe_pwm_pin, BreakoutIOExpander.PIN_PWM)
duty_cycle = 32000
ioe.output(ioe_pwm_pin, duty_cycle) # 50 Hz tone
time.sleep(0.5)
ioe.output(ioe_pwm_pin, 0)
time.sleep(1)
# 256 Hz
period = 11719
ioe.set_pwm_period(period)
ioe.set_mode(ioe_pwm_pin, BreakoutIOExpander.PIN_PWM)
duty_cycle = 32000
ioe.output(ioe_pwm_pin, duty_cycle) # 256 Hz tone
time.sleep(0.5)
duty_cycle = 0
ioe.output(ioe_pwm_pin, 0)
It might be that the internal piezo is just underpowered with 3V3. I did various things with my buzzers and I always used 5V. But even then there are differences.
I can confirm that with this script above I heard the buzzer of the presto. Weak and with high pitched tones.
I also used the 2nd script from Tonygo2 with an external passive buzzer via a Pimoroni Breakout IOExpander with the buzzer connected to PWM Pin 3. That also worked however also weak sound, a little stronger than the buzzer of the Presto.
@Tonygo2 , @paulsk : are you really using a passive buzzer? These buzzers need three pins: VCC, GND and signal. On the images I can only see two cables going to the buzzer. The signal pin drives a transistor and that turns the power on/off. With two pins, you only provide power/GND and the rest is internal within the buzzer (that is why they are called “active” buzzers).
Raw buzzers always have two pins. To distinguish the type, just connect to power and ground - if you only hear a click, it is a passive buzzer, otherwise you can hear a tone. Driving these active buzzers from a 3V3 GPIO might not be enough, but I have some that are very loud.
Passive buzzers need electronics, so you better buy a small PCB which has the electronics integrated. Look for “KY-006” or “HW-508”. Active buzzers are sold as “KY-012”. Watch out: you will find active buzzers with three pins, but then one is not connected. So the pin count alone is not useful to differentiate.
Unfortunately, the PRESTO does not provide a 5V supply so driving at 5V requires additional external power. We would also need a voltage shifter or a transistor to switch from 3.3V to the 5V of the buzzer +ve pin.
We want to change the tones - not have a fixed frequency buzz.
The main difference between active and passive buzzers lies in their internal oscillator. Active buzzers have a built-in oscillator, allowing them to produce sound with a simple DC power supply, while passive buzzers lack an oscillator and require an external AC signal to generate sound.
Here’s a more detailed breakdown:
Active Buzzer:
Internal Oscillator: Contains a built-in oscillator that generates a specific frequency, typically a fixed tone.
Self-Contained: Requires only a DC power source to produce sound.
Simple to Use: Easy to control, often just by turning on or off the power supply.
Fixed Tone: Produces a single, predetermined tone.
Passive Buzzer:
No Internal Oscillator: Requires an external AC audio signal to create sound.
External Signal Required: Needs an external source to generate the sound wave.
More Versatile: Can produce various tones and melodies by varying the frequency of the applied signal.
Requires More Control: Requires more complex circuitry or microcontroller control to generate different tones.*
The main thing is: an active buzzer has an internal oscillator (that has a fixed frequency), the passive buzzer needs the external signal which is the PWM you produce. This will give you different frequencies.
In your image you only have two wires connected to the buzzer and I don’t see any transistor in your wiring. I think you are passing the signal (PWM) to the voltage pin of an active buzzer. So you are driving the active buzzer with the current that is provided by the GPIO-pin. Although this does give you some sort of frequency variation, you won’t have the full tonal range of a passive buzzer (which is not great, but large enough for example for playing the first Bach Prelude).
Not having 5V only affects loudness. 3V3 is ok, but 5v is better if you need more volume.
All of these buzzers are driven by 3V3 GPIOs from the Pico, but are connected to the 5V power source. No problem. All of them still have a different loudness, but that is due to the fact that they are probably from different batches.
I have to correct my last post: the buzzer I used in the last test is an active buzzer. It has a model marking on the side: TMB12A05. It came with a box for experiments with an Arduino Mega 2560 which I bought in 2019. The box contains this Active buzzer and a Passive buzzer. I am going to connect also the Passive one. Btw: both have only two pins each. Both have a clear marking for which is the “Plus” potential wire, A circle with a ‘+’ sign inside. images
These little black cylinders can contain the necessary electronics (active buzzer) or not (passive buzzer). The buzzer itself is only the piezo. The PCBs I was referring above connect these two pin raw buzzers with the necessary electronics.
Most probably you should see a difference in height: the active buzzer is a tad taller than the passive buzzer. And if you open it (don’t do it, rather google for images), you will see the internal electronics like the builtin oscillator.
As written above, just connect power and ground to both pins and listen. The active buzzer will give you a tone, the passive buzzer just clicks (which is barely audible).
Driving the power pin of a raw passive buzzer with PWM does produce some noise, but without the transistor in between you don’t get the current amplification of the transistor circuit and you won’t hear much.
Maybe your experimentation box also contains a suitable transistor?
Thank you for the explanation and for the suggestion to use a transistor for amplification.
I leave my contribution by this. I just wanted to let you guys know my experience with the buzzer builtin to the Presto. Have a nice weekend all!
If you want to make noise\play tunes\music? the Explorer board is a much better bet. It make really good sounds. For PRESTO, a buzzer on the IO Expander makes more noise than the built in one but is more difficult to control.
Different devices is certainly a good bet. The schematic does not specify the exact piezo, so it is hard to tell if the 3V3 are a recommended voltage for the piezo on the Presto.
Another thing is current: the 3V3 of the Presto is from a regulator that provides at most 330mA, which is a bit low for everything connected. This also affects the IO-Expander, if you power it from the 3V3 Presto.
For your specific setup: you drive the load (buzzer) directly from the GPIO. You only do this if you are sure that the load does not overload the GPIO. I think this is ok for the buzzer, but the volume might be limited due to what the GPIO provides.