An advanced Arduino-compatible library for configuring and controlling the NAU8325 Class-D audio amplifier over I2C—featuring dynamic MCLK configuration, ESP32 compatibility, and full support for audio path management and clock tree logic.
The PCBCUPID NAU8325 library offers a robust interface to the NAU8325 Codec With Stereo Class-D amplifier. It provides:
- Automatic MCLK configuration
- Oversampling selection
- Volume control
- Automatic Level Control (ALC)
- Abstraction of low-level register management
Tailored for ESP32(tested - GLYPHC3, GLYPHH2 & GLYPHC6), and other Arduino-compatible microcontrollers (not tested), this library simplifies the integration of high-performance audio output into your embedded projects.
- Automatic MCLK-to-FS ratio matching
- Validates MCLK frequency range
- Dynamically selects N1, N2, N3 clock divider/multiplier
- Configurable DAC oversampling (OSR 32–256)
- Full support for ESP32 both RISC-V & ARM
- Uses
TwoWireinterface with custom I2C instance support - Multiple
begin()overloads for flexible setup
- Independent left/right volume control
- Automatic Level Control (ALC) with programmable timing
- VMID bias and Class-D power management
- Soft mute/unmute functionality
Supported ICs:
- NAU8325 Codec With Stereo Class-D Audio Amplifier
Compatible Platforms:
- ESP32 (all variants)
- Arduino compatible microcontroller with I2S & I2C interface
bool begin(uint32_t fs, uint8_t bits_per_sample, uint16_t ratio);
bool begin(uint32_t fs, uint8_t bits_per_sample); // Default ratio = 256
bool begin(); // Defaults to 44100 Hz, 16-bit, ratio = 256
void setVolume(uint8_t left, uint8_t right);
void softMute(bool enable);
void powerOn(); // Enable DACs and analog path
void powerOff(); // Soft mute and disable analog blocks
void setOversampling(OversamplingMode mode); // OSR_64, OSR_128, etc.
void setPowerUpDefault(bool enable); // Enables analog default on boot
void resetChip(); // Hardware reset
uint16_t readDeviceId(); // Returns 0x21F2 if successful
| Sample Rate | Supported MCLK Frequencies (Hz) | Default Ratio |
|---|---|---|
| 8000 Hz | 2048000, 3200000, 4000000 | 256 |
| 16000 Hz | 4096000, 6400000, 8000000 | 256 |
| 44100 Hz | 11289600, 17640000, 22050000 | 256 |
| 48000 Hz | 12288000, 19200000, 24000000 | 256 |
| 96000 Hz | 24576000, 38400000, 48000000 | 256 |
All necessary divider/multiplier (N1, N2, N3) selections are handled internally.
Included examples demonstrate:
- Simple I2S configuration & Audio Generation
- I2S configuration + MP3 Decoder + SD card integration
Examples are located in the
examples/directory of the library.
- NAU8325 Datasheet: Nuvoton NAU8325
- Arduino AudioTools: AudioTools Library
- Community Support: PCBCUPID Forum
This library was developed and maintained by PCBCUPID, based on the NAU8325 codec specifications and the I2C protocol defined by Nuvoton Technology Corporation. We gratefully acknowledge the open-source community for foundational research and NAU8325 references.
Original Author:
- Karthik Elumalai – @PCBCUPID
- Version: 1.0.0
- License: MIT License (refer to the LICENSE file for terms)
We welcome contributions and feedback from the community. You can:
- Report issues or suggest improvements
- Submit pull requests with enhancements or fixes
- Share example projects using this library
Please refer to the Contributing Guidelines before submitting changes.
This library is licensed under the MIT License. See the LICENSE file for full details.
Made with 🎵 by PCBCUPID