TPA3118 PBTL Mono Digital Amplifier
The TPA3118 is a high-performance, mono, digital audio power amplifier with aStereo Serial Interface (SSI) for improved sound quality and reduced noise. It is designed for use in portable audio devices, wireless speakers, and other applications where high-quality audio reproduction is required.
The TPA3118 comes in a 20-pin QFN package. The pinout is as follows:
| Pin | Function | Description |
| --- | --- | --- |
| 1-4 | GND | Ground pins |
| 5 | VCC | Power supply pin ( typically 5V or 3.3V) |
| 6 | SCK | Serial clock input |
| 7 | SDI | Serial data input |
| 8 | LOUT- | Left channel output negative terminal |
| 9 | LOUT+ | Left channel output positive terminal |
| 10 | ROUT- | Right channel output negative terminal |
| 11 | ROUT+ | Right channel output positive terminal |
| 12-15 |Reserved | No connection |
| 16 | SHUTDOWN | Shutdown input (active low) |
| 17 | FLT | Fault output (active low) |
| 18 | VREF | Voltage reference output |
| 19 | AGND | Analog ground pin |
| 20 | DGND | Digital ground pin |
The following examples demonstrate how to use the TPA3118 PBTL Mono Digital Amplifier in various contexts.
Example 1: Basic Audio Playback with Arduino
This example demonstrates how to use the TPA3118 with an Arduino board to play a basic audio tone.
```c
#include <TPA3118.h>
#define SCK 13 // Serial clock pin
#define SDI 11 // Serial data input pin
#define SHUTDOWN 10 // Shutdown pin
TPA3118 amplifier(SCK, SDI, SHUTDOWN);
void setup() {
amplifier.begin();
}
void loop() {
amplifier.setVolume(50); // Set volume to 50%
amplifier.playTone(440, 1000); // Play a 440Hz tone for 1 second
delay(1000);
}
```
Example 2: Audio Playback with Raspberry Pi (Python)
This example demonstrates how to use the TPA3118 with a Raspberry Pi to play an audio file.
```python
import RPi.GPIO as GPIO
import pygame
# Define TPA3118 pins
SCK = 17
SDI = 23
SHUTDOWN = 24
# Initialize TPA3118
GPIO.setup(SCK, GPIO.OUT)
GPIO.setup(SDI, GPIO.OUT)
GPIO.setup(SHUTDOWN, GPIO.OUT)
# Initialize Pygame
pygame.init()
pygame.mixer.init()
# Play an audio file
pygame.mixer.music.load("audio_file.wav")
pygame.mixer.music.play()
# Set volume to 50%
GPIO.output(SCK, 1)
GPIO.output(SDI, 0x10)
GPIO.output(SHUTDOWN, 1)
# Wait for the audio file to finish playing
while pygame.mixer.music.get_busy():
pass
# Clean up
pygame.quit()
GPIO.cleanup()
```
Example 3: Audio Streaming with ESP32 (C++)
This example demonstrates how to use the TPA3118 with an ESP32 board to stream audio data from a server.
```c
#include <WiFi.h>
#include <TPA3118.h>
#define SCK 18 // Serial clock pin
#define SDI 19 // Serial data input pin
#define SHUTDOWN 23 // Shutdown pin
TPA3118 amplifier(SCK, SDI, SHUTDOWN);
WiFiClient client;
const char ssid = "your_wifi_ssid";
const char password = "your_wifi_password";
const char serverUrl = "http://example.com/audio_stream.mp3";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
void loop() {
client.setServer(serverUrl, 80);
client.connect();
// Stream audio data from the server
while (client.connected()) {
int bytesRead = client.read((char)buffer, 1024);
if (bytesRead > 0) {
amplifier.playAudio(buffer, bytesRead);
}
}
client.stop();
delay(1000);
}
```
These examples demonstrate the basic usage of the TPA3118 PBTL Mono Digital Amplifier with various microcontrollers and platforms. The TPA3118 can be used in a wide range of applications, including audio players, speakers, and soundbars.