Hi there,
I'm a big Raspberry Pi B+ guy, but I decided to finally try out my first project with the Arduino Uno. I followed the instructions for installation and successfully uploaded that example "Blink" sketch that flashes the LED by pin 13.
However, I'm having trouble with a more complicated second project with my new Electret Capsule Microphone. I followed these instructions for setup (minus the soldering which I'll do later but the connections look pretty good). And I uploaded this sketch:
/****************************************
Example Sound Level Sketch for the
Adafruit Microphone Amplifier
****************************************/
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup()
{
Serial.begin(9600);
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 3.3) / 1024; // convert to volts
Serial.println(volts);
}
When I open the Serial Monitor, I can see numbers scrolling. But these numbers seem to have no relationship to the audio levels in the room. I even disconnected the amplifier and the numbers continue scrolling... See attached screenshots.
Any ideas what these scrolling numbers are measuring? And what I'm doing wrong?
You should learn to solder connections. It often makes the difference between functional and nonfunctional.
(minus the soldering which I'll do later but the connections look pretty good
You need to solder headers onto the board. While the connections might look good it is unlikely that they will be.
I even disconnected the amplifier and the numbers continue scrolling
Yes they will keep on scrolling why should they not? Also the numbers will be random, that is simply pickup from the floating input.
But these numbers seem to have no relationship to the audio levels in the room. I even disconnected the amplifier....
With the input disconnected you may be picking-up lots of noise.
Try grounding the analog input (with the mic disconnected). With the input grounded the peak-to-peak voltage should be zero.
You can also try adding a couple of print statements to look at the actual Min & Max values. This should give you a clue about what you're getting from the microphone (if anything).
With the analog input connected to ground (with the mic disconnected) you should read zero and with the input connected to 5V you should read 1023. (The peak-to-peak voltage is zero in either case.)
If you increase the sampleWindow time to a few seconds (a few thousand milliseconds) you can manually switch between ground (zero volts) and 5V and that should give you a peak-to-peak voltage of 5V.
If the ground and voltage tests work, that proves your Arduino and sketch are working and the problem is with the microphone or the mic wiring.
You can also try the [u]Analog Read Serial[/u] sketch (without the pot) to directly read and display the ADC when connected to ground, 5V, or the microphone.
BTW - This isn't important right now, but the voltage calculation in the sketch looks wrong since you are not using a 3.3V ADC reference.
Hey guys,
You were right, the soldering did the trick. Now when I upload the sketch, the Serial Monitor starts scrolling around 0.03 until I blast music and it jumps to 0.35 or even 0.40. So I think that's working now!
However, I moved on to the next portion of the demo and I've run into a new problem. I followed the instructions to assemble / solder a Bicolor LED Matrix to illustrate the sound levels. However, after finishing all the assembly, downloading / unzipping the relevant libraries, and uploading the relevant sketch (copied below), I'm getting no response from the LED matrix.
/****************************************
Scrolling Sound Meter Sketch for the
Adafruit Microphone Amplifier
****************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
// Include the Matrix code for display
Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
const int maxScale = 8;
const int redZone = 5;
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup()
{
Serial.begin(9600);
matrix.begin(0x70); // pass in the address
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin;
// map 1v p-p level to the max scale of the display
int displayPeak = map(peakToPeak, 0, 1023, 0, maxScale);
// Update the display:
for (int i = 0; i < 7; i++) // shift the display left
{
matrix.displaybuffer[i] = matrix.displaybuffer[i+1];
}
// draw the new sample
for (int i = 0; i <= maxScale; i++)
{
if (i >= displayPeak) // blank these pixels
{
matrix.drawPixel(i, 7, 0);
}
else if (i < redZone) // draw in green
{
matrix.drawPixel(i, 7, LED_GREEN);
}
else // Red Alert! Red Alert!
{
matrix.drawPixel(i, 7, LED_RED);
}
}
matrix.writeDisplay(); // write the changes we just made to the display
}
I'm not an expert at soldering but I think I got all the connections (see attached photos)... Any ideas?
Try running the matrix examples to see if that works first. It will check your wiring.
Hey Grumpy Mike,
Good call. So I just tried running Examples > Adafruit LED Backpack Library > Matrix 8x8. It uploaded just fine, but none of the LEDs are lighting up. I tried Bicolor 8x8 too for good measure but no luck.
I just double-checked all of my connections which still look good. So the only thing I can think of is that I possibly killed the 8x8 Bi-Color LED Matrix during soldering? This was my first time, and I just read something online that you need to be careful about how long your iron touches the pins...
Any other ideas for troubleshooting before I order a new part?
Any other ideas for troubleshooting before I order a new part?
Yes there are several things that could be wrong.
First off, using the example code try swapping the A4 & A5 wires over, even if it is wrong it will do no harm.
Next get your meter and measure the voltage on the input pins of the matrix module to make sure it is getting to the module and it is the right way round. If you haven't got a meter then go out and buy one, you can get one at a thrift shop for less than $10.
Next remove the power and with the meter check the continuity from pin to pin. That is from the pin on the Arduino chip to the pin on the matrix PCB, in that way you check the connectors and get to learn where things are on the actual chips.
Check the soldered connections for shorts to adjacent tracks.
This was my first time, and I just read something online that you need to be careful about how long your iron touches the pins
It is unlikely to be that.
Thanks Grumpy Mike! I tried everything you mentioned and still couldn't get it to work, but while playing with it I noticed some of the soldered connections were a little loose (they wobbled a little bit). So I decided to re-do them which actually took a long time because I messed up so many times, but I finally got it working!
Check out the attached pic. thanks so much.