Breaking

Make a USB Microphone Using the Raspberry Pi Pico

This tutorial will show you how to build your own USB microphone device with a Raspberry Pi Pico board and an external digital microphone. This project will make use of the RP2040 microcontroller's Programming I/O (PIO), Direct Memory Access (DMA), and Universal Serial Bus (USB) features (MCU).

Make a USB Microphone Using the Raspberry Pi Pico

This project's materials

USB is a widely used standard for connected computer peripherals such as keyboards, mouse, printers, scanners, and microphones that was first introduced in 1996.

The RP2040 MCU on the Raspberry Pi Pico board offers a "USB 1.1 Host/Device" functionality that lets you to connect to an existing USB peripheral device (host mode) or develop your own USB peripheral (device mode). The TinyUSB library serves as the Raspberry Pi Pico SDK's USB software stack.

The Tiny USB library is "an open source cross-platform USB stack for embedded systems" that supports a variety of MCUs, including the Raspberry Pi RP2040, and features device and host mode support. We can leverage the Pico's built-in USB Audio Class functionality to turn it into a USB microphone device.

Choosing a Microphone

The RP2040 MCU includes a built-in 4-channel Analog-to-digital converter (ADC) with 12-bit accuracy, which may be used to gather audio from an external analogue microphone; however, we found the audio quality from the analogue microphone to be poor, so we will utilise a digital microphone instead.

For digital microphones, there are two typical interfaces:

  • Pulse Density Modulation (PDM)
  • Inter-IC Sound (I2S)

While neither of these interface types is built-in to the RP2040, the very flexible Programmable I/O (PIO) functionality may be leveraged to design our own PDM or I2S peripheral interface in software. I'll use one pin to provide an output clock signal to the microphone and another pin to receive data from the microphone.

What is the process of PDM?

When the PDM microphone gets the clock signal, it emits a 0 or 1 signal depending on the analogue audio value captured by the microphone. To record audio at 16, 000 samples per second (16 kHz), the PDM microphone's clock input must be driven at 1.024 MHz = 64 x 16kHz, and the PDM's microphone data single may then be filtered and downsampled. The 0 or 1 output for 64 values for each sample is averaged to provide a single 16-bit number between -32678 and 32767 for the sample.

What is the process of PDM
Sandeep Mistry (https://www.hackster.io/sandeep-mistry)

To inspect the PDM CLK and DAT signals, use a logic analyzer such as Saleae.

Pipeline for Processing

The system will do the following actions:

1. Insert a 1.024 MHz clock signal into the PDM Microphone using the PIO.

2. Using PIO, capture a digital value from the PDM Microphone once each clock interval.

3. The DMA will be set to collect 1 millisecond of audio at a sample rate of 16 kHz, resulting in 16 samples being created per millisecond. The 16 samples will have a total bit count of 64 x 16 = 1024.

4. Once the raw PDM data for 16 samples is received, it will filter and downsample the 1024 bit raw PDM data into 16 Pulse-code modulation (PCM) 16-bit audio samples using the OpenPDM2PCM library.

5. Connect the 16 PCM audio samples to the PC via USB.

Connect the 16 PCM audio samples to the PC via USB
Sandeep Mistry (https://www.hackster.io/sandeep-mistry)

Hardware Setup

Solder male headers to your Raspberry Pi Pico board and the Adafruit PDM MEMS Microphone Breakout board so that they may be connected to a breadboard. More information on soldering pin headers to the Raspberry Pi Pico board can be found in The MagPi's "How to Solder GPIO Pin Headers to Raspberry Pi Pico" tutorial.

Place both soldered objects on a breadboard and wire them together as follows:

Create a USB Microphone with the Raspberry Pi Pico
Sandeep Mistry (https://www.hackster.io/sandeep-mistry)

+---------+-------------------+
| PDM Mic | Raspberry Pi Pico |
|---------+-------------------|
| 3V | 3V3 |
|---------+-------------------|
| GND | GND |
|---------+-------------------|
| SEL | GND |
|---------+-------------------|
| DAT | GPIO2 |
|---------+-------------------|
| CLK | GPIO3 |
+---------+-------------------+

When the PDM Mic. SEL is connected to GND, it will clock out additional data after the clock signal has fallen (goes from logic level 1 to 0).

Create a USB Microphone with the Raspberry Pi Pico
Sandeep Mistry (https://www.hackster.io/sandeep-mistry)

Configuring the Pico SDK Development Environment

You must first load the Raspberry Pi Pico SDK and any relevant toolchains on your PC.

For further details, see "Getting Started with Raspberry Pi Pico."

Section 2.1 of the handbook is applicable to all operating systems, and it is followed by the operating-specific section:

  • Linux: Section 2.2
  • macOS: Section 9.1
  • Windows: Section 9.2

Obtaining and creating a library of pico-microphones and examples

Ascertain that the PICO SDK environment variable is set.

export PICO_SDK_PATH=/path/to/pico-sdk

Clone the git repository and change folders in a terminal window:

cd ~/ 

git clone https://github.com/sandeepmistry/pico-microphone.git


cd pico-microphone
Make a build directory and add the following folders to it:
mkdir build

cd build
To compile, use cmake and make:
cmake .. -DPICO_BOARD=pico

make
Hold down the BOOTSEL button on the board while connecting it to your computer via a USB wire.

Copy the examples/usb microphone/usb microphone.uf2 file to the Raspberry Pi Pico boot ROM disc that has been mounted.
cp -a examples/usb_microphone/usb_microphone.uf2 /Volumes/RPI-RP2/.
Your system should now have a new microphone device named "MicNode" attached to it:

Audio Data Capture

Now that we've setup the Raspberry Pi Pico board as a USB microphone, we can use any desktop recording tool, such as Audacity, to capture data from the device over USB.

Audacity to be downloaded and installed on your PC.

Once installed, launch the programme and pick the "MicNode" device as the input device.

Download and install Audacity
Sandeep Mistry (https://www.hackster.io/sandeep-mistry)

To begin recording audio for the Raspberry Pi Pico, click ⏺ the Record button. To stop recording audio, use the Stop button.

Using a Raspberry Pi Pico board and an external PDM microphone, we built our own USB microphone. The PIO, DMA, and USB hardware capabilities of the Raspberry Pi RP2040, as well as the OpenPDM2PCM and TinyUSB software libraries on one of the RP2040's Arm Cortex-M0+ processors, were all utilised in this project.

In real-time, our USB microphone gathers PDM audio data from the PDM microphone, transforms the PDM data to PCM format, and then transfers the PCM data to the PC over USB! Because the Raspberry Pi Pico board communicates with the PC through the USB Audio standard, no new software is required on the PC side.

In real-time, our USB microphone gathers PDM audio data from the PDM microphone, transforms the PDM data to PCM format, and then transfers the PCM data to the PC over USB! Because the Raspberry Pi Pico board communicates with the PC through the USB Audio standard, no new software is required on the PC side.

Author Credit: Sandeep Mistry 


The lifeblood of the Raspberry Pi and maker communities is the first and third component accessories. They provide new features and make it easier to complete projects.

SB Components, a UK-based official Raspberry Pi Reseller, was the first to market. They have launched 17 new Pico accessories, ranging from basic breakout boards that allow several addons to be utilised for DIY projects to exploring the potential of the Raspberry Pi Pico, and a Pico LoRa™ Expansion board, which comes with an onboard CH340 USB TO UART converter, Voltage Level Translator(74HC125V), E22-900T22S SMA antenna connector that covers 868MHz & 433MHz frequency band. We have shared the products below:

  1. Pico LoRa Expansion 868MHz : Pico LoRa™ Expansion is a low-power consumption data transmission board that includes an onboard CH340 USB TO UART converter, a Voltage Level Translator (74HC125V), an E22-900T22S SMA antenna connector that covers the 868MHz frequency band, an onboard 1.14" LCD, an IPEX antenna connector, and LoRa™ Spread Spectrum Modulation technology with auto multi-level repeating. Pico LoRa™ Expansion is developed to enable data transmission up to 5 KM through serial port. Pico LoRa™ Expansion was created to allow data transfer up to 5 kilometres through serial interface. 433MHz LoRa Expansion for Pico also Available. 
  2. 1.28” Round LCD HAT for Pico : 1.28-inch display HAT with 240 x 240 resolution, 65K RGB colours, crisp and colourful display effect, and joystick, developed for the Raspberry Pi Pico to broaden its engagement through SPI connection by offering a standard 40 pin Pico GPIO interface.
  3. 1.14” LCD HAT For Pico : 1.14-inch display expansion board module with a joystick and a resolution of 240135, 65K RGB colours, clean and colourful presenting effect, created specifically for Raspberry Pi Pico to increase its involvement through SPI connection by offering a standard 40 pin GPIO interface. 
  4. Pico Motor Driver HAT : DC motor control module supplied by one H-bridge IC L293D with a motor input supply voltage range of 6 V to 12 V. It is intended to link two DC motors at the same time or one stepper motor, allowing the user to create projects with a small footprint and great efficiency. 
  5. Pico RTC (Real Time Clock) HAT : Real-Time clock extension module with the powerful IC DS3231, backup battery holder, 3.3 V working voltage, and Fast (400kHz) I2C Interface that detects time and aligns the device's time with the "Real-Time". 
  6. Pico RFID Expansion : RFID Reader with a 125KHz frequency and a small design that includes a programmable 0.91” Oled screen and an improved UART/I2C interface that is compatible with the Raspberry Pi Pico Board
  7. Pico Dual Channel Relay HAT : Relay HAT is a two-channel high-quality relay with loads up to 250V AC/ 7 A, 30V DC/ 10A to control high voltage/current devices. 
  8. Pico Single Channel Relay HAT : It can handle loads of up to 250V AC/ 7A and 30V DC/ 10A, allowing you to manage high voltage/current devices. It has a Female Pin Header for easy connection to the Raspberry Pi Pico through stacking. 
  9. Pico 3V Relay HAT : High-quality two-channel relay with a switching voltage (VAC) of up to 2A/120V (Max), a switching voltage (VDC) of up to 2A/24V (Max), and an operating voltage of 3.3V. 
  10. Pico 2 Channel Expander : Pico 2 CH Expander is intended specifically for use as a GPIO extender, having 2 sets of 2 x 20 pin headers for connecting to HATs or Breadboards.
  11. Pico 4 Channel Expander : Pico 4 Channel Expander is intended to function as a GPIO extender by offering 4 sets of two 20-pin headers for use with HATs or breadboards. 
  12. Pico HAT Expansion : HAT Expansion is a Raspberry Pi Pico input/output expansion board that includes one set of 2x20 pin headers in the form of a Raspberry Pi Header and one set of 2 x 20 pin. This implies that any HAT developed for the Raspberry Pi Board can be plugged in. 
  13. Pico GPIO Expansion Board : Pico GPIO Expansion Board with 3.3 V output voltage. Pico GPIO Expansion Board is designed to split off all of the Raspberry Pi Pico development board's pins and power in two ways (male or female header). It enables the user to connect it to other components via a jumper wire. 
  14. Pico Breadboard Kit : A multi-purpose Kit with a "400 points half-size breadboard" on top, a Programmable Buzzer, 4 Programmable LEDs, 4 Push buttons, and dedicated 5V, 3v3, and GND pins all in one spot. It contains sophisticated features like as individually controlled LEDs, switches, and a 400-point half-size breadboard that allows users to efficiently prototype their ideas using the Raspberry Pi Pico. 
  15. Pico Relay Board : Up to four appliances and loads of up to 250V AC at 7A and 30V DC at 10A can be controlled. It allows users to control high-voltage/high-current devices. It has a “Optocoupler,” which enables the circuit to convey an electrical signal between two separated circuits using light energy.
  16. Pico Zero Board : Pico Zero Board is a useful and well-labelled board with a 6x20 grid of 2.54mm spacing mounting holes that allows users to quickly solder the Pico pins. With properly connecting bespoke circuits, the Pico Zero Board provides a secure, compact, and long-term safe housing for your breadboard project!
  17. Pico Zero Expansion : cleanly labelled expansion, with a 6x20 grid in the centre for the Raspberry Pi Pico and an 8x20 grid on both sides to connect peripherals, 2.54mm spacing mounting holes suited for users to simply solder the Pico pins

Recommended Article:

Popular Posts