Maker.io main logo

Audio Codec Breakout - WM8960 Hookup Guide

2024-01-16 | By SparkFun Electronics

License: See Original Project Wireless ESP32

Courtesy of SparkFun

Guide by QCPETE, BBOYHO

Introduction

The SparkFun Audio Codec Breakout - WM8960 is a low power, high quality stereo codec with 1W ‎Stereo Class D speaker drivers and headphone drivers. The WM8960 acts as a stereo audio ADC ‎and DAC, and communicates using I2S, a standard audio data protocol (not to be confused with I2C). ‎This audio codec is chock full of features some of which includes advanced on-chip digital signal ‎processing for automatic level control (ALC) for the line or microphone input, programmable gain ‎amplifier (PGA), pop and click suppression, and its ability to configure I2S settings and analog audio ‎path through software via I2C.‎

SparkFun Audio Codec Breakout - WM8960 (Qwiic)‎

SparkFun Audio Codec Breakout - WM8960 with Headers ‎‎(Qwiic)‎

 

Required Materials

To follow along with this tutorial, you will need the following materials at a minimum. You may not ‎need everything though depending on what you have. Add it to your cart, read through the guide, ‎and adjust the cart as necessary. Note that the Wishlist does not include any microphones or ‎speakers.‎

Audio Codec WM8960 Wishlist SparkFun Wish List

VIEW AUDIO CODEC WM8960 WISHLIST ON SPARKFUN.COM

Note: For users interested in just the wireless speaker and example 9, check out the SparkFun ‎Qwiic Wireless Speaker Kit below! The kit includes a TRRS breakout with headers instead of the ‎TRS breakout. RING2 of the TRRS connector also connects to the TRS cable's sleeve. When ‎wiring your circuit up, we recommend connecting to the sleeve in case you have a headphone with ‎a TRRS connector. The kit also includes a mini amplified speaker.

Arduino Microcontroller

You will need an Arduino microcontroller to configure the WM8960. We recommend the Espressif's ‎ESP32 WROOM. For the scope of this tutorial, we will be using the IoT RedBoard ESP32 - ‎Development Board since it already includes female headers on the board to connect jumper wires ‎to the WM8960.‎

Differential Microphone Input

Below is a differential microphone from the catalog that you can connect as a differential ‎microphone input. Note that you will need a resistor and the MICBIAS pin to connect to the eletret ‎microphone.‎

Single Ended Microphone Input

Below are a few electret and MEMS microphones from the catalog that you can connect as a single ‎ended microphone input.‎

Differential Speaker Output

Below are a few speakers from the catalog that you could use as an output. You will want to choose ‎differential speakers like the following listed below (not to be confused by the piezo buzzers). Note ‎that some speakers may perform better than others at certain frequencies while others operate ‎around a certain frequency range. Make sure to check out the speaker's datasheet when choosing ‎a speaker.‎

Note that some speakers may be rated as a higher wattage (more than what the Audio Codec's ‎speaker driver can output). Higher wattage speakers will still play sound, but they won't be fully ‎powered.‎

Note: Amplified speakers that have a 3.5mm TRS audio connector can also be used. However, you ‎will not be using the speaker output channels. Users can connect the headphone output to ‎amplified speakers with a TRS audio connector as well. The hamburger mini speaker could be one ‎option.

Looking for more power? Try connecting the audio codec's headphone output to another ‎external amplifier like the Qwiic Speaker Amp. The Qwiic Speaker Amp is capable of driving 4Ω ‎speakers at up to 2.8W in stereo, and 8Ω speakers at up to 1.7W in stereo.

Audio Accessories

Depending on your setup, you may need an adapter or cable for the TRS audio connection for line ‎level input or headphone output.‎

You can also use a TRRS breakout instead of the TRS breakout listed above. RING2 of the TRRS ‎connector also connects to the TRS cable's sleeve. When wiring your circuit up, we recommend ‎connecting to the sleeve in case you have a headphone with a TRRS connector.‎

Tools

You will need a soldering iron, solder, and general soldering accessories for a secure connection ‎when using the plated through hole pads.‎

Prototyping Accessories

Depending on your setup, you may want to use IC hooks for a temporary connection. However, you ‎will want to solder header pins to connect devices to the plated through holes for a secure ‎connection. Note that you will need to breakaway the male header pins or cut the female header ‎pins down to fit the two rows of 1x16 PTH on the breakout. Of course, you could also solder wire ‎as well.‎

For users that are interested in adding an input to adjust volume or modes, you can add a trimpot ‎and button to the setup. A few of the examples used in this tutorial use the trimpot to adjust. You ‎will need to add a few lines of code if you want to toggle certain modes (i.e., 3D enhance, loopback, ‎etc.) or if you decided to use buttons to turn up or down the volume. For advanced users using ‎their own differential microphones, you will need to add a 2.2kΩ resistor in series with each ‎microphone. Other passives like capacitors may also be needed depending on your application.‎

For those that want to take advantage of the Qwiic enabled devices, you'll want to grab a Qwiic cable.

You Will Also Need

Depending on your setup, you will also need some sort of audio source. This can be from your ‎smartphone or computer. Most of the examples listed in this tutorial will output the audio through ‎the headphones. You will also need to have a pair of headphones with a 3.5mm TRS audio jack on ‎the end.‎

  • Audio Source
    • MP3 Player
    • Bluetooth ® Audio Device (e.g., smartphone, computer, transmitter)
  • Headphones with 3.5mm TRS Audio Jack

Suggested Reading

If you aren't familiar with the MicroMod ecosystem, we recommend reading here for an overview if ‎you decide to take advantage of the Qwiic connector.‎

qwiic_1

Qwiic Connect System

If you aren’t familiar with the following concepts, we also recommend checking out a few of these ‎tutorials before continuing. Make sure to check the respective hookup guides for your ‎microcontroller to ensure that you are installing the correct USB-to-serial converter. You may also ‎need to follow additional instructions that are not outlined in this tutorial to install the appropriate ‎software.‎

  • How to Solder: Through-Hole Soldering: This tutorial covers everything you need to ‎know about through-hole soldering.‎
  • Analog to Digital Conversion: The world is analog. Use analog to digital conversion to help ‎digital devices interpret the world.‎
  • How to Use a Breadboard: Welcome to the wonderful world of breadboards. Here we will ‎learn what a breadboard is and how to use one to build your very first circuit.‎
  • I2C: An introduction to I2C, one of the main embedded communications protocols in use today.‎
  • SparkFun Serial Basic CH340C Hookup Guide: SparkFun Serial Basic Breakout takes ‎advantage of USB-C and is an easy-to-use USB-to-Serial adapter based on the CH340C IC from ‎WCH. With USB-C you can get up to three times the power delivery over the previous USB ‎generation and has the convenient feature of being reversable.‎
  • Installing Board Definitions in the Arduino IDE: How do I install a custom Arduino ‎board/core? It's easy! This tutorial will go over how to install an Arduino board definition using the ‎Arduino Board Manager. We will also go over manually installing third-party cores, such as the ‎board definitions required for many of the SparkFun development boards.‎
  • IoT RedBoard ESP32 Development Board Hookup Guide: Delve into the ‎functionality-rich world of the IoT RedBoard ESP32 Development Board!‎

Hardware Overview

We broke out the pins of the WM8960 onto a breakout board to standard 0.1" spaced PTH. We'll ‎highlight relevant application circuits, hardware, and pins that are broken out in this section.‎

audio_2

Top View

audio_3

Bottom View

Keep in mind that the WM8960 is chock full of features as you can see from the datasheet's block ‎diagram below. The input and output will depend on your project's needs. We recommend ‎referencing the block diagrams listed in the datasheet to follow along. For more information, check ‎out the datasheet linked in the Resources and Going Further.‎

diagram_4

Block diagram from the WM8960 Datasheet (v4.2) on page 1.‎

Power

There are a variety of power and power-related nets broken out to the Qwiic connector and through ‎hole pads on the edge of the board. The nets consist of the following.‎

  • VIN - Voltage input for the analog and speaker circuits. The input voltage is ‎between 3.7V and 5.5V.‎
    • SPKVDD - By default, the VIN pin is connected directly to SPKVDD. The connection ‎can be disabled but cutting the jumper on the back between VIN and SPKVDD. There ‎is an option to connect the SPKVDD pad to the 3V3 pin by adding a solder blob ‎between the two pads. If you decide to provide your own voltage, users will need to ‎keep the jumpers open. The recommended voltage for this pin is ‎between 2.7V and 5.5V.‎
    • AVDD - Voltage from the VIN pin is regulated down to 3.3V from the XC6222 ‎‎3.3V/700mA voltage regulator. This voltage is used to power the analog circuit. For ‎users that want to provide their own voltage, cut the jumper on the back of the board ‎labeled as AVDD-ISO. The recommended voltage for this pin is ‎between 2.7V and 3.6V.
  • 3V3 - This pin is broken out on the edge of the board as well as the Qwiic connector. This ‎voltage is used to power the digital circuit. This voltage is tied to the IC's DCVDD and DBVDD ‎pins. Note that this is on a separate net and not connected to the 3.3V voltage regulator. The ‎recommended voltage for this pin is between 1.7V and 3.6V. This will typically be 3.3V when ‎connecting to a microcontroller's 3.3V voltage regulator and Qwiic connector.
  • GND - Common, ground voltage (0V reference) for the system.‎

power_5

To get started powering the audio codec, you will just need to provide power to ‎the VIN and 3V3 pins. We recommend using your development board's voltages without adjusting ‎the jumpers. For example, the IoT RedBoard - ESP32 Development Board can provide 5V through ‎the female header and 3.3V through the Qwiic connector. Users can connect 5V to the audio ‎codec's VIN pin to power the analog and speaker circuit. To power the digital circuit, users can ‎provide 3.3V by adding a Qwiic cable between the Qwiic connectors. Of course, you will need to ‎also connect your reference voltage for your system. By using the Qwiic cable, you will be ‎connecting GND on both boards.‎

Warning! If you decide to cut the trace between VDD and SPKVDD to connect SPKVDD to 3V3, ‎make sure to avoid any shorts between VDD and SPKVDD. If you place an input voltage on VIN that ‎is higher than 3V3 pin is rated for will damage the WM8960 and anything connected to 3V3. ‎

For users providing their own power supply for SPKVDD and AVDD, make sure to keep the ‎jumpers open.‎

Enable Pin

The enable pin (labeled as en) on the edge of the board is active low. Pulling the pin low will ‎disable the 3.3V voltage regulator XC6222 that is connected to AVDD.‎

pin_6

Digital Audio Interface

The board breaks out pins for the digital audio interface. This is used for inputting DAC data into ‎the WM8960 and outputting ADC data from the IC.‎

  • BCLK - Bit clock, for synchronization. This can be set as an input or output depending on the ‎configuration.
  • DLRC or DACLRC - DAC data left and right alignment clock. This can be set as an input or ‎output depending on the configuration.‎
  • DDAT or DACDAT - DAC data input.‎
  • ALRC or ADCLRC - ADC data left and right alignment clock. This can be set as an input or ‎output depending on the configuration.‎
    • This pin can also be configured as a GPIO pin (e.g., GPIO1). As stated in the ‎datasheet, the ADC will use the DACLRC as a frame clock for the ADCs and DACs. ‎The ADCLRC/GPIO1 pin function should not be modified when the ADC is enabled. ‎For more information check out the section about the Digital Audio Interface in the ‎datasheet on pg. 48.‎
  • ADAT or ADCDAT - ADC data output.‎

digital_7

Four audio data formats listed below are supported.‎

  • Left justified
  • Right justified
  • I2S (not to be confused with I2C)
  • DSP

Qwiic and I2C

The board includes one Qwiic connector to configure the I2S settings and analog audio path. For ‎users that need to solder directly to the board, the pins are also broken out on the edge PTH. The ‎I2C data and clock lines are also tied to 2.2kΩ pull-up resistors. The default address of the WM8960 ‎is 0x1A. Note that the datasheet shows the address as 0x34h, which is 0x1A shifted left 1 bit and ‎then includes the appended "0" (aka write bit).‎

board_8

Stereo Input

The WM8960 includes 6x flexible analog input pins. These pins can be used for line level or ‎microphone level (balanced or un-balanced). Note that balanced microphones refer to differential ‎microphones while un-balanced microphones refer to single-ended microphones.‎

  • RIN3 / RINPUT3 - Right analog input 3 pin. This is connected to RINPUT3 or JD3.‎
    • right channel, line input
    • right channel, differential +MIC input
    • jack detect input pin
  • RIN2 / RINPUT2 - Right analog input 2 pin. This is connected to RINPUT2.‎
    • right channel, line input
    • right channel, differential +MIC input
  • RIN1 / RINPUT1 - Right analog input 1 pin. This is connected to RINPUT1.
    • ‎right channel, single-ended MIC input
    • right channel, differential -MIC input
  • LIN1 / LINPUT1 - Left analog input 1 pin. This is connected to LINPUT1.
    • ‎left channel, single-ended MIC input
    • left channel differential -MIC input
  • LIN2 / LINPUT2 - Left analog input 2 pin. This is connected to LINPUT2.
    • ‎left channel, line input
    • left channel, differential +MIC input
  • LIN3 / LINPUT3 - Left analog input 3 pin. This is connected to LINPUT3 or JD2.
    • ‎left channel, line input
    • left channel, differential +MIC input
    • jack detect input pin

stero_9

Remember the block diagram that was linked earlier just before soldering the headers to the board? ‎The datasheet goes into more detail with the input path for the left and right channel.‎

Below is a modified image of the block diagram that highlights the input signal path before the left ‎ADC for the left input channels on page 19.‎

path_10

Left Input Signal Path from the WM8960 Datasheet (v4.2) on page 19.‎

Note: Note that the pins are flipped from the initial block diagram and the left input channels. ‎Instead of LINPUT3 at the top, it starts with LINPUT1.‎

Below is a modified image of the block diagram that highlights the input signal path before the right ‎ADC for the right input channels on page 20.‎

path_11

Right Input Signal Path from the WM8960 Datasheet (v4.2) on page 20.‎

Microphone Bias

The MICB or MICBIAS provides a low noise reference voltage for biasing eletret condenser ‎microphones (ECMs).‎

microphone_12

Speaker Out

The WM8960 includes differential stereo speaker outputs for the left and right speaker. The ‎speaker is rated as a class D speaker driver and can drive 1W into 8Ω speakers. For users looking ‎to power the speakers with a separate power supply, you can cut the jumper between the pads ‎labeled as SPKVDD and VIN on the back of the board.‎

  • SL+ / SPK_LP - Speaker left positive output.‎
  • SL- / SPK_LN - Speaker left negative output.
  • SR+ / SPK_RP - Speaker right positive output.
  • SR- / SPK_RN - Speaker right negative output.‎

speaker_13

Note: When wiring differential speakers to speaker out terminals, make sure to match the "+" to "+" ‎and "-" to "-" for both speakers. If one of the stereo speakers is wired "+" to "-" and "-" to +" while ‎the other speaker is wired "+" to "+" and "-" to "-", the audio signals will interfere and cancel each ‎other out. If there are no labels on the speakers, just make sure to wire the speakers consistently.‎

Headphones Output

The WM8960 can drive 16Ω and 32Ω headphones. The connection will depend on your setup. ‎Make sure to check out the Headphone Output in the datasheet on page 41 for more information.‎

  • HPL - The left headphone out will be connected to the Tip of a TRS connector.‎
  • OUT3 - This is connected to the Sleeve of a TRS connector. If using DC blocking capacitors, ‎connect this pin to AGND.‎
  • HPR - The right headphone out will be connected to the Ring of a TRS connector.‎

headphones_14

LED

The board includes one LED labeled as PWR. This indicates when there is power on the 3.3V net ‎to power the IC's digital circuit. You can disable it with the jumper on the back of the board.‎

led_15

Jumpers

Note: If this is your first time working with jumpers, check out the How to Work with Jumper Pads ‎and PCB Traces tutorial for more information.‎

The following ten jumpers are included on the Audio Codec Breakout - WM8960.‎

  • VIN, SPKVDD, and 3V3 - This 3-pad jumper allows users to select a voltage source for the ‎speaker VDD (SPKVDD). By default, the center pad (SPKVDD) is closed on the VIN pad. Cut ‎this trace and add a solder blob on the 3V3 side to provide SPKVDD with 3.3V. Leave both ‎jumpers open to provide an external voltage for SPKVDD from the header pin.
  • AVDD-ISO - By default, this jumper is closed. Cut this jumper to isolate AVDD from the voltage ‎regulator to provide a VDD from the header pin.‎
  • LED - By default, this jumper is closed and located on the bottom of the board. Cut this trace ‎to disable the LED that is connected to the output of the 3.3V voltage regulator.‎
  • I2C - By default, this 3-pad jumper is closed and located on the bottom of the board. The ‎‎2.2kΩ pull-up resistors are attached to the primary I2C bus; if multiple devices are connected ‎to the bus with the pull-up resistors enabled, the parallel equivalent resistance will create too ‎strong of a pull-up for the bus to operate correctly. As a general rule of thumb, disable all but ‎one pair of pull-up resistors if multiple devices are connected to the bus.‎

jumpers_16

Warning! If you decide to cut the trace between VDD and SPKVDD to connect SPKVDD to 3V3, ‎make sure to avoid any shorts between VDD and SPKVDD. If you place an input voltage on VIN that ‎is higher than 3V3 pin is rated for will damage the WM8960 and anything connected to 3V3. ‎

For users providing their own power supply for SPKVDD and AVDD, make sure to keep the ‎jumpers open.‎

Board Dimensions

The board dimensions of the Audio Codec Breakout - WM8960 is 1.60" x 1.00".‎

dimensions_17

Hardware Hookup

There are a number of ways to connect to the input and output pins of the WM8960. We will go ‎over each .‎

Soldering

Header pins were left off the Audio Codec Breakout to allow users the flexibility of connecting any ‎type of 0.1"-spaced header to the board. Depending on your connections, you may need to solder ‎additional breakout boards and adapters. For temporary connections to the I/O pins, you could use ‎IC hooks to test out the pins. However, you'll need to solder headers or wires of your choice to the ‎board for a secure connection. For the scope of this tutorial, we will be soldering male header pins ‎on the board and wiring the circuit on a breadboard. Here are a few tutorials to connect to the pads ‎depending on your personal preference.‎

solder_18

How to Solder: Through-Hole Soldering

This tutorial covers everything you need to know about through-hole soldering.‎

wire_19

Working with Wire

How to strip, crimp, and work with wire.‎

Power

To power the WM8960 appropriately, you will just need to provide power to VIN and the 3V3 pins. ‎As stated in the Hardware Overview: Power, you can take advantage of your development board's ‎voltages without adjusting jumpers. We recommend making the following connection listed in the ‎table.

table_20

Using wires and the Qwiic cable to power VIN and 3V3, your circuit should look similar to the circuit ‎diagram below. We will use this method to power the audio codec for the proceeding circuit ‎diagrams.‎

cablediagram_21

Danger: Note that we are connecting 5V to the audio codec's VIN pin. Depending on the ‎development board that you are using VIN from your Arduino may be too high of a voltage for the ‎Audio Codec's VIN pin. Exceeding the voltage beyond the absolute maximum rating can damage the ‎components on the audio codec breakout.‎

Depending on your setup, you could provide a separate input voltage to the SPKVDD and VDD. ‎Just make sure to adjust the jumpers on the back, as necessary.‎

Warning! If you decide to cut the trace between VDD and SPKVDD to connect SPKVDD to 3V3, ‎make sure to avoid any shorts between VDD and SPKVDD. If you place an input voltage on VIN that ‎is higher than 3V3 pin is rated for will damage the WM8960 and anything connected to 3V3. ‎

For users providing their own power supply for SPKVDD and AVDD, make sure to keep the ‎jumpers open.‎

Qwiic and I2C

To configure the I2S settings or signal path, you will need to connect to the I2C port. Users can save ‎some time wiring this part of the circuit up by adding a Qwiic cable between the audio codec ‎breakout and the IoT RedBoard ESP32. As an alternative, users could also solder to the PTH as ‎well. We recommend making the following connection listed in the table.‎

table_22

Surprise! Your connection is basically the same as the circuit diagram in the previous section. We ‎just highlighted the circuit connection for I2C data and clock lines here.‎

connections_23

Line Input 3‎

The following connection is for a line level input 3. For simplicity, the table does not include the ‎power and I2C pins.‎

table_24

Your circuit should look similar to the circuit diagram below.‎

circuitdiagram_25

Line Input 2‎

The following connection is for a line level input 2. For simplicity, the table does not include the ‎power and I2C pins.‎

table_26

Your circuit should look similar to the circuit diagram below.‎

circuitdiagram_27

Line Input 1‎

The following connection is for a line level input 1. For simplicity, the table does not include the ‎power and I2C pins.‎

table_28

Your circuit should look similar to the circuit diagram below.‎

inputdiagram_29

I2S Passthrough

The following connection is for passing an audio source through the ADC and immediately back to ‎the DAC. For simplicity, the table does not include the power and I2C pins. Note that this is for ‎setting the codec as a I2S peripheral.‎

table_30

Your circuit should look similar to the circuit diagram below.‎

circuit_31

I2S Decoder

The following connection is for decoding audio. One example is if users connect an audio ‎Bluetooth® device (such as your phone or laptop) to the ESP32 and stream music wirelessly. For ‎simplicity, the table does not include the power and I2C pins. Note that this is for setting the codec ‎as a I2S peripheral.‎

table_32

Your circuit should look similar to the circuit diagram below.‎

circuit_33

Differential Microphone Input

The following connection is for connecting differential microphones to the audio codec. When ‎using a pseudo-differential microphone configuration, make sure to include a 2.2kΩ resistor ‎between the MICBIAS and the + terminals of each differential microphone. You will also need to set ‎voltage on the MICBIAS pin. For simplicity, the table does not include the power and I2C pins.‎

table_34

Your circuit should look similar to the circuit diagram below.‎

circuitmicrophone_35

Single Ended Microphone Input

The following connection is for connecting single ended microphones to the audio codec. Instead ‎of using a line level input from the TRS connector, users can also connect unbalanced ‎microphones (these are usually microphones with an amplifier on the breakout boards and have ‎one audio output pin) to the left and right pins of INPUT1. Make sure to also connect power and ‎GND to the boards. For simplicity, the table does not include the power and I2C pins between the ‎ESP32 and WM8960.‎

table_36

Your circuit should look similar to the circuit diagram below.‎

single_37

Headphone Output

Based on the recommended output configuration from the datasheet, we will be using a capless ‎headphone output in this tutorial.‎

headphone_38

Recommended headphone output configuration from the WM8960 Datasheet (v4.2) on page 41.‎

The following connection is for connecting headphones to the audio codec's headphone output. ‎For simplicity, the table does not include the power and I2C pins.‎

table_39

config_40

Differential Speaker Output

There are a few recommended speaker output configurations from the datasheet to minimize the ‎speaker connection losses due to series resistance and EMI. For a basic setup, we will be using a ‎short wire connection between the audio codec's breakout board and each differential speaker. For ‎those that require long exposed track and want to go the extra mile, users can build an LC filter ‎circuit, add ferrite beads, or shield the wires using PCB ground plane (or Vdd).‎

speakeroutput_41

Recommended speaker output configuration from the WM8960 Datasheet (v4.2) on page 88.‎

The following connection is for connecting speakers to the audio codec's speaker output channels. ‎For simplicity, the table does not include the power and I2C pins.‎

table_42

connection_43

Software Installation

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. ‎If this is your first-time using Arduino, please review the following tutorials. ‎

Arduino Board Definitions and Driver

We'll assume that you installed the necessary board files and drivers for your development board. ‎In this case, we used the IoT RedBoard - ESP32 which uses the CH340 USB-to-serial converter. If ‎you are using a Processor Board, make sure to check out its hookup guide for your Processor ‎Board.‎

install_44

Installing Board Definitions in the Arduino IDE

How do I install a custom Arduino board/core? It's easy! This tutorial will go over how to install an ‎Arduino board definition using the Arduino Board Manager.

We will also go over manually installing ‎third-party cores, such as the board definitions required for many of the SparkFun development ‎boards.‎

board_45

‎IoT RedBoard ESP32 Development Board Hookup Guide

Delve into the functionality-rich world of the IoT RedBoard ESP32 Development Board!‎

drivers_46

How to Install CH340 Drivers

How to install CH340 drivers (if you need them) on Windows, Mac OS X, and Linux.‎

‎Installing the Arduino Library

The SparkFun Arduino library can be downloaded with the Arduino library manager by searching ‎‎'SparkFun Audio Codec Breakout WM8960' or you can grab the zip here from the GitHub ‎repository to manually install.‎

SPARKFUN WM8960 ARDUINO LIBRARY (ZIP)

Example 1: Volume

In this example, we will pass a line level audio source into the WM8960's line input 3 port. The ‎signal will go through the mixers and gain stages of the audio codec. For this output, we will be ‎sending the audio to the headphones.‎

Hardware Hookup

Connect power, I2C, line input 3 port, and the headphone output as explained earlier. Your circuit ‎should look similar to the circuit diagram below.‎

hookup_47

Connect a USB cable into your IoT RedBoard ESP32 and a TRS cable from your audio source (e.g., ‎MP3 player, smartphone, or computer) into the audio connector. Then connect your headphones to ‎the output. For those that are sensitive to sounds, you may want to hear the example output before ‎inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_01_Volume. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones. After every 5 seconds, the volume will ‎decrease until it is muted.‎

If you waited too long to hit the play button, the audio codec may have already muted the track. Try ‎hitting the reset button on the IoT RedBoard to restart the example since it executes the code once.‎

Example 2: Line Input 2‎

In this example, we will pass a line level audio source into the WM8960's line input 2 port. The ‎signal will go through the mixers and gain stages of the audio codec like the previous example. For ‎the output we will be sending the audio to the headphones as well.‎

Hardware Hookup

Connect power, I2C, line input 2 port, and the headphone output as explained earlier. Your circuit ‎should look similar to the circuit diagram below.‎

hookup_48

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector. Then ‎connect your headphones to the output. For those that are sensitive to sounds, you may want to ‎hear the example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_02_INPUT2. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones. Compared to the first example, this just sets ‎the volume once.‎

Example 3: Line Input 1 [or Single Ended ‎Microphone Input ]‎

Similar to the past two examples, we will pass the line level audio source into the WM8960's line ‎input 1 port. As an alternative, users can also wire up single ended microphones to input 1 instead ‎of using a line level audio source from the TRS connector. The signal will go through the mixers ‎and gain stages of the audio codec. Again, we will be sending the audio to the headphone output.‎

Hardware Hookup 1‎

Connect power, I2C, line input 1, and the headphone output as explained earlier. Your circuit should ‎look similar to the circuit diagram below.‎

connectpower_49

Connect a USB cable into your IoT RedBoard ESP32 and a TRS cable from your audio source (e.g., ‎MP3 player, smartphone, or computer) into the audio connector. Then connect your headphones to ‎the output. For those that are sensitive to sounds, you may want to hear the example output before ‎inserting the headphones into your ears.‎

Hardware Hookup 2‎

Input 1 also has the ability to allow single ended microphones to the left and right inputs. As an ‎alternative, you can also connect single ended electret or MEMS microphones to these pins. ‎Connect power, I2C, single ended microphones, and the headphone output as explained earlier. ‎Your circuit should look similar to the circuit diagram below.‎

input_50

Note: The audio input for each of the MEMS Mic is located on the bottom of the board. The ‎Fritzing part show the top view of the MEMs Mic. Depending on your application, you may want to ‎consider soldering wire, using a right-angle header, or soldering the male header pins from the ‎bottom side.‎

Connect a USB cable into your IoT RedBoard ESP32. Then connect your headphones to the output. ‎For those that are sensitive to sounds, you may want to hear the example output before inserting ‎the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_03_INPUT1. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source if you are using a TRS connector. Make sure that the volume from ‎the audio source is turned up. You should hear some music from the headphones. This is basically ‎the same as the previous two examples but now we are using input 1.‎

Example 4: Speaker‎

In this example, we will pass a line level audio source into the WM8960's line input 1 port. The ‎signal will go through the mixers and gain stages of the audio codec. For the output, we will be ‎sending the audio to a pair of differential speakers.‎

Hardware Hookup

Connect power, I2C, line input 1, and the speakers on the output channels as explained earlier. ‎Your circuit should look similar to the circuit diagram below.‎

speakerhookup_51

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_04_Speaker. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the speakers.‎

Example 5: Loopback

In this example, we will pass a line level audio source into the WM8960's line input 1 port. The ‎signal will go through the mixers and gain stages of the audio codec. What's different in this ‎example is that we will also turn on loopback so that the ADC is fed directly to the DAC. The output ‎of the DAC will then be sent to the headphone output.‎

Hardware Hookup

Connect power, I2C, line input 1, and the headphone output as explained earlier. Your circuit should ‎look similar to the circuit diagram below.‎

loopback_52

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector. Then ‎connect your headphones to the output. For those that are sensitive to sounds, you may want to ‎hear the example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_05_Loopback. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones.‎

Example 6: 3D Enhance

In this example, we will pass a line level audio source into the WM8960's line input 1 port. The ‎audio source will go through the mixers and gain stages into the ADC. With the loopback turned on, ‎the ADC is sent directly to the DAC and output to the headphone output. In the loop() function, ‎turn on and off the 3D enhance feature every 5 seconds.‎

Hardware Hookup

Connect power, I2C, line input 1, and the headphone output as explained earlier. Your circuit should ‎look similar to the circuit diagram below.‎

hardware_53

Connect a USB cable into your IoT RedBoard ESP32 and a TRS cable from your audio source (e.g., ‎MP3 player, smartphone, or computer) into the audio connector. Then connect your headphones to ‎the output. For those that are sensitive to sounds, you may want to hear the example output before ‎inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_06_3D_Enhance. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output when the 3D ‎enhance mode is enabled. Then hit the play button on your audio source. Make sure that the ‎volume from the audio source is turned up. Experience the virtual surround sound!‎

Example 7: Microphone Bias

In this example, we will set the microphone bias voltage and measure the voltage. This is for ‎advanced users looking to add a differential microphone to the microphone input pins.‎

Hardware Hookup

Connect power and I2C. as explained earlier. Then grab a multimeter with alligator clips and M/M ‎jumper wires. Connect the wires to MICBIAS and GND to measure the voltage. Your circuit should ‎look similar to the circuit diagram below.‎

multi_54

If you have not already, insert a USB cable into your IoT RedBoard ESP32.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_07_MicBias. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Measuring the ‎output with a multimeter, the voltage should be similar to the voltages that were set for the MICBIAS ‎pin. After 3 seconds, the pin will be disabled. If you missed the window to measure the MICBIAS ‎voltage, hit the reset button the IoT RedBoard to run the example again.‎

If you are satisfied with your MICBIAS voltage, head over to example 14 to add a resistor in series ‎with each electret microphone.‎

Example 8: I2S Passthrough

In this example, we will pass a line level audio source into the WM8960's line input 1 port. The ‎signal will go through the mixers and gain stages of the codec. The audio will be read from the ADC ‎via I2S and then immediately sent back to the DAC via I2S. The output of the DAC will then be sent ‎to the headphone output.‎

Hardware Hookup

Connect power, I2C, line input 3, and the headphone output as explained earlier. Your circuit should ‎look similar to the circuit diagram below.‎

passthrough_55

Connect a USB cable into your IoT RedBoard ESP32 and a TRS cable from your audio source (e.g., ‎MP3 player, smartphone, or computer) into the audio connector. Then connect your headphones to ‎the output. For those that are sensitive to sounds, you may want to hear the example output before ‎inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_08_I2S_Passthrough. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones.‎

Example 9: I2S Bluetooth

In this example, we will wirelessly connect a Bluetooth audio source and use the IoT RedBoard ‎ESP32 as a Bluetooth audio sink. Once the audio codec is set as an I2S peripheral, the ESP32 will ‎receive audio and play it back via I2S. Once the WM8960 receives the I2S audio, it will be sent to the ‎DAC and then the headphone output.‎

Hardware Hookup

Note: For users using the SparkFun Qwiic Wireless Speaker Kit, the kit includes a TRRS breakout ‎with headers instead of the TRS breakout. RING2 of the TRRS connector also connects to the TRS ‎cable's sleeve. When wiring your circuit up for this example, we recommend connecting to the ‎sleeve in case you have a headphone with a TRRS connector.

Connect power, I2C, I2S, and the headphone output as explained earlier. Your circuit should look ‎similar to the circuit diagram below.‎

connectboard_56

Connect a USB cable into your IoT RedBoard ESP32. Turn on the Bluetooth on your audio source ‎‎(e.g., MP3 player, smartphone, or computer). Then connect your headphones to the output. For ‎those that are sensitive to sounds, you may want to hear the example output before inserting the ‎headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_09_I2S_Bluetooth. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 1152000 baud to view the serial output. On your ‎phone, pair and connect to the ESP32's Bluetooth. In this case, the name of the ESP32's Bluetooth ‎is called "myCodec". Then hit the play button on your audio source. Make sure that the volume ‎from the audio source is turned up. You should hear some music from the headphones.‎

Try adding a battery to the mix to untether the circuit from your computer. Do a little dance or flip ‎and rock to the beat of the music! Of course, you'll want to be careful of the wires while moving ‎around. For a more secure connection, you could take a solderable breadboard or an Arduino ‎shield and manually wire the circuit together.‎

Example 10: ADC Gain

This example is pretty much example 5. The difference is that we are adding a trim pot to the ‎ESP32's analog input and using the measurement to adjust the codec's ADC digital volume.‎

Hardware Hookup.‎

Connect power, I2C, line input 1, trim pot, and the headphone output. Your circuit should look ‎similar to the circuit diagram below.‎

gain_57

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector. Then ‎connect your headphones to the output. For those that are sensitive to sounds, you may want to ‎hear the example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_10_AdcGain. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones. Adjust the volume to your desired setting by ‎rotating the trim pot clockwise or counterclockwise.‎

Example 11: Volume Plotter

This example is similar to example 3. However, we will be connecting to reading I2S audio from the ‎ADC and plotting the audio samples on the Arduino Serial Plotter.‎

Hardware Hookup

Connect power, I2C, I2S, line input 1, and the headphone output. Your circuit should look similar to ‎the circuit diagram below.‎

volume_58

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector. Then ‎connect your headphones to the output. For those that are sensitive to sounds, you may want to ‎hear the example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_11_VolumePlotter. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Plotter and set it to 115200 baud to view the output. Then hit the play ‎button on your audio source. Make sure that the volume from the audio source is turned up. You ‎should hear some music from the headphones and view the audio samples on the Serial Plotter.‎

Example 12: Automatic Level Control

This example builds off of example 5. The difference is that we are adding a trim pot toe the ‎ESP32's analog input and using the measurement to configures the Automatic Level Control (ALC) ‎target value. The ALC will adjust the gain of the PGA input buffer to try and keep the signal level at ‎the target.‎

Hardware Hookup

Connect power, I2C, line input 1, trim pot, and the headphone output as explained earlier. Your ‎circuit should look similar to the circuit diagram below.‎

auto_59

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector. Then ‎connect your headphones to the output. For those that are sensitive to sounds, you may want to ‎hear the example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_12_AutomaticLevelControl. If you have not already, select your Board (in ‎this case the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload ‎button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones.‎

Example 13: DAC Gain

This example is similar to example 10. The difference is that we are adding a trim pot to the ‎ESP32's analog input and using the measurement to adjust the codec's DAC digital volume.‎

Hardware Hookup

Connect power, I2C, I2S, line input 1, trim pot, and the headphone output. Your circuit should look ‎similar to the circuit diagram below.‎

dacgain_60

If you have not already, insert a USB cable into your IoT RedBoard ESP32 and a TRS cable from ‎your audio source (e.g., MP3 player, smartphone, or computer) into the audio connector. Then ‎connect your headphones to the output. For those that are sensitive to sounds, you may want to ‎hear the example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_13_DacGain. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Then hit the ‎play button on your audio source. Make sure that the volume from the audio source is turned up. ‎You should hear some music from the headphones. Adjust the volume to your desired setting by ‎rotating the trim pot clockwise or counterclockwise.‎

Example 14: Electret Mic

Continuing on from example 7, we will use differential microphones as the audio input based on the ‎‎"pseudo-differential MIC configuration." The example will configure the PGA before passing it to ‎the mixers and gain stages of the codec like the previous examples. The output will be to the ‎headphones.‎

Hardware Hookup

Connect power, I2C, I2S, differential microphones (each with a 2.2kΩ resistor wired in series with ‎the MICBIAS pin), and the headphone output. Your circuit should look similar to the circuit diagram ‎below.‎

mic_61

If you have not already, insert a USB cable into your IoT RedBoard ESP32. Then connect your ‎headphones to the output. For those that are sensitive to sounds, you may want to hear the ‎example output before inserting the headphones into your ears.‎

Upload Code

From the menu, select the following: File > Examples > SparkFun WM8960 Arduino ‎Library > Example_14_Electret_Mics. If you have not already, select your Board (in this case ‎the SparkFun ESP32 IoT RedBoard), and associated COM port. Then hit the upload button.‎

Open the Arduino Serial Monitor and set it to 115200 baud to view the serial output. Make some ‎noise on the differential microphones. You should hear some audio from the headphones.‎

Troubleshooting

Not working as expected and need help? ‎

If you need technical assistance and more information on a product that is not working as you ‎expected, we recommend heading on over to the SparkFun Technical Assistance page for some ‎initial troubleshooting.

SPARKFUN TECHNICAL ASSISTANCE PAGE‎ ‎

If you don't find what you need there, the SparkFun Forums are a great place to find and ask for ‎help. If this is your first visit, you'll need to create a Forum Account to search product forums and ‎post questions.

SPARKFUN FORUMS

Resources and Going Further

Now that you've successfully got your Audio Codec Breakout up and running, it's time to ‎incorporate it into your own project! For more information, check out the resources below:‎

制造商零件编号 BOB-21250
SPARKFUN AUDIO CODEC BREAKOUT -
SparkFun Electronics
制造商零件编号 BOB-21772
SPARKFUN AUDIO CODEC BREAKOUT -
SparkFun Electronics
制造商零件编号 COM-09806
TRIMMER 10K OHM 0.5W PC PIN TOP
SparkFun Electronics
制造商零件编号 PRT-08431
JUMPER WIRE M/M 6" 10PCS
SparkFun Electronics
制造商零件编号 PRT-00116
BREAK AWAY HEAD
SparkFun Electronics
制造商零件编号 PRT-17258
FLEXIBLE QWIIC CABLE - 200MM
SparkFun Electronics
AUDIO CABLE TRS - 1M
制造商零件编号 CAB-18983
AUDIO CABLE TRS - 1M
SparkFun Electronics
AUDIO JACK 3.5MM
制造商零件编号 PRT-08032
AUDIO JACK 3.5MM
SparkFun Electronics
制造商零件编号 PRT-12002
BREADBOARD - SELF-ADHESIVE (WHIT
SparkFun Electronics
制造商零件编号 CAB-15426
CBL USB2.0 A PLUG TO C PLG 0.98'
SparkFun Electronics
制造商零件编号 WRL-19177
SPARKFUN IOT REDBOARD - ESP32 DE
SparkFun Electronics
制造商零件编号 KIT-21773
SPARKFUN QWIIC WIRELESS SPEAKER
SparkFun Electronics
制造商零件编号 WRL-15663
SPARKFUN THING PLUS ESP32 WROOM
SparkFun Electronics
制造商零件编号 WRL-20168
THING PLUS ESP32 WROOM USB-C
SparkFun Electronics
制造商零件编号 BOB-19389
SPH8878LR5H-1 MEMS MICROPHONE
SparkFun Electronics
制造商零件编号 BOB-12758
EVAL BOARD FOR OPA344
SparkFun Electronics
制造商零件编号 BOB-18011
ICS-40180 MEMS MICROPHONE
SparkFun Electronics
制造商零件编号 PRT-20660
SPEAKER 8OHM TOP PORT T/H
SparkFun Electronics
制造商零件编号 COM-19102
SPEAKER 4OHM 10W TOP PORT 85DB
SparkFun Electronics
制造商零件编号 COM-18379
SPEAKER 8OHM 15W TOP PORT 83DB
SparkFun Electronics
制造商零件编号 COM-14023
SPEAKER 4OHM 3W TOP PORT
SparkFun Electronics
制造商零件编号 DEV-20690
SPARKFUN QWIIC SPEAKER AMP
SparkFun Electronics
制造商零件编号 BOB-11570
SPARKFUN TRRS 3.5MM JACK BREAKOU
SparkFun Electronics
制造商零件编号 TOL-14456
SOLDERING IRON - 60W (ADJUSTABLE
SparkFun Electronics
SOLDER LEAD FREE - 15-GRAM TUBE
制造商零件编号 TOL-09163
SOLDER LEAD FREE - 15-GRAM TUBE
SparkFun Electronics
制造商零件编号 CAB-09741
TEST LEAD HOOK TO TIP PLUG 2.5"
SparkFun Electronics
制造商零件编号 PRT-14311
ESP32 STACKABLE HEADER SET
SparkFun Electronics
制造商零件编号 COM-10969
RESISTOR KIT - 1/4W (500 TOTAL)
SparkFun Electronics
制造商零件编号 PRT-14460
MULTICOLOR BUTTONS - 4-PACK
SparkFun Electronics
制造商零件编号 KIT-15081
QWIIC CABLE KIT
SparkFun Electronics
制造商零件编号 PRT-14427
QWIIC CABLE - 100MM
SparkFun Electronics
制造商零件编号 PRT-14429
QWIIC CABLE - 500MM
SparkFun Electronics
制造商零件编号 PRT-14425
QWIIC CABLE - BREADBOARD JUMPER
SparkFun Electronics
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum