-
Notifications
You must be signed in to change notification settings - Fork 908
Add example for analog ICS-40180 microphone #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for analog ICS-40180 microphone #135
Conversation
while (1) { | ||
adc_raw = adc_read(); // raw voltage from ADC | ||
printf("%.2f\n", adc_raw * ADC_CONVERT); | ||
sleep_ms(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the 10ms sleep here implies there's a maximum frequency that this code will be able to detect? (only mentioning this because you talked about FFT analysis earlier)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Though I'm not 100% sure where the botteneck is/will be, I don't think it's with the ADC but rather on the Python side with polling values from the UART, so I just set 10ms as a sensible value.
|
||
def serial_getter(): | ||
# grab fresh ADC values | ||
# note sometimes UART drops chars so we try a max of 5 times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, this is probably related to raspberrypi/pico-sdk#504 !
adc/microphone_adc/README.adoc
Outdated
|
||
The Pico has a 12-bit ADC, meaning that a read operation will return a number ranging from 0 to 4095 (2^12 - 1) for a total of 4096 possible values. Therefore, the resolution of the ADC is 3.3/4096, so roughly steps of 0.8 millivolts. The SparkFun breakout uses an OPA344 operational amplifier to boost the signal coming from the microphone to voltage levels that can be easily read by the ADC. An important side effect is that a bias of 0.5*Vcc is added to the signal, even when the microphone is not picking up any sound. | ||
|
||
The ADC provides us with a raw voltage value but when dealing with sound, we're more interested in the amplitude of the audio signal. This is defined as one half the peak-to-peak amplitude. Included with this example is a very simple Python script that will plot the values it receives via the serial port. By tweaking the sampling rates, and various other parameters, the data from the microphone can analyzed in various ways, such as in a Fast Fourier Transform to see what frequencies make up the signal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why say "we're more interested in the amplitude of the audio signal. This is defined as one half the peak-to-peak amplitude." when the Python code just plots the raw voltage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plotting the voltage lets us see everything, including the peaks. It's just background info I guess.
printf("Beep boop, listening...\n"); | ||
|
||
bi_decl(bi_program_description("Analog microphone example for Raspberry Pi Pico")); // for picotool | ||
bi_decl(bi_1pin_with_name(ADC_PIN, "ADC input pin")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kilograham Is ADC_PIN
here correct, or should it be ADC_PIN + 26
as used with adc_gpio_init
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amusingly, I faced the same dilemma. adc_select_input
expects 0-3 while adc_gpio_init
expects a proper pin number.
Where are we on this, are we ready to pass it to @kilograham for a final review? @lurch opinions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds an example for an analog ICS-40180 based microphone from SparkFun (but really any analog microphone should do). It includes a simple Python script that takes information directly from the serial and plots it for easy visualization.
Checklist