-
Notifications
You must be signed in to change notification settings - Fork 184
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
Support MEMS microphone #11
Comments
I agree to me it would be very useful to have code for mems mic readout. |
The microphone is set up as a regular audio input via i2s, so any software capable of reading a standard audio device can access it. The reason Python support is currently missing is because it's something of a challenge sampling a microphone input and performing any meaningful analysis on it on realtime in Python. It's a work in progress, though. The solution involves a C daemon called FFsockeT the sole purpose of which is to sample the microphone, apply a (libfftw3) FFT and output the transformed data via a socket into a client application- the intent being that Python can consume this datae easily. The source for that is here- https://github.com/pimoroni/FFsockeT I've been using Internally we also have a rough-and-ready Python application for sampling the microphone:
|
@Bugierek the someone would be me, and this is on my radar! (in fact I'm more or less the only software wrangler at the moment, for better or worse) |
Thanks for reply. I appreciate your effort to make it all working, great job! |
I'm certainly no expert on these matters, but as I understand it A-weighting requires a FFT step in order to produce the per-frequency amplitude bands which are then weighted. The alternative being to use a digital filter to isolate the individual frequency bands one at a time before A-weighting them. Getting a raw dB SPL without any kind of time to frequency domain conversion is - I believe - a folly since it wouldn't account for either the characterists of human hearing nor the variable frequency response of the microphone itself. Granted it may provide a useful relative measurement of noise level for a particular environment - ie: which times of day are more reletively noisy than others. I also suspect for most environmental noise analysis that a certain subset of frequencies or events will be particularly of interest- things like obnoxiously driven cars, horns, large trucks passing, etc. Honestly, this is one of the most difficult challenges I've faced in terms of general understanding of the core concepts. Sound is decidedly more information dense than light levels or temperature. This is one of those problems where capturing chunks of audio throughout the day and throwing them at machine learning to classify frequency and density of "annoying noise events" would be, I guess, ideal. This looks like a deep rabbit hole, though- https://github.com/tyiannak/pyAudioAnalysis/ Some useful information here, too (for posterity) - https://makersportal.com/blog/2018/9/17/audio-processing-in-python-part-ii-exploring-windowing-sound-pressure-levels-and-a-weighting-using-an-iphone-x And while I'm bundling information here, the datasheet for the MEMS microphone part - https://media.digikey.com/pdf/Data%20Sheets/Knowles%20Acoustics%20PDFs/SPH0645LM4H-B.pdf |
Yes you're right that it'd be best to have at least A weighted SPL values and even better some sort of FFT graph.Another way that people look at noise are full octave or third octave bands of frequencies, but it also requires FFT step to calculate bands of frequencies. Actually the Full or 3rd octave bands are the default way that acoustic consultants look at noise data :) btw that's another project I've found on the subject. A bit outdated but still: https://github.com/SuperShinyEyes/spl-meter-with-RPi |
Hi @jk , can you share your updates to push data to InfluxDB and Grafana? I would love to have that data locally for historical purposes. I already have a TIG stack running. |
A few notes for people following this issue. I'm new to Raspberry Pi, and what follows is from my poking at this with a new Pi Zero and Enviro+ with a fresh Raspbian Stretch install from the latest 2019-04-08 image. But I did get sound working! If you Google search getting the MEMS mic to work, you'll like land on this article at Adafruit. Don't follow that as-is, it's pretty old and leads your through a lot of unnecessary work. First, do not use rpi-update to get your system up to date. For the driver stuff, a simple Second, you do not need to run rpi-source to download and recompile the kernel. Just install the kernel headers with After that, get the kernel module source and follow the rest of the instructions from the Adafruit article. Since I have a Pi Zero, I had to change the module source as instructed. And to test the volume control (in the bottom of the Adafruit article) I had to change the name from "Boost Capture Volume" to "Master Capture Volume" (which was down a ways in this thread). But after modifying the source and building and loading the module I was able to record a wav file using arecord! Then I had to modify the FFsocket source to open the MEMS mic kernel module by changing it from hw:adau7002 to hw:sndrpisimplecar. And with that I managed to get ffsocket to run and was able to use client.py to read the output and can see varying values in the output array. I don't know what any of those values mean :-) but it seems to be doing something in response to noise near the Enviro+ |
David thank you for your post I will follow your instructions on my Enviro+ plus board. I am working on using the ACD pin to read an external adafruit 1733 anemometer as well by modifying the Gas.py script to include a read function and convert voltage to m/s reading , Then adding another mode to enviro_demo.py to be able to get a display of wind speed. |
Regarding obtaining the A-Weighted SPL I have found this example: |
I have found another implementation here, so it might be helpful to see how it was done on other platform : https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Sound_Pressure_Level.html |
Hi @Gadgetoid I just wanted to follow up on this issue. It would be really great to have a python script to measure noise pollution. I am currently developing a project that will use the Enviro + sensor in 30+ classrooms and getting a measure of noise would be really amazing. |
You have to adapt a dead cat attachment to the noise sensor otherwise the
hard walls and floors and ceiling will amplify your levels and give you
improper levels .
…On Mon, Oct 14, 2019 at 10:47 AM vschinazi ***@***.***> wrote:
Hi @Gadgetoid <https://github.com/Gadgetoid> I just wanted to follow up
on this issue. It would be really great to have a python script to measure
noise pollution. I am currently developing a project that will use the
Enviro + sensor in 30+ classrooms and getting a measure of noise would be
really amazing.
Thank you.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#11?email_source=notifications&email_token=AKFAE2ZCQYLDSCW4TPSJJR3QOSBB3A5CNFSM4H62SO7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBFAWOQ#issuecomment-541723450>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKFAE24Q22DKTVSFSVMKNHDQOSBB3ANCNFSM4H62SO7A>
.
|
Oh wow, thank you for the heads up! What do you recommend for that? Do you actually have a working python script for the microphone? Would you be able to share that? |
Sorry I should have mentioned that the noise/microphone code is currently pending review and merge in a pull-request which you can find here: #33 I'll keep this issue open because I don't believe Python is the best/only way to do this, and alternate setups which access the i2s microphone could be useful or interesting to others. |
Hi, Sorry for flooding this topic with bunch of links, I'm not a dev and can't really code, but hopefully in some of these examples there will be something useful and helpful to get it working well on Rpi. |
There is some sound code written now, but when I do (on a fresh install of Raspbian): |
in case anyone is wondering, this seemed to help: |
Hi, I am another one interested in being able to measure noise pollution in terms of dBA, which would clearly be useful in an Environmental monitoring board. (In fact we wrongly assumed this would be provided before buying the board). Now, I notice that there is now a noise.py library with three functions to obtain noise profile and mean amplitudes at a frequency range or ranges. But it's not clear what units these return and I don't think they fit the bill for dBA (which involves root-squared-mean values and A-weighting according to a curve). Am I wrong @Gadgetoid - or can these be easily adapted for dBA? (Apologies if you see this twice - I thought I posted it yesterday - but it seems to have been my imagination :-) ) Thanks a lot. |
Hi. Another who bought several Enviro+ hoping to measure dBA. |
Hi. Also bought an Enviro+ hoping to measure dBA. Would love to get some input here! Thank you :-) |
Hello to everyone! I bought Enviro+ mainly to acquire data related to indoor environments and mainly for noise level (dB or dBA). |
Anybody else got this error on running the noise-profile.py:
Installed also the sounddevice and the libportaudio2 |
Hi Gadgetoid. |
Hey Steve, drop me a line - follow the link to my website. I have some ideas for you. |
@seaniedan @ftosteve, do you have any updates from your discussions that you can share publicly? |
Nothing from me sorry. I have been offline for a few weeks. I did look at seaniedan's link but nothing related to this subject. |
I took a copy of your northcliff_spl_monitor. Until I commented out the mic line, I got an exception (couldn't find device)
I got it working on my Enviro. I'm now trying to splice it into the app wot I wrote, which displays a horizontal bar chart of the measurements at various bands. I'll post the code if & when I get it cleaned up. It's a hacked mess at the moment. Anyway, thanks for your code. |
@Cumberland-Pi, great news, and let us know if you need anyone to test your code even in early stages. :) |
@Cumberland-Pi I suspect that if the script couldn't find "dmic-sv", the I2S microphone setup (as per the Setup section of the README) hasn't been successfully completed. I might be wrong, but you might find that the northcliff_spl_monitor code won't run successfully without it because I found that the microphone level needed to be increased to get reasonable readings. I've also now updated my code to include the ability to provide graphical displays. The display types can be selected as command line arguments that are shown in the updated README. |
@roscoe81 |
@roscoe81 Running your .py I get dB(A) reading on the screen that is about ~5dB(A) more than my phone app, which is not bad as an indicator. On a side note. I want to replicate my pi/enviro devices 50+ times. Thanks again, |
@ftosteve I would expect that imaging the SD will replicate all the required settings. |
@roscoe81 Got my sound app mentioned above working, and I've incorporated your Noise class. Here's the code: Comments always welcome. I plan to splice in Ross' displays at some later date. |
thanks @roscoe81 for moving this forward |
Thanks for the feedback @dguk25 |
Great work @roscoe81 ! |
Glad that you're seeing progress @dguk25 I've now added a maximum sound level line (along with the time and date when it was recorded) to Display 1 in my latest code update. I've found that to be quite useful. |
I’ve now integrated noise level measurement into my enviro-monitor and it seems to work reasonably well. |
Brilliant. Will check it out later today. Thanks for the note above as well. The maximum sound level line works really well 👍 |
@roscoe81, thanks a lot for all your work! I've finally had a chance to test the current version northcliff_spl_monitor.py and it seems to work well. I hope to find some time next week to compare the measured noise levels with some apps I have installed on my phone. Three issues I ran into while following the instructions in the README were:
And a final question: Is there any difference in the noise measurement implementation between enviro-monitor and the stand-alone script? Thanks again and keep up the great work. |
Quick update on the alsamixer issue: When physically logged into the console via a keyboard I was able to change the capture level as documented. So the behaviour I was seeing definitely seems to be related to me being connected via SSH beforehand. |
Thanks for your feedback @ChristophDerndorfer
I've found that the measurements between the two implementations are identical but the cycle rates are slower on the enviro-monitor |
|
Not sure if will help anyone, but i've been scratching my head on this for ages. After many obscure searches I stumbled upon https://www.alsa-project.org/main/index.php/Asoundrc. Reason, I need this, is my pi has no desktop and my code will run as a Service on boot, so ordinarily not logged in to console. |
hi all . great to see this continually progressing. appreciate the work @roscoe81 I'm wondering about a couple of things:
|
Thanks for your feedback @dguk25.
|
I followed the instructions here and then the |
I find I'm having to do this step each time I reboot the pi:
copying specific text, then running
Otherwise it doesn't recognise the i2smic. Is there a way round this @roscoe81 ? Have I missed something in the setup. |
I haven't come across that issue @dguk25 and the i2smic is recognised on my unit after each reboot, so I'm not sure that I can help you. The only thing I can suggest is to ask if you set up the auto load at boot in "Auto Load at Boot" in these instructions. |
Thanks. I have done that (on multiple occasions!). Is ~/.asoundrc meant to
be a permanent doc? It seems to need creating after each boot.
I'll hopefully be setting up a couple of other devices soon, so will see if
I get the same behaviour.
…On Thu, 6 May 2021 at 07:06, Ross Fowler ***@***.***> wrote:
I haven't come across that issue @dguk25 <https://github.com/dguk25> and
the i2smic is recognised on my unit after each reboot, so I'm not sure that
I can help you. The only thing I can suggest is to ask if you set up the
auto load at boot in "Auto Load at Boot" in these instructions
<https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-test>
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AETBUPWWTGAVXMXSYKGIRM3TMIWWLANCNFSM4H62SO7A>
.
--
--
<http://youngrobot.com/>
Young Robot |* *App
Development Specialists
Registered in England and Wales. Company No
06076173.
Registered Office: International House, 24 Holborn Viaduct,
London, EC1A 2BN
*Technical Support
*UK: +44 7872 825 008 |
***@***.*** ***@***.***>
*** IMPORTANT
NOTICE **
*This e-mail and the information it contains may be privileged
and/or confidential. The unauthorized use, disclosure or copying of this
e-mail or any information it contains, is prohibited and could, in certain
circumstances be a criminal offence. If you are not the intended recipient
please notify us immediately and delete this message from your system.
|
For anyone in the future who is also trying to make
After running these steps, test if everything works through: |
Thank you to everyone who has contributed to this awesome thread! Thanks especially to @roscoe81 I can now record from the mic. What is going over my head through is just getting a simple output to a csv e.g. a csv with the noise level every minute or the average noise level in the past minute. E.g. similar to the other outputs here https://angelaambroz.com/blog/posts/2021/Mar/08/pi_project_2_indoor_environment_monitor/ |
That really is EXCELLENT news! Thank you. I'll be experimenting more with this functionality and hopefully improve my Grafana dashboard. |
Sorry for the lack of response here. I don't have a good answer for why it slipped me by, other than: ARGH. I think it goes without saying that the effort of @roscoe81 is greatly, greatly appreciated. I am not in possession of the time, expertise and headspace to produce as well-rounded a solution. Our software always straddles some awkward line between "feature complete, usable example" and "very basic starter for makers to take and run with" and it doesn't always work out. Should this library try to implement @roscoe81's code? I believe we should probably have a basic setup in the Enviro library, but also link to @roscoe81's excellent project as a more complete solution. This is so we can direct credit where credit is due, lend some exposure to a good project, but also not simply kick the can for proper noise monitoring support completely down the road. |
I received my enviro+ last week and over the weekend I managed to install the examples and build my own InfluxDB bridge to show all those measurements via Grafana. Had a lot of tinkering fun, thanks :)
But I'm missing a way to interface the MEMS microphone to read out noise levels. I suppose that support is under way, can someone give an ETA or directions where to read further.
The text was updated successfully, but these errors were encountered: