Using with Arduino
Its super easy to use this stereo amplifier board with an Arduino thanks to the great Adafruit library. Once you've installed the library you can connect the TPA2016 via I2C your Arduino, it will work with any kind or flavor. If you're using a different kind of microcontroller, the library is a good reference to help you port the code over.Download the library
First up, we'll download the Arduino library from the Arduino library manager.
Open up the Arduino library manager:
Search for the Adafruit TPA2016 library and install it
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Run Test Sketch
After you've restarted, you should be able to load up the File->Examples->Adafruit_TPA2016->audioamp sketch- On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5
- On Leonardo/Micro, SDA == Digital 2, SCL == Digital 3
- On Mega/ADK/Due, SDA == Digital 20, SCL == Digital 21
Now you can configure the amplifier settings on your own using the library procedures.
Adafruit TPA2016 Library reference
To use the library, you'll need to have something like these lines in the beginning of your code, they'll include the I2C Wire library and the Adafruit library as well. Then it will create the audio amplifier object. There's no way to change the I2C address on this device.#include <Wire.h> #include "Adafruit_TPA2016.h" Adafruit_TPA2016 audioamp = Adafruit_TPA2016();
audioamp.begin();
Channel Control
Now that you're talking to the amp, you can do stuff like turn on and off the right and left channels withaudioamp.enableChannel(rightchannel, leftchannel);for example, to turn off the left channel and keep the right one on, use
audioamp.enableChannel(true, false);Both channels are on by default
Gain Control
You can control the max gain that the amplifier will use, this is even with the AGC on. So if you select 20dB for example, the AGC won't automatically amplify any higher than 20dB.You can set the gain with:
audioamp.setGain(gain);Where gain is from -28 (dB) to 30 (dB)
Limiter Settings
The limiter is what helps avoid overdriving speakers if you have a fixed Wattage you want to stay under. By default it is On, you can turn it off with
audioamp.setLimitLevelOn();and back off with
audioamp.setLimitLevelOff();You can set the maximum voltage gain with
audioamp.setLimitLevel(limit);where limit ranges from 0 (-6.5dBv) to 31 (9dBV) see page 22 of the Datasheet for more details.
AGC configuration settings
You can set up the AGC for how it will react to audio level changes. If you're an audio geek you can use the tables on page 23-24 of the datasheet to set up the AGC exactly how you like. If you aren't sure what settings to use, check page 19 of the datasheet which has some basic guidance.You can start by setting the AGC compression ratio. This tells the amplifier how much to automatically tweak the gain to make loud and soft sounds about the same volume. For example, spoken word should have high compression since you want to have it all about the same volume. Adjustments are made by calling
audioamp.setAGCCompression(compression);Where the compression setting is TPA2016_AGC_OFF (1:1 compression), TPA2016_AGC_2 (1:2 compression), TPA2016_AGC_4 (1:4 compression), or TPA2016_AGC_8 (1:8 compression).
For example, to set the attack, use:
audioamp.setAttackControl(attackvalue);where attackvalue ranges from 0-31
To set the hold value, use:
audioamp.setHoldControl(holdvalue);Where holdvalue is between 0-31
and for the AGC release, use:
audioamp.setReleaseControl(releasevalue);Where releasevalue is also between 0-31
Pages 23-24 of the datasheet will tell you how to convert those values to ms/dB numbers.