# Adafruit STEMMA Piezo Driver Amp

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/124/208/medium800/adafruit_products_5791-06.jpg?1693921333)

Piezos make noise when you put an AC voltage across them - and the bigger the voltage, the louder they are. With your standard 3V logic microcontroller you can make 3 volts peak to peak (Vpp) with a PWM out, or 6Vpp differential with two complementary outputs. But what if you want even louder? Or if you're using a piezo to sense distance using ultrasonic bounces?

![](https://cdn-learn.adafruit.com/assets/assets/000/124/209/medium800/adafruit_products_5791-05.jpg?1693921369)

We found the nifty [PAM8904](https://www.digikey.com/short/p9bwzp2t), which is an amplifier specifically designed for driving piezo elements - and unlike audio amplifiers, it's good for up to 300 KHz! It's a switched-cap piezo driver that has bridge-tied load (BTL) output and up to 3x voltage multiplication thanks to a built-in boosting circuit for up to ~13Vpp.

We whipped up a quick breakout in our 2mm JST-PH STEMMA form-factor to make it easy for anyone who wants to beep their boops very loudly.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/210/medium800/adafruit_products_5791-02.jpg?1693921436)

Usage is easy: power with 3 to 5VDC on the Vin and GND pins. Then provide a square wave on the signal pin, from 20Hz to 300KHz - any duty cycle is ok but 50% will probably work best. There's a dual DIP switch to set the gain: you can set it to off (zero gain), x1 gain, x2 gain and x3 gain. The output is differential, so 2x gain will give you 4xVin peak-to-peak across the piezo lines. Connect your piezo to the terminal block and you're ready to rock.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/211/medium800/adafruit_products_5791-04.jpg?1693921469)

 **Please note: If you are powering the driver from 5VDC, don't set the gain to x3 because the 15V output is higher than the driver is specified for.** (Yeah we also sorta wondered why the chip manufacturer allows it). So if you are using **3.3V power, x3 gain is OK** and will give you about 10V out but if you're powering with **5V use 2x gain** max to keep the max voltage at 10V.

[Piezo element](https://www.adafruit.com/product/1739) and [3-pin JST PH cable](https://www.adafruit.com/product/3893) not included! But we stock 'em in the shop if you want to pick up separately.

# Adafruit STEMMA Piezo Driver Amp

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/124/212/medium800/adafruit_products_5791-05.png?1693921659)

## Power Pins

- **VIN** - This is the power pin - provide between 2.3 to 5V DC
- **GND** - This is common ground for power and logic.

## I/O Pins

- **SIG** - The signal input pin. Provide a square wave from 20Hz to 300KHz to output to the attached piezo. The signal level does not have to match the power voltage level
- **VO+** - The positive output for a piezo.&nbsp;
- **VO-** - The negative output for a piezo.&nbsp;

## STEMMA Connector

The **STEMMA connector** is located on the left side of the front of the board, to the left of the **Gain** DIP switch. You can use a **STEMMA JST PH 2mm 3-pin cable** to connect the driver to your microcontroller board, for example [this cable](https://www.adafruit.com/product/3893) to connect using a breadboard.

The STEMMA connector has the following pins:

- **SIGNAL** **(white wire)** - Signal input pin
- **VIN (red wire)** - Power pin, 3-5VDC
- **GND (black wire)** - Ground pin.

## Terminal Block

The **terminal block** is located on the right side of the front of the board, above the **PAM8904** label on the board silk.

The block has the following terminals:

- **VO+** - This terminal is towards the top of the board, and is located next to the **x1** label on the board silk. It is the same as the VO+ pin. Connect the positive wire on your piezo to this terminal.
- **VO-** - This terminal is towards the bottom of the board and is located next to the **PAM8904** label on the board silk. It is the same as the VO- pin. Connect the negative wire on your piezo to this terminal.

## Gain Selector Switch

- **Gain** - The dual DIP switch at the top of the board lets you adjust the gain output from the PAM8904. You can set it to off (zero gain), **x1** gain by flipping the **x1** switch to **ON** , **x2** gain by flipping the **x2** switch to **ON** and x3 gain by flipping both the **x1** and **x2** switches to **ON**. The output is differential so 2x gain will give you 4xVin peak-to-peak across the piezo lines.

**Please note: If you are powering the driver from 5VDC, don't set the gain to x3 because the 15V output is higher than the driver is specified for.** So if you are using **3.3V power, x3 gain is OK** and will give you about 10V out but if you're powering with **5V use 2x gain max** to keep the max voltage at 10V.

Warning: 

## Power LED and Jumper

- **Power LED -** On the front of the board, below the JST-PH connector, is the power LED, labeled **ON**. It is a green LED.
- **Power LED jumper** - In the lower right corner on the back of the board is a jumper for the power LED. It is labeled **LED** on the board silk. To disable the power LED, cut the trace on this jumper. To enable it again, solder the pads back together.

## Signal LED and Jumper

- **Signal LED -** On the front of the board, above the JST-PH connector, is the signal LED, labeled **Sig**. It is a red LED. It will light-up every time a signal is received on the signal pin.
- **Signal LED jumper** - In the upper right corner on the back of the board is a jumper for the signal LED. It is labeled **SIG** on the board silk. To disable the signal LED, cut the trace on this jumper. To enable it again, solder the pads back together.

# Adafruit STEMMA Piezo Driver Amp

## CircuitPython and Python

It's easy to use the **STEMMA Piezo Driver Amp** with Python or CircuitPython, and the [pwmio](https://docs.circuitpython.org/en/latest/shared-bindings/pwmio/index.html) module. This module allows you to easily write Python code to control pulse width modulation (PWM).

You can use this driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

## CircuitPython Microcontroller Wiring

First wire up a driver to your board exactly as follows along with a piezo element. The following is the driver wired to a Feather RP2040 using the STEMMA JST-PH connector:

- **Board 3.3V** to **driver VIN (red wire)**
- **Board GND** to **driver GND (black wire)**
- **Board pin 5** to **driver SIG (white wire)**
- **Driver VO+** to **piezo positive (red wire)**
- **Driver VO-** to **piezo negative (black wire)**

![adafruit_products_feather_stemma_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/223/medium640/adafruit_products_feather_stemma_bb.jpg?1693930534)

The following is the adapter wired to a Feather RP2040 using a solderless breadboard:

- **Board 3.3V** &nbsp;to&nbsp;**driver VIN (red wire)**
- **Board GND** &nbsp;to&nbsp;**driver GND (black wire)**
- **Board pin 5** &nbsp;to&nbsp;**driver SIG (white wire)**
- **Driver VO+** &nbsp;to&nbsp;**piezo positive (red wire)**
- **Driver VO-** &nbsp;to&nbsp;**piezo negative (black wire)**

![adafruit_products_feather_bb_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/224/medium640/adafruit_products_feather_bb_bb.jpg?1693930658)

## Python Computer Wiring

Since there are _dozens_ of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux). [pwmio](https://docs.circuitpython.org/en/latest/shared-bindings/pwmio/index.html) will also need to be implemented for your board.

Here's the Raspberry Pi wired using the STEMMA JST-PH connector:

- **Pi 3.3V** to **driver VIN (red wire)**
- **Pi GND** to **driver GND (black wire)**
- **Pi GPIO 5** to **driver SIG (white wire)**
- **Driver VO+** to **piezo positive (red wire)**
- **Driver VO-** to **piezo negative (black wire)**

![adafruit_products_pi_stemma_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/225/medium640/adafruit_products_pi_stemma_bb.jpg?1693930771)

Here's the Raspberry Pi using a solderless breadboard:

- **Pi 3.3V** to **driver VIN (red wire)**
- **Pi GND** to **driver GND (black wire)**
- **Pi GPIO 5** to **driver SIG (white wire)**
- **Driver VO+** to **piezo positive (red wire)**
- **Driver VO-** to **piezo negative (black wire)**

![adafruit_products_pi_bb_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/226/medium640/adafruit_products_pi_bb_bb.jpg?1693930864)

## Python Setup

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require verifying you are running Python 3. [Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

`pwmio` is a built-in module and does not need to be installed separately using `pip`. Make sure to check that `pwmio` is supported on your platform though if you aren't using something more common like a Raspberry Pi.

## CircuitPython Usage

To use with CircuitPython, you need to update **code.py** with the example script.

Thankfully, we can do this in one go. In the example below, click the **Download Project Bundle** button below to download the **code.py** file in a zip file. Extract the contents of the zip file, and copy the **code.py** file to your **CIRCUITPY** drive. The example uses built-in modules, so no additionally libraries need to be copied to the **CIRCUITPY/lib** folder.

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/Piezo_Driver_Examples_CircuitPython_Piezo_Driver_Example.png )

## Python Usage

Copy or download the following example to your computer, and run the following, replacing **code.py** with whatever you named the file:

`python3 code.py`

## Example Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Piezo_Driver_Examples/CircuitPython_Piezo_Driver_Example/code.py

When you run the example code, you'll hear an ascending C major scale through the piezo element on a loop. Use the gain DIP switch to adjust the gain for the piezo element.

### Python Note

If you run this example on a Raspberry Pi, you'll see this printed to the serial console when the code starts running:

`Variable Frequency is not supported, continuing without it...`

After that you'll hear the tones being played through the piezo element.

# Adafruit STEMMA Piezo Driver Amp

## Python Docs

# Adafruit STEMMA Piezo Driver Amp

## Arduino

Using the STEMMA Piezo Driver Amp with Arduino involves wiring up the adapter to your Arduino-compatible microcontroller, attaching a piezo element to the driver and running the provided example code.

## Wiring

Wire as shown for a **5V** board like an Uno. If you are using a **3V** board, like an Adafruit Feather, wire the board's 3V pin to the driver VIN.

Here is an Adafruit Metro wired up to the driver using the STEMMA JST-PH connector:

- **Board 5V** to **driver VIN (red wire)**
- **Board GND** to **driver GND (black wire)**
- **Board pin 5** to **driver SIG (white wire)**
- **Driver VO+** to **piezo positive (red wire)**
- **Driver VO-** to **piezo negative (black wire)**

![adafruit_products_metro_stemma_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/227/medium640/adafruit_products_metro_stemma_bb.jpg?1693931708)

Here is an Adafruit Metro wired up using a solderless breadboard:

- **Board 5V** to **driver VIN (red wire)**
- **Board GND** to **driver GND (black wire)**
- **Board pin 5** to **driver SIG (white wire)**
- **Driver VO+** to **piezo positive (red wire)**
- **Driver VO-** to **piezo negative (black wire)**

![adafruit_products_metro_bb_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/228/medium640/adafruit_products_metro_bb_bb.jpg?1693931745)

 **Please note: If you are powering the driver from 5VDC, don't set the gain to x3 because the 15V output is higher than the driver is specified for.** If you're powering with **5V use 2x gain max** to keep the max voltage at 10V.

Warning: 

## Example Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Piezo_Driver_Examples/Arduino_Piezo_Driver_Example/Arduino_Piezo_Driver_Example.ino

Upload the sketch to your board and open up the Serial Monitor ( **Tools -\> Serial Monitor** ) at 115200 baud. You'll see the tone frequencies printed to the Serial Monitor as they are played through the piezo element. Use the gain DIP switch to adjust the gain for the piezo element.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/229/medium800/adafruit_products_arduino_serial.png?1693931864)

# Adafruit STEMMA Piezo Driver Amp

## Arduino Docs

# Adafruit STEMMA Piezo Driver Amp

## Downloads

## Files

- [PAM8904 Datasheet](https://cdn-learn.adafruit.com/assets/assets/000/124/205/original/PAM8904E.pdf?1693920924)
- [EagleCAD PCB Files on GitHub](https://github.com/adafruit/Adafruit-STEMMA-Piezo-Driver-Amp-PCB)
- [Fritzing object in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20STEMMA%20Piezo%20Driver%20Amp.fzpz)

## Schematic and Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/124/206/medium800/adafruit_products_schem.png?1693921128)

![](https://cdn-learn.adafruit.com/assets/assets/000/124/207/medium800/adafruit_products_fab.png?1693921135 dimensions are in inches)


## Primary Products

### Adafruit STEMMA Piezo Driver Amp - PAM8904

[Adafruit STEMMA Piezo Driver Amp - PAM8904](https://www.adafruit.com/product/5791)
Piezos make noise when you put an AC voltage across them: and the bigger the Vpp the louder they are. With your standard 3V logic microcontroller you can make 3Vpp with a PWM out, or 6Vpp differential with two complimentary outputs. But what if you want even louder? Or if you're using...

In Stock
[Buy Now](https://www.adafruit.com/product/5791)
[Related Guides to the Product](https://learn.adafruit.com/products/5791/guides)

## Featured Products

### Large Enclosed Piezo Element w/Wires

[Large Enclosed Piezo Element w/Wires](https://www.adafruit.com/product/1739)
This large (30mm diameter) piezo element is nicely enclosed with mounting holes so you can attach easily. Piezo elements convert vibration to voltage or voltage to vibration. That means you can use this as a buzzer for making beeps, tones and alerts AND you can use it as a sensor, to detect...

In Stock
[Buy Now](https://www.adafruit.com/product/1739)
[Related Guides to the Product](https://learn.adafruit.com/products/1739/guides)
### STEMMA JST PH 2mm 3-Pin to Male Header Cable - 200mm

[STEMMA JST PH 2mm 3-Pin to Male Header Cable - 200mm](https://www.adafruit.com/product/3893)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with high-quality 0.1" male header plugs on the end. We're carrying these to match up with our Hallowing, for extending and connecting sensors or LEDs - and the wires are even color coded!

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3893)
[Related Guides to the Product](https://learn.adafruit.com/products/3893/guides)
### STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm

[STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm](https://www.adafruit.com/product/3894)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with high-quality 0.1" female header sockets on the end. We're carrying these to match up with our Hallowing, for extending and connecting sensors or LEDs - and the wires are even color coded!

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3894)
[Related Guides to the Product](https://learn.adafruit.com/products/3894/guides)
### JST PH 2mm 3-pin Plug-Plug Cable - 100mm long

[JST PH 2mm 3-pin Plug-Plug Cable - 100mm long](https://www.adafruit.com/product/4336)
This cable is a little over 100mm / 4" long&nbsp;and fitted with JST-PH 3-pin connectors on either end.&nbsp;

We dig the solid and compact nature of these connectors and the latch that keeps the cable from coming apart easily. We're carrying these to <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4336)
[Related Guides to the Product](https://learn.adafruit.com/products/4336/guides)
### JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable

[JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable](https://www.adafruit.com/product/4030)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with grippy mini alligator clips. We're carrying these to match up with any of our boards or breakouts with 3-pin 'STEMMA' connectors on them such as the&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4030)
[Related Guides to the Product](https://learn.adafruit.com/products/4030/guides)

## Related Guides

- [PowerWash Simulator Nozzle Controller](https://learn.adafruit.com/powerwash-simulator-nozzle-controller.md)
- [Raspberry Pi Care and Troubleshooting](https://learn.adafruit.com/raspberry-pi-care-and-troubleshooting.md)
- [Ultrasonic Sonar Distance Sensors](https://learn.adafruit.com/ultrasonic-sonar-distance-sensors.md)
- [Adafruit 2.8" PiTFT - Capacitive Touch](https://learn.adafruit.com/adafruit-2-8-pitft-capacitive-touch.md)
- [BLE Thermal "Cat" Printer with CircuitPython](https://learn.adafruit.com/ble-thermal-cat-printer-with-circuitpython.md)
- [Adafruit RS232 Pal](https://learn.adafruit.com/adafruit-rs232-pal.md)
- [Circuit Playground-O-Phonor](https://learn.adafruit.com/circuit-playground-o-phonor.md)
- [Adafruit MOSFET Driver](https://learn.adafruit.com/adafruit-mosfet-driver.md)
- [Adafruit BH1750 Ambient Light Sensor](https://learn.adafruit.com/adafruit-bh1750-ambient-light-sensor.md)
- [reef-pi Guide 5: Light Controller](https://learn.adafruit.com/reef-pi-lighting-controller.md)
- [Network Interface Failover using FONA](https://learn.adafruit.com/network-interface-failover-using-fona.md)
- [Adafruit Feather M4 Express](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51.md)
- [Scrolling Countdown Timer](https://learn.adafruit.com/scrolling-countdown-timer.md)
- [Clue Coffee Scale](https://learn.adafruit.com/clue-coffee-scale.md)
- [Nunchuck Controlled Laser Cat Toy](https://learn.adafruit.com/nunchuck-controlled-laser-cat-toy.md)
