Go Down

Topic: WTV020SD -> Problem (Read 729 times) previous topic - next topic

Zawislak

Hello everyone!
i am creating an SPL Meter using Sparkfun Sound Detector, speaker, LEDs, LCD and WTV020sd with 512MB microSD card.
I almost finished my code, I am converting the ADC value from sparkfun to SPL value in dBs.
I've made 3 sections using "if". It works like this:
for example:
40-50 dBs green LED on, actual value in dB at the screen
50-70dBs yellow LED on, actual value in dB at the screen
and
over 70dbs red LED on, actual value in dB at the screen AND my own sound effect "Please be quiet".
And there is a problem because everything works just fine when i test the code without the line with wtv020sd. The LEDs and LCD is working just like i want it to work. The SPL value is the value i want. When i add the lines with wtv020sd ( the whole set is working i play this sound at the blank project) the program comples etc but it shows all the time that it's "loud' and it shows some stupid values like 90dB even though normally it shows like 45 dB. So well i wonder what i can do because it looks like the line with wtv020sd is breaking down evverything.
If anyone knows what may be the problem i would be very grateful !

Idahowalker

Well, from the well formatted code you showed in code tags, I'd say the problem, after looking at the code, is the line with wtv020sd.

Really, help us help you and post some well formatted code in code tags so we can see and comment.

Zawislak

#2
Oct 15, 2019, 11:09 am Last Edit: Oct 15, 2019, 11:17 am by Zawislak
Code: [Select]

adc=analogRead(A3);
adcV=(adc*VoltPerRead);
dB=20*log(adcV/sensitivity);
dBSPL=-46+dB+94;

if ( (dBSPL>0 ) && (dBSPL<=50))
{
digitalWrite(8, HIGH); //green
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(500);
}
else if ( (dBSPL>50) && (dBSPL<=70))
{
digitalWrite(8, LOW);
digitalWrite(9, HIGH); //yellow
digitalWrite(10, LOW);
delay(500);
}
else if ( (dBSPL>70) && (dBSPL<=110))
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH); //red
wtv020sd16p.asyncPlayVoice(3);//"Please be quiet"
delay(5000);
wtv020sd16p.stopVoice();
}
}

Everything works fine if I don't add the 3 last lines with wtv020sd. When I add them my results go bad and I get "loud" all the time. I tried to use the wtv020sd seperately and it works so it looks like it gives some disruption or something and I have no clue what I can do more.

Grumpy_Mike

#3
Oct 15, 2019, 11:22 am Last Edit: Oct 15, 2019, 11:23 am by Grumpy_Mike
The compiler has no idea what "wtv020sd16p" is.

Did you forget to include a library that knows?

Please post all the code so we stand a chance of spotting your error.

Often it is not the code that throws an error that is wrong but the code leading up to it.

Zawislak

Well I don't have any errors it compiles and it works but the results are bad. I have all the libraries etc. The whole program is working and i check the values on serial print and the are good. The only problem is when I add the line to the "if" sections. In the setup loop I have something like a welcome speach, it plays only once when I turn on the device and it works okay. The only problem is when I add it to the if section.

Zawislak

Okay i moved on a little. The program starts better now but I have 2 issues:
1. I make an avarage of 10 samples of sound from the Sound Detector and:
After i run the program I see that the first few samples are going up a little and after a second everything cools down.
2. I realised that when it's too loud and the sound goes on it creates also samples over the value that's loud in the program and that's why it jumps in some kind of a loop for a while.
I don't know how to make it like: when it's too loud it starts taking samples after the sound from the speaker .

Grumpy_Mike

Read reply #1 again. And ask yourself how the hell is anyone else but you is going to know what is going on.

Go Up