Harmony SD card Audio Player/Reader Tutorial


MPLAB® Harmony provides the capability to quickly develop complex embedded systems that utilize multiple middleware stacks running at the same time in a Real-Time Operating System (RTOS) or non RTOS system.

The rapid prototyping ability of MPLAB Harmony is due to the availability of software modules: Drivers, System Services and Middleware Libraries; and tools: MPLAB® Harmony Configurator (MHC) and MPLAB® Harmony Graphics Composer (MHGC); that are designed to allow maximum reuse of code and rapid development.

The following exercises demonstrate the quick prototyping capability of MPLAB Harmony. These exercises should be completed in a sequential manner so as to understand how a following exercise enhances and adds on new functionality to the earlier exercise.

Two ways to use this tutorial:

  1. Create the projects from scratch
    • Use the provided source files and step-by-step instructions for each lab.
  2. Use the solution project as an example
    • Just build the solution project (found in the lab's firmware folder) and download it to the MEB II board to observe the expected behavior.


  • Create an MPLAB® X IDE Harmony project for a PIC32 microcontroller from scratch.
  • Use (MHC) to configure and generate Harmony code.
  • Create new application states and variables for Harmony projects.
  • Identify the proper place to add your own application code to the Harmony project.
  • Demonstrate the use of Harmony peripheral libraries and drivers to control PIC32 peripherals (SPI, I2C, Timers, etc.).
  • Demonstrate the use of Harmony middleware libraries (USB, FS, and Graphics, etc.).


Hardware Tools

Tool About Purchase
In-Circuit Emulator
PIC32MZ Embedded Connectivity with FPU
Starter Kit
PIC32 Multimedia Expansion Board II
For PIC32 Starter Kits

It is not necessary to have an MPLAB Real ICE to program/debug the code. The PIC32MZ EF Starter Kit includes a PICkit on-board (PKOB) debugger. The PKOB debugger can be connected to a host PC through the USB Mini-B connector on the PIC32MZ EF Starter Kit for programming/debugging (see red cable in the hardware setup)

Apart from the hardware tools listed above, the following items are required to play audio from an SD card and to load audio files into the SD card over a USB interface from the PC:

  • Wired Stereo headphone.
  • Micro SD card containing audio files in waveform audio format (WAV).
  • USB Type A male to micro-B male cable for SD card reader functionality.
  • USB Type A male to mini-B male cable for programming/debugging with PKOB

Development Board User's Guides


Software Tools

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v3.26, MPLAB XC32 Compiler v1.40, MPLAB Harmony v1.08

Because we regularly update our tools, occasionally you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double check using the same versions that the project was tested with.

Archived versions of our tools can be found on the following Microchip websites:
MPLAB Harmony (see "Archived Downloads" tab)
MPLAB X IDE and XC32 Compiler (see "Downloads Archive" tab)
Note that multiple versions of all these tools can co-exist on the same computer.

Tool About Installers
Windows Linux Mac OSX
Integrated Development Environment
C/C++ Compiler
MPLAB® Harmony
Integrated Software Framework

Harmony SD card Audio Player/Reader Labs

The associated ZIP file contains the completed solution of these five labs. The completed solution is not needed to develop the labs from scratch; it can be used as an example and requires no modifications. To gain a deeper understanding of how to use the MPLAB Harmony framework for Quick Audio Prototyping, and creating an SD card Audio Player/Reader, we recommend you follow the step-by-step procedures detailed in the "Procedure" section below.

  • Lab1: Audio tone generation using lookup table
  • Lab2: Audio tone generation using text file stored in SD card
  • Lab3: SD card reader support to load audio files
  • Lab4: Play WAV audio file from SD card
  • Lab5: Display graphics support to select and play audio file

Lab Source Files and Solutions

This ZIP file contains the completed solution projects for all labs associated with this SD card audio player tutorial. It also contains the source files needed to perform the labs per the following step-by-step instructions (see the "Proceedure" section on this page).

The contents of this ZIP file need to be placed in this directory:

<Harmony install path>/apps/training/middleware/
(example Harmony install path = c:/microchip/harmony/v1_08)

If this is not done, the MPLAB® X IDE will not be able to find all source files for the lab solutions (see project in the firmware folder); the solution projects will not build successfully.

Extracting the ZIP file will create the following folders:

  • audio_player contains five lab folders (audio_player_labx, where x = 1 through 5).
  • audio_player_labx contains the lab solutions (in the firmware folders) and source files (in the dev_files folders).
  • dev_files contains application source files and other support files (if any) required to perform each lab (see "Procedure" section below).
  • firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behavior.


The exercise is split into five labs. Each lab progressively moves towards achieving the final goal of creating a complete audio solution using Harmony:

  1. Lab1: Audio tone generation using lookup table
  2. Lab2: Audio tone generation using text file stored in SD card
  3. Lab3: SD card reader support to load audio files
  4. Lab4: Play WAV audio file from SD card
  5. Lab5: Display graphics support to select and play audio file


You will observe the following at the end of each lab:

  • Lab1: You should be able to hear a sine tone output through the headphone jack on the Multimedia Expansion Board II (MEB II).
  • Lab2: As in Lab1, you should be able to hear a sine tone output through the headphone jack on the MEB II.
  • Lab3: You should be able to load audio files to the SD card by connecting the MEB II to a PC over USB interface. The MEB II will act as a USB Mass Storage Device.

For Lab3, you will be able to play audio data saved in a tone.txt file by loading it through the USB interface. For subsequent labs, you will be able to play WAV files by loading them to the SD card using the USB interface.

  • Lab4: You should be able play, and hear audio tracks (WAV files) played on your headphones connected to the MEB II.
  • Lab5: You should see a graphical user interface on the MEB II display, populated with a list of audio tracks (WAV files) read from the SD card, along with volume and mute control. The user interface should respond to touch events and you should be able to select random tracks for playback, adjust volume level and mute/unmute the audio output.

Problems with the results of each of lab could occur if you don't carefully follow the detailed steps provided. Also note that each lab is an extension of the previous lab; successful completion of earlier labs is essential for following labs to work.


In this exercise series we have successfully developed an audio solution right from the basic tone playback to an SD card audio player. We added graphics display support and also added support for an SD card reader. Using the MHC we configured the hardware modules including Clock, CODEC driver, Reference clock for the CODEC, I2S driver, SPI driver, SD card driver, GFX library and USB Library. Each of the lab applications were developed in a state based, loosely coupled implementation. The state based implementation and loose coupling enabled easily enhancing subsequent labs.


By the end of this lab series you will have successfully developed a fairly complex audio solution in a fairly short time. By now you should appreciate the real power of MPLAB Harmony, particularly the power of MHC and the ease with which it allows you to add/remove software modules to an existing developed application. With this lab series completed, you are now in the position of creating complex applications using PIC32 microcontrollers. MPLAB harmony provides all the necessary software tools which enables you to quickly develop your application. If you want to expand on this exercise series try adding more software components such as the TCP/IP stack, or add application support for audio recording.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.