Hello, welcome to this afternoon hack.
I have this ATTin85 on this carrier board, this speaker, and this tiny little microphone
right here.
I'm going to see if I can turn this into a loudspeaker system.
I could use something called an operational amplifier but I wanna see if I can just do
it with an attiny85 using the differential timer outputs.
Not quire sure how loud it will be, but it's worth finding out.
Who know maybe this could be used for some other project in the future.
The thing that inspired me to do this is this thing over here on twistedsanity.net.
A Class D amplifier.
It's really geared more toward being a high power amp with a bunch of other components
and it's a really neet project, but it's not really geared in the same direction I want,
which is to have the simplest project possible.
It does also use the ADC inputs and the PWM outputs I'm going to be using on this project.
The ATTiny85 has some interesting features.
It's got the ADC inputs and it's got these interesting inverted PWM outputs.
So, I can have a PWM signal which means that it'll be on and off and on and off and if
you average it out, it creates basically an analog signal.
One of the really neat things about the attiny85 is that speed in which the counter can be
incremented for PWMs can be very very fast, around 100MHz.
So, if you have a 100MHz signal and you divide it by 256 which is the number of increments
you can change the width of this...
You get around a 500 kHz output PWM wave, which is crazy high and the speaker will largely
just ignore.
So if the signal is off more than its on on the regular output, then the speaker will
go out, and if it's on more than it's off the speaker will go in.
It's also helped out because it has the inverted output, which helps push this output potential
even higher.
First I'm going to solder some wire onto this microphone here so I can hook it up to the
carrier board.
The way that these little microphone thingies work is they provide a current that will pull
the line down.
So, what that means is I can use a resistor to pull back on it.
So, I can take this tiny resistor here, it's 15 kOhms - this red line is hooked up to five
volts and I can probe the voltage across the microphone.
And, right now, it's reading 2.13 volts.
That means when there's no sound at all, there will be an average of 2.13 volts, which is
a voltage inside the range that the AVR can read.
What I'm gonna do is I'm gonna connect this little resistor here between Vcc and PB2,
which is an analog input on the AVR.
Now, I'm just going to take the microphone and the speaker ends here, and I'm going to
screw them into place on the terminals.
I would say our hardware here is done.
Time to go write some software.
One thing I think that might make sense to do right now is take a look at the sine wave
coming off of this PB2.
So, I'm going to look at PB2, and I am going to look at the oscilloscope.
So, right there, that is - actually it's disconnected right now.
Let's reconnect it.
That is about 2.2 volts.
And if I talk into the microphone, you can see the signal on the oscilloscope.
Oooo kaaayyy that's a lot of fun ♫I don't know why I like oscilloscopes sooo much.
Ooooooooooooooo♫.
Okay I think that's enough fun for right now.
Okay.
I just programmed it.
There is sound coming out of here.
It doesn't sound quite right.
It sounds a lot lower than I think it should be.
Probe right here and look at the scope and hope I see something.
So, there is a signal on here.
As, I can hear it.
I'm not sure what I'm looking at, though.
That is particularly confusing.
It looks like the div is roughly 100 Hz.
Maybe 120 Hz.
So, something is really wrong that the frequency is off by that much - and I'm not really sure
what the sound we're hearing is.
So, let's check the other pin.
That looks very different.
Hmm.
We're gonna have to go look at the code a little and the datasheet to see what could
be going wrong here.
Okay!
Now, it's a lot louder, and the signal makes a lot more sense.
Though there's still a lot of squiggles all over the signal.
You can actually zoom in and see the Fck on it.
It's pretty high.
It still doesn't quite look right, but whatever.
You do see a nice triangle wave.
It is going down in value instead of up.
There could be something wrong there, but, let's just play around with this.
That'll produce a triangle wave instead of a sawtooth.
[humming noise from speaker].
Oooh.
Very nice smooth sound.
Probably can't hear it very well.
[pitch increases].
Okay.
I'm just gonna say "Make" now.
I'm just gonna plug this back in.
It's still doing that same stupid triangle wave.
And let's see what happens.
[silence].
Hellooooo [click-click-click-click] hello hello hello hello.
Okay, Ican sorta hear it.
You can see that it's totally changing.
It's uuh it's working.
It just looks terrible on the oscilloscope.
If I talk into here, you can hear it, so it's [click click click click click click click
click] Hello Hello Hello Hello Hello Hello Hello Okay.
Let's see if we can bump up the volume.
Hello!
It looks like that algorithm there, it works.
It sounds terrible but it totally works.
So, ATTiny85, Speaker, Microphone.
That's really all you need in order to make a loudspeaker.
You know, maybe the reason it wasn't loud enough was because I wasn't using a big enough
speaker.
Hello!
Okay, now it is definitely loud enough!
There is one warning with all of this that's that you're actually outputting a lot of very
high frequency signal, that can damage speakers if they're smaller and especially if they're
tweeters.
I really don't care about this speaker, so it's a lot of fun.
Okay.
I think I'm actually done this time.
[Darth Vader Breathing] Luke, I am your father.