A Python Script that performs a basic sound pressure level monitor using the Pimoroni Enviro+
This script explores the potential of using the Pimoroni Enviro+ as a sound pressure level monitor. This project is still in the experimental phase. It should therefore not be used when accurate sound pressure level readings are required and should only be used as a base for future development.
Versions 1.0 and later use streaming to overcome the microphone's startup "plop" that was identified in the excellent review here
The microphone's startup "plop" can be seen here and it plays havoc with the sound readings if the microphone is started for each sampling. A DC offset remained after removing the startup "plop", seen here and removing that DC results in this.
Version 2.8 introduces improved A-Curve weighting. This requires the installation of some additional modules and an adjustment of the alsamixer microphone level to avoid clipping. These are highlighted in the Setup section.
sudo apt-get update
sudo apt-get upgrade
curl -sSL https://get.pimoroni.com/enviroplus | bash
sudo pip3 install matplotlib
sudo python -m pip uninstall sounddevice
sudo pip3 install sounddevice==0.3.15
For Versions 2.8 and later:
sudo apt-get install python3-scipy
sudo pip3 install git+https://github.com/endolith/waveform_analysis.git@master
For Versions 2.8 and later if wishing to use matplotlib for microphone debugging:
sudo apt-get install python3-gi-cairo
Follow instructions at: https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-test including “Adding Volume Control”
Use the following instead of the documented text for ~/.asoundrc:
- #This section makes a reference to your I2S hardware, adjust the card name
- #to what is shown in arecord -l after card x: before the name in []
- #You may have to adjust channel count also but stick with default first
- pcm.dmic_hw {
- type hw
- card adau7002
- channels 2
- format S32_LE
- }
- #This is the software volume control, it links to the hardware above and after
- #saving the .asoundrc file you can type alsamixer, press F6 to select
- #your I2S mic then F4 to set the recording volume and arrow up and down
- #to adjust the volume
- #After adjusting the volume - go for 50 percent at first, you can do
- #something like
- #arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v myfile.wav
- pcm.dmic_sv {
- type softvol
- slave.pcm dmic_hw
- control {
- name "Master Capture Volume"
- card adau7002
- }
- min_dB -3.0
- max_dB 30.0
- }
For versions prior to Version 2.8:
Use alsamixer to set adau7002 capture level to 50
For Version 2.8 and later:
Use alsamixer to set adau7002 capture level to 10
For a numerical display of the current approximate overall sound level (Display 0):
Run python3 northcliff_spl_monitor.py or python3 northcliff_spl_monitor.py 0
or for a graphical display of current and past approximate overall sound levels (Display 1):
Run python3 northcliff_spl_monitor.py 1
or for a graphical display of current and past approximate sound levels by frequency band (Display 2):
Run python3 northcliff_spl_monitor.py 2
Version 2.1 adds the ability to cycle through the three displays by briefly touching the Enviro+'s light/proximity sensor
Version 2.2 adds a line in Display 1 that shows the maximum sound level that's been recorded since selecting that display, as well as the time and date when it was recorded. The maximum sound level is reset when selecting another display.