Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Connecting an Analog Microphone to WM8960 breakout board #1065

Answered by pschatzmann
syedadil19 asked this question in Q&A
Discussion options

Hi Phil,
This is my code to capture the analog microphone signal, digitze it using WM8960 ADC and send the digitized data to ESP32 via I2S.
/**

#include "AudioTools.h"
#include "AudioLibs/WM8960Stream.h"

AudioInfo info(44100, 1, 16);
WM8960Stream in;
CsvOutput<int16_t> csvStream(Serial);
StreamCopy copier(csvStream, in); // copies mic into Serial

// Arduino Setup
void setup(void) {
// Open Serial
Serial.begin(115200);
while(!Serial);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);

// setup wire on pins 19 and 21
Wire.begin(19, 21);
Wire.setClock(10000);

// start I2S
Serial.println("starting I2S...");
auto config = in.defaultConfig(RX_MODE);
config.copyFrom(info);
config.wire = &Wire;
// use default i2s pins
// config.pin_bck = 14;
// config.pin_ws = 15;
// config.pin_data_rx = 32;
// Configure the WM8960 Audio Codec
// config.sample_rate = 44100; // Set sample rate to 44.1 kHz
// config.channels = 1; // Set to 1 channel for mono audio
// config.bits_per_sample = 16; // Set to 16-bit samples
//config.i2s_format = I2S_STD_FORMAT;
config.is_master = false; // Let WM8960 be the I2S master
//config.use_apll = false; // try with yes
config.default_volume = 0.6; // Set default volume (range 0.0 to 1.0)
config.features = WM8960_FEATURE_MICROPHONE1; // Enable microphone feature
in.begin(config);
// Initialize the WM8960 Audio Codec
if (!in.begin(config)) {
Serial.println("Failed to initialize WM8960 Audio Codec!");
while (1) delay(1000);
}

Serial.println("WM8960 Audio Codec Initialized Successfully");
}

void loop() {
copier.copy();
}

My connection are as the following,
WM8960 ESP32
QWIIC red ------------ 3V3
QWIIC black --------- GND
QWIIC blue --------- GPIO19
QWIIC yellow ------- GPIO21
BCLk ---------------- GPIO14
ALRC --------------- GPIO15
ADAT --------------- GPIO32

While the MAX9814 microphone out is connected to LIN1.

My code compiled and uploaded successfully:
starting I2S...
mtb_wm8960_set_wire
[W] WM8960Stream.h : 195 - Setup features: 1
mtb_wm8960_init
mtb_wm8960_write 0xf = 0x0
mtb_wm8960_write 0x19 = 0xfe
mtb_wm8960_write 0x2f = 0x30
mtb_wm8960_adjust_input_volume
_mtb_wm8960_adjust_volume
mtb_wm8960_write 0x0 = 0x92
mtb_wm8960_write 0x1 = 0x192
mtb_wm8960_adjust_heaphone_output_volume
_mtb_wm8960_adjust_volume
mtb_wm8960_write 0x28 = 0x58
mtb_wm8960_write 0x29 = 0x158
mtb_wm8960_adjust_heaphone_output_volume
_mtb_wm8960_adjust_volume
mtb_wm8960_write 0x2 = 0x58
mtb_wm8960_write 0x3 = 0x158
mtb_wm8960_activate
mtb_wm8960_write 0x19 = 0xfe
mtb_wm8960_write 0x1a = 0x0
mtb_wm8960_write 0x2f = 0x30
mtb_wm8960_configure_clocking
_mtb_wm8960_setup_pll
mtb_wm8960_write 0x34 = 0x38
mtb_wm8960_write 0x35 = 0x0
mtb_wm8960_write 0x36 = 0x0
mtb_wm8960_write 0x37 = 0x0
mtb_wm8960_write 0x1a = 0x1
mtb_wm8960_write 0x4 = 0x5
mtb_wm8960_write 0x7 = 0x42
WM8960 Audio Codec Initialized Successfully

The issue is that, it does not print anything apart from the initialization of the WM8960.

I can't seem to attach the oscilloscope output here

This is the output from Serial Plotter:
2

What happened next was that this is the Serial Plotter when I disconnected the ALRC jumper from my ESP32:
3

And, it looks the output remains the same even when the microphone is not connected at all to any of the IN pins. Do you have any idea how this could've happened and is there a solution to it?

You must be logged in to vote

What did you try ?
There are plenty of examples in the examples-audiokit directory

Replies: 4 comments · 3 replies

Comment options

Not sure what the issues is. I did not find any read sketch for the WM8960, so I am not even sure if I have tested this.
I would play with the is_master setting and check the I2S signals in the oscilloscope.

You must be logged in to vote
3 replies
@syedadil19
Comment options

But your WM8960Stream.h with mtb_wm8960.h and mtb_wm8960.cpp do provide support to configure the microphone setup for LIN1, LIN2, LIN3, RIN1, RIN2 or RIN3 right?

This is my oscilloscope output:
tek00000

@pschatzmann
Comment options

Is this the bitclock and the data in ?
For the functionality I suggest you have a look at the documentation:
https://pschatzmann.github.io/arduino-wm8960/docs/html/group__wm8960.html#gae06d07ab61d7585d7708902f7d7b1386

@syedadil19
Comment options

That's only the ADAT/data in waveform. When I changed the config.is_master to true, I got this,
tek00001

I'll take a look at the link you sent.

Comment options

I would add the ws signal as well so that you can see the signal start point. If you record a sine wave should see that the data signal is getting longer and shorter.

Your second picture is confusing me: I an not sure how to read the light blue or dark blue sections.

You must be logged in to vote
0 replies
Comment options

Analog microphone signal, digitze it using WM8960 ADC and send the digitized data to ESP32 via I2S.

I haven't been able to get it working either, and there isn't a direct example in the codebase. Could you please provide a test example? Thank you.

@pschatzmann

You must be logged in to vote
0 replies
Comment options

What did you try ?
There are plenty of examples in the examples-audiokit directory

You must be logged in to vote
0 replies
Answer selected by pschatzmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.