Photon2- Can't compile an example program for PDM microphone

I cannot make any progress trying to compile the Microphone_PDM using SDFat example
This is part of the file that Rickas7 gave a link for in the post
"PDM digital microphone support for P2/Photon2" .
Specifically, I am looking in the more-examples folder at 1-sdfat.
What I hoped this would do is save the PDM microphone data to an SDCARD I have connected up.
Using the Web-IDE, I cut/paste the sdfat.cpp code into a new program.
Then I add the 3 libraries called for at the head of this program, using the Library "Include in Program" button.
This procedure duplicates the 3 existing #include ... statments, so I remove them. When I compile it, I get tons of errors like
/firmware/user/../wiring/inc/spark_wiring_logging.h:730:0: multiple definition of "WavHeaderBase::~WavHeaderBase()"
lib/Microphone_PDM/WavWriter.cpp:90:0: multiple definition of "WavHeaderBase::getDataOffset() const"
Given this problem, I remembered that it might be better to just look at the
examples provided for the Microphone_PDM library, and invoke the
"Use this example as a program" option. However, none of the "extra-examples" are included, so that doesn't work.
Anyone else run into this/solved this? Thanks

It's not currently possible without modifying the code. The problem is that the current version of Microphone_PDM has the WavWriterBase class defined, but that same class also exists in the SdFatWav library. One of them needs to have the class renamed.

If you upgrade to version 0.0.3 of Microphone_PDM you can now compile the SdFat example.

Hi Rick: Sorry- I see you answered my question 2 weeks ago. I was working on something else and was waiting for an email notification- (which is how I remembered it in the past). I never got one- the thread shows me watching for notification though.
In any case it compiles now. But, if you look up the microphone_PDM lib (v0.0.3) and then pick the SDFAT example, and "use this as a project", the code window comes up with the same example that you show. This includes lines for the other two SDFat related dependencies shown as #includes. But, they are not really included, as the compiler throws errors on the first SDFat #include line. I have to include them myself, manually. I expect that if I write my own program, I can't just add the #include file directives- I have to use the library tab and do the importation manually. But, I expected the Particle examples would take care of this automatically. In any other toolchain that I use, merely adding the #include is all that is required- assuming the library is present in the proper path in first place.Of course, I'm not using an online toolchain in the other cases, either.
I will actually check out the program operation as soon as I get a chance.Thanks :smiley:

You need to manually add the three libraries as shown. The reason is that that you can't have a library example with additional dependencies only for that example. That's why the SdFat example is in more-examples instead of the regular examples directory.

Thanks Rick: I had some trouble getting the program to actually work. This example uses a different CS line pin (A2) rather than the defined SPI0 CS line (S3), which I had been using to test the SD card operation.It took me a while to notice the difference.
However, even when I got everything working, the audio recorded in the WAV file is terrible. Poor audio quality and a lot of clicking. Certainly not good enough to use these files for Edge Impulse learning. I had already tried an Edge Impulse voice recognition example for the Photon2, using voice learning samples recorded on my phone- and it didn't work at all on the Photon2. When I let Edge Impulse generate the image for the same app on an ESP32, and used those same samples, it worked but not very well. That is why I wanted to generate voice samples using the same microphone for both training and operation.
I tried to attach the lousy WAV file I captured but it seems it will only accept picture files. I am using the same Adafruit PDM mike module specified in the Github posting.

We didn't use the PDM microphone for training. The main thing with the PDM microphone is to be sure you're not picking up RF interference. I saw that when I used Dupont wires in a breadboard that passed directly over the Wi-Fi antenna but was able to get the signal clean enough for classification.

Are you saying that the Edge Impulse voice recognition application for Photon2, that you/someone tested, was done using voice samples from a phone, for example, but that the program running on the Photon2 was using the PDM microphone as described in the Github post?
I used the 6" long STEMMA cable from Adafruit that just plugs into the Adafruit mike module itself. I will shorten and shield that and try again. But, the Photon2 wouldn't be transmitting while recording, I wouldn't think.

Correct. We used the mobile app for the training samples.

I can't guarantee that it was the Wi-Fi module, but I did get poor microphone performance initially, but changed things around a bit, and the microphone worked significantly better but I didn't put it back the way it was to determine for sure that was the problem.

OK. I am putting some high-quality RG-174 cable shielding around DAT, CLK wires now.

It could also be power related. Since the connection is digital, it shouldn't be affected by the RF noise, but I'm guessing the wires are acting like an antenna and it's affecting the PDM mic in some other way.

We'll see. I also have to move the 4-pin socket on the board over next to the A0, A1 pins on the Photon2. I'll put a bypass cap across the GND/3.3V lines too.

1 Like

Well, that made absolutely no difference. CLK and DAT are now perfectly shielded right up to the Photon2 pins and Vcc/GND are bypassed with 2.2 uF cap.If didn't sound like RF to me, but I wanted to give this a try. There are loud clicks every 500 ms or so. Sounds more like the software isn't doing the sampling correctly. I've used these little MEMS mikes successfully before but only I2S, not PDM. I'd have to check to see if I have a PDM library for any of the other MCUs I have on hand and use.
I tried to fool the upload feature by renaming my audio file to a jpg, but it wasn't fooled, so I can't let you hear it.

I tried various other sample rates- 8K, 11025, 22050. They were all worse or didn't work at all (except that 8K was clear of clicks but was rendered at 2X speed. I don't have any reason to think that Windows Media Player can't handle these wav files correctly.
I'm out of things to try.

Rick- On another topic. The Particle community library Adafruit_SGP40 and its included example "usage" won't compile (for Photon2 anyway). The following line
#include <Adafruit_BusIO_Register.h>
is missing and has to be added manually. Also the given example uses the function call
but that function does not exist in the adafruit_SGP40 library itself.The example is definitely not meant for the ADAFRUIT_SGP40 library that is in the Particle community library.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.