I heard that you can do I2S audio with the Qualia RGB666 board, but I didn't find any instructions. Well, now you won't have the same problem. Let's get this thing beeping! This is a Dexter Starboard project, with assistance from ProtoEngineer
Description
This project explores the implementation of digital audio output using the MAX98357 I2S Class-D Mono Amplifier in conjunction with the Qualia ESP32-S3 RGB666 board. The goal is to produce a sine wave tone through a speaker connected to the amplifier.
Equipment
- Qualia ESP32-S3 RGB666 board - A versatile microcontroller board based on the ESP32-S3 chip, ideal for projects requiring WiFi and Bluetooth connectivity along with powerful processing capabilities.
- MAX98357 I2S Class-D Mono Amplifier Breakout - An easy-to-use digital amplifier perfect for adding high-quality sound to your projects.
- Speakers compatible with the amplifier.
- Connecting wires. I used 6" female jumper wires.
- Header pins for the Qualia board and the MAX98357 breakout. Go ahead and attach the headers now.
- Personal computer with CircuitPython installed.
::closeup of the Qualia board showing pins::
::closeup of the MAX89357 showing pins::
Procedure
Install the Latest CircuitPython Build for the Qualia Board:
-
Install the latest CircuitPython build
- Begin by downloading the latest CircuitPython firmware for the Qualia ESP32-S3 RGB666 board. For this project, the specific build used is referenced in the
boot_out.txt
as "Adafruit CircuitPython 9.0.0-alpha.5 on 2023-11-15; Adafruit-Qualia-S3-RGB666 with ESP32S3". - Visit the CircuitPython download page for the Qualia ESP32-S3 RGB666 and download the appropriate
.uf2
file for the board. - Connect the Qualia board to your computer via USB and enter the bootloader mode.
- The board should appear as a drive on your computer (named
TFT_S3BOOT
). If it does not, you may need to follow the board-specific instructions to enter the bootloader mode. - Drag and drop the
.uf2
file onto the board's drive. This will initiate the firmware update process. - Once the transfer is complete, the board will automatically restart with the new CircuitPython firmware installed.
- Begin by downloading the latest CircuitPython firmware for the Qualia ESP32-S3 RGB666 board. For this project, the specific build used is referenced in the
-
Disconnect the USB:
- Safely eject the Qualia board from your computer and then disconnect the USB cable.
-
Connect the Speaker to the Breakout:
- Attach your speaker to the speaker terminals on the MAX98357 I2S Class-D Mono Amplifier Breakout.
-
Connect the Breakout to the Qualia Board:
- Use the following wiring connections between the breakout and the Qualia board:
Breakout Pin Wire Color Qualia Board Pin VIN Red 3.3V GND Black GND DIN Brown A0 BCLK Orange A1 LRC Yellow CS
Writing and Testing the Code:
-
Write the CircuitPython Script:
- Create a new file named
code.py
on your computer. - Write the CircuitPython code to generate and play a sine wave tone through the I2S interface. The script should include the following functionalities:
- Generation of a 440 Hz sine wave.
- Setup of the I2S interface using the MAX98357 amplifier and the specific pins on the Qualia board.
- A loop to play the sound for 0.6 seconds, followed by a silence of 0.4 seconds, repeating indefinitely.
- Create a new file named
-
Upload the Script to the Qualia Board:
- Reconnect the Qualia board to your computer via USB.
- The board should appear as a drive on your computer.
- Drag and drop or copy the
test_audio.py
file onto the board's drive.
-
Test the Audio Output:
- Once the script is uploaded, the Qualia board will automatically execute the
code.py
script. - Listen for the tone played through the speaker. It should play for 0.6 seconds and then be silent for 0.4 seconds, repeating this pattern.
- Verify that the sound is clear and the timing matches the expected pattern.
- Once the script is uploaded, the Qualia board will automatically execute the
# SPDX-FileCopyrightText: Copyright (c) 2023 Randall Bohn (dexter) # # SPDX-License-Identifier: MIT # Assisted by ProtoEngineer https://chat.openai.com/g/g-t57yKlbup-protoengineer import board import audiobusio import time import array import math import audiocore # Set up the sine wave parameters sample_rate = 8000 tone_volume = 0.1 frequency = 440 length = sample_rate // frequency sine_wave = array.array("H", [0] * length) for i in range(length): sine_wave[i] = int((math.sin(math.pi * 2 * frequency * i / sample_rate) * tone_volume + 1) * (2**15 - 1)) # Initialize I2S audio = audiobusio.I2SOut(bit_clock=board.A1, word_select=board.CS, data=board.A0) sine_wave_sample = audiocore.RawSample(sine_wave, sample_rate=sample_rate) if __name__ == "__main__": # Play the tone for 0.6 seconds and be silent for 0.4 seconds in a loop while True: audio.play(sine_wave_sample, loop=True) time.sleep(0.6) audio.stop() time.sleep(0.4)
Results
Upon successful completion of the setup and script upload, the following observations were made:
-
Intermittent Tone Production: Once the software was loaded onto the Qualia board, the speaker connected to the MAX98357 I2S Class-D Mono Amplifier began producing an intermittent tone. This tone was consistent with the specifications set in the
code.py
script. - Tone Characteristics: The tone generated was a 440 Hz sine wave, played for 0.6 seconds followed by a silence of 0.4 seconds. This pattern repeated indefinitely, as dictated by the loop in the script.
- Audio Quality: The sound emitted from the speaker was clear, indicating that the digital-to-analog conversion and amplification processes were functioning correctly. It was a little quieter than expected.
- Consistency with Script Parameters: The duration of the tone and the silent intervals matched the timing specified in the script, demonstrating that the timing functions in the CircuitPython code were effective.
TROUBLESHOOTING:
In the process of setting up and testing the audio output with the Qualia board and the MAX98357 amplifier, you may encounter some issues. Here are common problems and their potential solutions:
-
No Sound from Speaker:
- Check Connections: Ensure all wires are securely connected to the correct pins on both the breakout board and the Qualia board.
- Verify Speaker Functionality: Test the speaker with another audio source to confirm it is working.
-
Distorted or Weak Sound:
-
Volume Adjustment: If the sound is distorted, try lowering the
tone_volume
in the script. If it's too weak, consider increasing the volume. - Check Power Supply: Ensure the Qualia board is adequately powered, as insufficient power can lead to weak audio output.
-
Volume Adjustment: If the sound is distorted, try lowering the
-
Script Not Running:
-
Check File Transfer: Ensure the
test_audio.py
script is correctly transferred to the Qualia board. - Verify CircuitPython Version: Make sure the board is running the correct version of CircuitPython required for this project.
-
Check File Transfer: Ensure the
-
Intermittent Sound Not as Expected:
-
Timing Issues: If the timing of the sound does not match the expected pattern (0.6 seconds on, 0.4 seconds off), recheck the
time.sleep()
values in the script.
-
Timing Issues: If the timing of the sound does not match the expected pattern (0.6 seconds on, 0.4 seconds off), recheck the
-
Script Errors:
- Code Syntax: Verify that the script doesn’t have syntax errors. You can use a Python editor with syntax checking for this purpose.
If problems persist after following these troubleshooting steps, consider seeking assistance from online forums or the community surrounding CircuitPython and Adafruit products. You can join the Adafruit community on discord: https://adafru.it/discord
Conclusion
The project successfully demonstrated the capability of the Qualia ESP32-S3 RGB666 board to produce digital audio output using the MAX98357 I2S Class-D Mono Amplifier. Key conclusions drawn from this project are:
-
Functionality Confirmation: The Qualia board, combined with the MAX98357 amplifier, effectively generated and amplified a digital audio signal, which was clearly audible through the connected speaker. This confirms the board's suitability for audio-related projects.
-
CircuitPython Efficiency: CircuitPython proved to be an efficient and user-friendly platform for developing and testing digital audio applications. The ability to quickly write, modify, and test code significantly streamlined the development process.
-
Hardware Compatibility: The wiring and configuration of the Qualia board with the MAX98357 breakout were straightforward. The board's compatibility with standard audio components like the MAX98357 amplifier opens up a wide range of possibilities for audio-based applications.
-
Potential Applications: This setup has numerous applications, such as in creating musical instruments, interactive sound installations, audio alert systems, or educational tools for teaching digital signal processing and sound synthesis.
-
Future Enhancements: Future enhancements could include exploring more complex sound generation techniques, integrating multiple sound channels, or interfacing with other sensors and input devices to create interactive audio experiences.
In conclusion, the project not only achieved its goal of producing sound through a speaker using the Qualia ESP32-S3 RGB666 board and the MAX98357 amplifier but also highlighted the potential of CircuitPython and these hardware components in the realm of digital audio processing and output.
Admittedly, ProtoEngineer wrote most of this. I was just directing things.
Succes! --dexter 2023-11-18