Hello!
I am playing with the onboard microphone of the Arduino Nano RP2040 Connect.
I loaded the PDM example sketch, and only modified the Serial print to:
// Print samples to the serial monitor or plotter
for (int i = 0; i < samplesRead; i++) {
Serial.print(-20000);
Serial.print(" ");
Serial.print(20000);
Serial.print(" ");
Serial.println(sampleBuffer[i]);
}
This allow to keep a kind of fixed Y axis scale by always printing the same upper and lower value. You can personalize the upper and lower value to your liking. The green curve is the microphone read values. I am able to see spikes passing by, even if there is no noise going on:
Sometimes they are positive, sometime negative. Always the same absolute value, arround 10k.
I tried reducing the PDM frequency from 16kHz to 8kHz, and the output is now really clean. Does anybody have any idea of what is happening?
I tried to replicate your issue but my signal stays clean the whole time. A signal this short and such a large amplitude should be audible. On the other hand any naturally occurring acoustic signal would have a negative part and some ringing afterwards.
I had a look at the schematic and PCB. There is not really a lot that can be broken. The PDM interface is digital and the two wires between the microphone and the RP2040 are short.
Are the spikes remaining when you change the setup e.g., use another USB cable, USB port, create some sound signal (preferably a near sine wave)?
Hello!
I made some tests today and I think I might have a clue
First, i played a sine wave using a function generator and a small speaker:
For this first test, I was using my original setup which is a raspberry pi 400, to compile and upload the PDM example to the Arduino Nano RP2040 Connect. Here are the results:
We can see those strange spikes, they can be positive or negative, and there was no other noise appart from the sine wave in the room.
I then moved to a windows laptop, hooked the arduino in it (I did not recompile or anything) and had a look at the Serial Plotter, I saw exactly the same spikes. Just to try some random tests, I modified the frequency from 16000 to 16001 from windows laptop, and there was no spike, only a clean sine wave. I put the frequency back to 16000, and still no spike.
I moved back the Arduino to the pi 400 without recompiling: no spike. A soon as I recompiled from pi 400: spikes were back.
This lead me to think that indeed, it is not a hardware problem but a software issue. The PDM example seems to be exactly the same on pi 400 and windows laptop, so it could be that the PDM.h library that i have on pi 400 and on the windows laptop are not the same, or that something bad happen during compilation on pi 400. I found on pi 400 that PDM library version was 1.0 in library.properties. Wanted to compare with the windows laptop, but could not found the location of it!
Do my conclusion looks tangible? Where can i locate the PDM library properties file on the windows laptop?
Select File > Preferences from the Arduino IDE's menus.
Check the box next to "Show verbose output during: [] compilation".
Click the OK button.
Open any sketch that has an #include directive for PDM.h. This one will do:
#include <PDM.h>
void setup() {}
void loop() {}
Select Sketch > Verify/Compile from the Arduino IDE's menus.
Wait for the compilation to finish.
Now check the contents of the Click on the black console pane at the bottom of the Arduino IDE window. Near the bottom, you should see something like this:
Using library PDM at version 1.0 in folder: C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\2.3.1\libraries\PDM
That is the location of the library. It also shows the version value from library.properties right there.
Of just as much interest is the 2.3.1 part of the path. This is the version of the "Arduino Mbed OS Nano Boards" platform in use, which you can also find in the Arduino IDE's Boards Manager. It would be good to check whether you have different versions of "Arduino Mbed OS Nano Boards" installed on the different machines.
It turns out i was using 2.2.0 on raspberry pi 400 and 2.1.0 on the windows laptop.
After updating both to 2.3.1, i have spikes on both they are half the previous amplitude though.
Well, I think i will stop my inquiry here... thank you Klaus_K and pert. It seems my problem was not present on 2.1.0, but i prefer to stay on last version.
Line 27: int decimation = 128; // this was 64 in version 2.1.0
// Open_PDM_Filter_64 in 2.1.0
Line 182: Open_PDM_Filter_128(rawBuffer[rawBufferIndex], finalBuffer, 1, &filter);
Line 78: filter.MaxVolume = 1; // added in 2.3.1, does not seem to cause issue
I am not sure yet, how this causes the issue. I believe it should be OK to use the old values.
Good catch! I admit i was tired yesterday and a little discouraged after updating everything, just to have spikes on both platform
Do you know if we can make like a report or something, so that the issue is looked into, or is this just too little of a problem? I think that for some case it could cause unwanted behavior, for example if you want to monitor ambient noise and want to react on a small threshold change.
You can see the development history for the PDM library here: https://github.com/arduino/ArduinoCore-mbed/commits/master/libraries/PDM
but a change in a dependency (e.g., Arduino core library, Arduino core API, Mbed OS) can also be a factor, so the PDM library code base may not tell the full story.
The output of the example is a sampled signal of the sound wave. Just the PDM used to transfer the signal from the microphone to the Arduino interface may seem a bit harder to understand.
With PDM the more HIGH bits/pulses you have the higher the signal value. The maximum is a continuous HIGH signal. The lower the signal value the fewer pulses you have until you have a continuous LOW signal.
The advantages of Pulse Density Modulation are
immune to interference because it is digital
can be converted to analog signal using a low pass filter (very cheap)
Most users do not need to worry. The library takes care of everything. From the applications point of view the PDM is invisible.