[{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eI 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 \u003ca href=\"https://chat.openai.com/g/g-t57yKlbup-protoengineer\" target=\"_blank\"\u003eProtoEngineer\u003c/a\u003e\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003eThis 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.\u003c/span\u003e\u003c/p\u003e\n\u003ch2\u003eEquipment\u003c/h2\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003ca href=\"https://www.adafruit.com/product/5305\" target=\"_new\"\u003eQualia ESP32-S3 RGB666 board\u003c/a\u003e\u003cspan\u003e - A versatile microcontroller board based on the ESP32-S3 chip, ideal for projects requiring WiFi and Bluetooth connectivity along with powerful processing capabilities.\u003c/span\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003ca href=\"https://www.adafruit.com/product/3006\" target=\"_new\"\u003eMAX98357 I2S Class-D Mono Amplifier Breakout\u003c/a\u003e\u003cspan\u003e - An easy-to-use digital amplifier perfect for adding high-quality sound to your projects.\u003c/span\u003e\n\u003c/li\u003e\n\u003cli\u003eSpeakers compatible with the amplifier.\u003c/li\u003e\n\u003cli\u003eConnecting wires. I used \u003ca href=\"https://www.adafruit.com/product/1950\"\u003e6\" female jumper wires\u003c/a\u003e.\u003c/li\u003e\n\u003cli\u003eHeader pins for the Qualia board and the MAX98357 breakout. Go ahead and attach the headers now.\u003c/li\u003e\n\u003cli\u003ePersonal computer with CircuitPython installed.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003e::closeup of the Qualia board showing pins::\u003cbr\u003e::closeup of the MAX89357 showing pins::\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n        \u003ch2\u003eProcedure\u003c/h2\u003e\n\u003cp\u003e\u003cstrong\u003eInstall the Latest CircuitPython Build for the Qualia Board:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eInstall the latest CircuitPython build\u003c/strong\u003e\n\u003cul\u003e\n\u003cli\u003eBegin by downloading the latest CircuitPython firmware for the Qualia ESP32-S3 RGB666 board. For this project, the specific build used is referenced in the \u003ccode\u003eboot_out.txt\u003c/code\u003e as \"Adafruit CircuitPython 9.0.0-alpha.5 on 2023-11-15; Adafruit-Qualia-S3-RGB666 with ESP32S3\".\u003c/li\u003e\n\u003cli\u003eVisit the \u003ca href=\"https://circuitpython.org/board/adafruit_qualia_s3_rgb666/\" target=\"_new\"\u003eCircuitPython download page for the Qualia ESP32-S3 RGB666\u003c/a\u003e and download the appropriate \u003ccode\u003e.uf2\u003c/code\u003e file for the board.\u003c/li\u003e\n\u003cli\u003eConnect the Qualia board to your computer via USB and enter the bootloader mode.\u003c/li\u003e\n\u003cli\u003eThe board should appear as a drive on your computer (named \u003ccode\u003eTFT_S3BOOT\u003c/code\u003e). If it does not, you may need to follow the board-specific instructions to enter the bootloader mode.\u003c/li\u003e\n\u003cli\u003eDrag and drop the \u003ccode\u003e.uf2\u003c/code\u003e file onto the board's drive. This will initiate the firmware update process.\u003c/li\u003e\n\u003cli\u003eOnce the transfer is complete, the board will automatically restart with the new CircuitPython firmware installed.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eDisconnect the USB:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eSafely eject the Qualia board from your computer and then disconnect the USB cable.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eConnect the Speaker to the Breakout:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eAttach your speaker to the speaker terminals on the MAX98357 I2S Class-D Mono Amplifier Breakout.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eConnect the Breakout to the Qualia Board:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eUse the following wiring connections between the breakout and the Qualia board:\u003c/li\u003e\n\u003c/ul\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003cth\u003eBreakout Pin\u003c/th\u003e\n\u003cth\u003eWire Color\u003c/th\u003e\n\u003cth\u003eQualia Board Pin\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003eVIN\u003c/td\u003e\n\u003ctd\u003eRed\u003c/td\u003e\n\u003ctd\u003e3.3V\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eGND\u003c/td\u003e\n\u003ctd\u003eBlack\u003c/td\u003e\n\u003ctd\u003eGND\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eDIN\u003c/td\u003e\n\u003ctd\u003eBrown\u003c/td\u003e\n\u003ctd\u003eA0\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eBCLK\u003c/td\u003e\n\u003ctd\u003eOrange\u003c/td\u003e\n\u003ctd\u003eA1\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003eLRC\u003c/td\u003e\n\u003ctd\u003eYellow\u003c/td\u003e\n\u003ctd\u003eCS\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n      ","metadata":{}},{"element_type":"markdown","content":"\u003cp\u003e\u003cstrong\u003eWriting and Testing the Code:\u003c/strong\u003e\u003c/p\u003e\n\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eWrite the CircuitPython Script:\u003c/strong\u003e\u003c/p\u003e\n\n\u003cul\u003e\n\u003cli\u003eCreate a new file named \u003ccode class=\"inline\"\u003ecode.py\u003c/code\u003e on your computer.\u003c/li\u003e\n\u003cli\u003eWrite the CircuitPython code to generate and play a sine wave tone through the I2S interface. The script should include the following functionalities:\n\n\u003cul\u003e\n\u003cli\u003eGeneration of a 440 Hz sine wave.\u003c/li\u003e\n\u003cli\u003eSetup of the I2S interface using the MAX98357 amplifier and the specific pins on the Qualia board.\u003c/li\u003e\n\u003cli\u003eA loop to play the sound for 0.6 seconds, followed by a silence of 0.4 seconds, repeating indefinitely.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eUpload the Script to the Qualia Board:\u003c/strong\u003e\u003c/p\u003e\n\n\u003cul\u003e\n\u003cli\u003eReconnect the Qualia board to your computer via USB.\u003c/li\u003e\n\u003cli\u003eThe board should appear as a drive on your computer.\u003c/li\u003e\n\u003cli\u003eDrag and drop or copy the \u003ccode class=\"inline\"\u003etest_audio.py\u003c/code\u003e file onto the board's drive.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eTest the Audio Output:\u003c/strong\u003e\u003c/p\u003e\n\n\u003cul\u003e\n\u003cli\u003eOnce the script is uploaded, the Qualia board will automatically execute the \u003ccode class=\"inline\"\u003ecode.py\u003c/code\u003e script.\u003c/li\u003e\n\u003cli\u003eListen 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.\u003c/li\u003e\n\u003cli\u003eVerify that the sound is clear and the timing matches the expected pattern.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n","metadata":{"markdown":"**Writing and Testing the Code:**\n\n1. **Write the CircuitPython Script:**\n   - Create a new file named `code.py` on your computer.\n   - Write the CircuitPython code to generate and play a sine wave tone through the I2S interface. The script should include the following functionalities:\n     - Generation of a 440 Hz sine wave.\n     - Setup of the I2S interface using the MAX98357 amplifier and the specific pins on the Qualia board.\n     - A loop to play the sound for 0.6 seconds, followed by a silence of 0.4 seconds, repeating indefinitely.\n   \n2. **Upload the Script to the Qualia Board:**\n   - Reconnect the Qualia board to your computer via USB.\n   - The board should appear as a drive on your computer.\n   - Drag and drop or copy the `test_audio.py` file onto the board's drive.\n\n3. **Test the Audio Output:**\n   - Once the script is uploaded, the Qualia board will automatically execute the `code.py` script.\n   - 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.\n   - Verify that the sound is clear and the timing matches the expected pattern."}},{"element_type":"code","content":"# SPDX-FileCopyrightText: Copyright (c) 2023 Randall Bohn (dexter)\n#\n# SPDX-License-Identifier: MIT\n# Assisted by ProtoEngineer https://chat.openai.com/g/g-t57yKlbup-protoengineer\n\nimport board\nimport audiobusio\nimport time\nimport array\nimport math\nimport audiocore\n\n# Set up the sine wave parameters\nsample_rate = 8000\ntone_volume = 0.1\nfrequency = 440\nlength = sample_rate // frequency\nsine_wave = array.array(\"H\", [0] * length)\nfor i in range(length):\n    sine_wave[i] = int((math.sin(math.pi * 2 * frequency * i / sample_rate) * tone_volume + 1) * (2**15 - 1))\n\n# Initialize I2S\naudio = audiobusio.I2SOut(bit_clock=board.A1, word_select=board.CS, data=board.A0)\nsine_wave_sample = audiocore.RawSample(sine_wave, sample_rate=sample_rate)\n\nif __name__ == \"__main__\":\n    # Play the tone for 0.6 seconds and be silent for 0.4 seconds in a loop\n    while True:\n        audio.play(sine_wave_sample, loop=True)\n        time.sleep(0.6)\n        audio.stop()\n        time.sleep(0.4)","metadata":{"language":"auto","linenums":false}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n        \u003ch2\u003eResults\u003c/h2\u003e\n\u003cp\u003eUpon successful completion of the setup and script upload, the following observations were made:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eIntermittent Tone Production:\u003c/strong\u003e 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 \u003ccode\u003ecode.py\u003c/code\u003e script.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eTone Characteristics:\u003c/strong\u003e 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.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eAudio Quality:\u003c/strong\u003e 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.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eConsistency with Script Parameters:\u003c/strong\u003e 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.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003e \u003c/p\u003e\n      \n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n        \u003cp\u003e\u003cstrong\u003eTROUBLESHOOTING:\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eIn 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:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eNo Sound from Speaker:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eCheck Connections:\u003c/strong\u003e Ensure all wires are securely connected to the correct pins on both the breakout board and the Qualia board.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eVerify Speaker Functionality:\u003c/strong\u003e Test the speaker with another audio source to confirm it is working.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eDistorted or Weak Sound:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eVolume Adjustment:\u003c/strong\u003e If the sound is distorted, try lowering the \u003ccode\u003etone_volume\u003c/code\u003e in the script. If it's too weak, consider increasing the volume.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eCheck Power Supply:\u003c/strong\u003e Ensure the Qualia board is adequately powered, as insufficient power can lead to weak audio output.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eScript Not Running:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eCheck File Transfer:\u003c/strong\u003e Ensure the \u003ccode\u003etest_audio.py\u003c/code\u003e script is correctly transferred to the Qualia board.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eVerify CircuitPython Version:\u003c/strong\u003e Make sure the board is running the correct version of CircuitPython required for this project.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eIntermittent Sound Not as Expected:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eTiming Issues:\u003c/strong\u003e If the timing of the sound does not match the expected pattern (0.6 seconds on, 0.4 seconds off), recheck the \u003ccode\u003etime.sleep()\u003c/code\u003e values in the script.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eScript Errors:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003eCode Syntax:\u003c/strong\u003e Verify that the script doesn’t have syntax errors. You can use a Python editor with syntax checking for this purpose.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eIf 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: \u003ca href=\"https://adafru.it/discord\"\u003ehttps://adafru.it/discord\u003c/a\u003e\u003c/p\u003e\n      \n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n        \u003ch2\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eThe 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:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eFunctionality Confirmation:\u003c/strong\u003e 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eCircuitPython Efficiency:\u003c/strong\u003e 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eHardware Compatibility:\u003c/strong\u003e 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003ePotential Applications:\u003c/strong\u003e 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eFuture Enhancements:\u003c/strong\u003e 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eIn 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.\u003c/p\u003e\n      \n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n        \u003cp\u003eAdmittedly, ProtoEngineer wrote most of this. I was just directing things.\u003c/p\u003e\n\u003cp\u003e\u003cem\u003eSucces!\u003c/em\u003e --dexter 2023-11-18\u003c/p\u003e\n      \n\n","metadata":{}}]