Can you use the Adavoice voice changer and still analog read

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kingnerd
 
Posts: 4
Joined: Sun Oct 26, 2014 9:10 pm

Can you use the Adavoice voice changer and still analog read

Post by kingnerd »

I built the Adafruit voice changer and everything is working great! I can convert my kids' voices into super freaky sounds-> Perfect.

Phase two of the project is to light up some neopixels based on the amplitude of the mic input. I know that you can't do AnalogRead on the mic input while the voice changer is active but is there any other way to do this? I tried to tap into the interrupt function and write the amplitude to a global variable but don't see how I would read the amplitude.

My super hacky way that kinda works is I shut down the the voice changer every 1000 times through the loop(), AnalogRead and then restart the voice changer. Super crappy and it clicks every time the voice changer starts but it works.

Another super hacky solution is to use a second arduino and do the neopixel stuff on that one. Is it possible for me to wire the microphone into both Arduinos or would I need a second mic? I really don't want to use a second arduino if at all possible.

Thanks in advance for any input on this.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Can you use the Adavoice voice changer and still analog

Post by pburgess »

Splitting the microphone to two Arduinos is totally doable, yes.

Modifying the interrupt function might better. Have a look at the adavoice_face sketch for ideas:
https://github.com/adafruit/adavoice/bl ... e_face.pde
Specifically, look for any reference to "oldsum" and "newsum," which maintain a sort of running average amplitude thing from 0 to 255. (Just noticed a possible bug in this code -- those variables should have been declared 'volatile' but aren't.) They're calculated in the interrupt, and the loop() function can then read the result at whatever its natural refresh rate is.

BUT...I just noticed you're using NeoPixels. Those just Will Not Play Nice Ever with code full of interrupts like this...they're super picky about timing.
Option 1: use a different type of pixels, such as LPD8806, which have a separate clock line and are immune to interference from interrupts.
Option 2: the split-to-two-Arduinos idea originally mentioned. You can use a low-cost board like a Trinket for this, and use analogRead() to gauge amplitude (maybe look at the Ampli-Tie project in the Learning System for code ideas).

User avatar
kingnerd
 
Posts: 4
Joined: Sun Oct 26, 2014 9:10 pm

Re: Can you use the Adavoice voice changer and still analog

Post by kingnerd »

Thanks for the super quick response! Exactly what I was looking for.

I already have an extra Mega so I will just use that for the neopixel side of things and split the mic and analogRead over there. I already have some code that smooths out the input amplitude.

With two arduinos do I have to ground them together or do anything special on the mic input to the Mega?

User avatar
kingnerd
 
Posts: 4
Joined: Sun Oct 26, 2014 9:10 pm

Re: Can you use the Adavoice voice changer and still analog

Post by kingnerd »

I have been experimenting with connecting a single mic two two Arduinos and have hit a roadblock.

One of the Arduinos (Name it "Arduino#1") is wired as a voice changer and it is working properly:

Image

The other Arduino (Name it "Arduino#2") has a tap on the "Out" line of the mic connected to analog input 0.

What I am seeing is that the mic input on Arduino#1 is working fine. If I don't start the voice changer and do an analogRead(0) then I am seeing the values I would expect (~512 with no mic input and then a range based on the volume into the mic). On Arduino#2 with the same analogRead(0) I am seeing values all over the place like this:

0
38
1023
524
2

Any ideas on what I am doing wrong would be greatly appreciated. My instinct says that it is something to do with power, ground and maybe the fact that Arduino#1 has an AREF connection to power and the Arduino#2 doesn't.

User avatar
kingnerd
 
Posts: 4
Joined: Sun Oct 26, 2014 9:10 pm

Re: Can you use the Adavoice voice changer and still analog

Post by kingnerd »

Some more interesting observations from some testing I just did:

If I connect the mic to the 3.3v and ground of Arduino#2 (It is an Arduino Mega) then analogRead(0) gives a baseline of ~340 and then reacts to sound as I would expect going from 0 to ~660. Interesting that it is a different baseline than having it connected to Arduino#1.

Another observation is that if I wire both arduinos up and have the mic out tap running to analog input 0 on Arduino#2 AND I connect the ground from Arduino#2 with the ground from Arduino#1 then I get the baseline of ~340 and it reacts as expected.

So..... If they both need to be grounded together then the only question left is why do Arduino#2 (The Mega) and Arduino#1 have different baselines and do I need to care.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Can you use the Adavoice voice changer and still analog

Post by pburgess »

Yes, both boards will need a common ground.

As for the voltage difference...Arduino #1 (running the voice changer code) is set to use the AREF (analog reference) pin for scaling inputs. Since 3.3V is connected there, the 0-3.3V from the microphone will center near 512 and exhibit the full-swing from 0 to 1023 (ish...there'll be a little wiggle factor in all these numbers).

To do the same on Arduino #2, connect 3.3V to AREF, then add this line in your setup() function before any analog readings are taken:

Code: Select all

analogReference(EXTERNAL);

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”