Teensy 4.1 with Adafruit MAX98357A I2S board

Hi,

I am working on a project that uses the Adafruit MAX98357A to play wav files but am not having good luck.

I believe this should be possible as I have a friend who uses "import" versions of the MAX98357A in his products.

The code I am using is :

Code:
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; // xy=301,144
AudioOutputI2S2 i2s2_1;    // xy=478,131
AudioConnection patchCord1(playSdWav1, 0, i2s2_1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s2_1, 1);
// GUItool: end automatically generated code


// in setup for testing
playSdWav1.play("IGNO.WAV");

I'm using I2S2 as it will make routing a PCB later easier, but I have tried I2S1 as well.

I am sure this is a me issue, but I can't find it.

Tried so far:
  • Validated audio board is getting +5v.
  • Checked the connections multiple times, both on I2S 1 and 2.
  • Tried using a "String" synth note to eliminate the WAV is in the wrong format.
  • Checked the speaker isn't damaged, it measures 4R across the leads which is correct.
  • Checked the speaker is actually connected to the header as I am using ferules, again 4R.
  • Using 8.3 file names for WAVs.

Is there a missing control object I need for this board? It's just the max and a handful of caps and resistors, I don't think it would require one.

Is there a simple way to try work out if it's the teensy or the max? Maybe MQS and look at it with a scope?

Pictures of the setup, click for bigger

Vague setup pictures, the I2S2 is hooked up at pins 2-4 front left.



The other end at the breakout board. Post-it is there to stop the speaker shorting on a jumper for the power rails under it.

 
Can you show the connections to the breakout clearly - the second image doesn't have all the connections you claim to have.

Where is your call to AudioMemory? You've ignored the forum rule - its there for a very good reason.
 
Can you show the connections to the breakout clearly - the second image doesn't have all the connections you claim to have.

Where is your call to AudioMemory? You've ignored the forum rule - its there for a very good reason.

It was a RTFM failure on my end. The mention of the missing AudioMemoryCall() made me start again.

I had indeed not included all of the audio setup. I was working from the Audio Design tool, not the tutorial sketches which was a mistake. Sorry for wasting anyone's time.

For anyone who lands here this is working code:


Code:
#include <avdweb_Switch.h>
#include <elapsedMillis.h>

#include "Config.h"
#include "Pins.h"
#include "F11D_Lights.hpp"

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; // xy=301,144
AudioOutputI2S2 i2s2_1;    // xy=478,131
AudioConnection patchCord1(playSdWav1, 0, i2s2_1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s2_1, 1);
// GUItool: end automatically generated code
// https://www.pjrc.com/teensy/gui/

#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13  // not actually used

Switch trigger1(trigger1Pin);
Switch trigger2(trigger2Pin, INPUT_PULLUP, LOW, 50, 3000, 250, 10); // Defaults + 3 second long press
Switch trigger3(trigger3Pin);

F11D_Lights lights(neopixelCount, neopixelPin, ledFrontRedPin, ledFrontGreenPin, ledFrontBluePin, ledTorchPin);

void setup()
{
    Serial.begin(115200);
    Serial.println("Starting");
    lights.begin();

    AudioMemory(10); // A starting point see MemoryAndCPuUsage.ino example to work out what is needed.

    // Initialise the SD card
    SPI.setMOSI(SDCARD_MOSI_PIN);
    SPI.setSCK(SDCARD_SCK_PIN);
    if (!(SD.begin(SDCARD_CS_PIN)))
    {
        while (1)
        {
            Serial.println("Unable to access the SD card");
            delay(500);
        }
    }

    Serial.println("SD Access");
    playSdWav1.play("IGNO.WAV");
}

void loop()
{
    buttonsLoop();

    if (trigger1.pushed())
    {
        Serial.println("Button 1 Pressed");
        fire();
    }

    if (trigger2.pushed())
    {
        Serial.println("Button 2 Pressed");
        startDisco();
    }

    if (trigger3.on())
    {
        lights.torchOn();
    }
    else
    {
        lights.torchOff();
    }

    lights.loop();
}

void buttonsLoop()
{
    trigger1.poll();
    trigger2.poll();
    trigger3.poll();
}

void startDisco()
{
    playSdWav1.play("CANTINA.WAV");
    lights.startDiscoMode();
}

void fire()
{
    playSdWav1.play("FOBLAST.WAV");
    lights.startBlast();
}
 
It was a RTFM failure on my end. The mention of the missing AudioMemoryCall() made me start again.

I had indeed not included all of the audio setup. I was working from the Audio Design tool, not the tutorial sketches which was a mistake. Sorry for wasting anyone's time.

For anyone who lands here this is working code:


Code:
#include <avdweb_Switch.h>
#include <elapsedMillis.h>

#include "Config.h"
#include "Pins.h"
#include "F11D_Lights.hpp"

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; // xy=301,144
AudioOutputI2S2 i2s2_1;    // xy=478,131
AudioConnection patchCord1(playSdWav1, 0, i2s2_1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s2_1, 1);
// GUItool: end automatically generated code
// https://www.pjrc.com/teensy/gui/

#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13  // not actually used

Switch trigger1(trigger1Pin);
Switch trigger2(trigger2Pin, INPUT_PULLUP, LOW, 50, 3000, 250, 10); // Defaults + 3 second long press
Switch trigger3(trigger3Pin);

F11D_Lights lights(neopixelCount, neopixelPin, ledFrontRedPin, ledFrontGreenPin, ledFrontBluePin, ledTorchPin);

void setup()
{
    Serial.begin(115200);
    Serial.println("Starting");
    lights.begin();

    AudioMemory(10); // A starting point see MemoryAndCPuUsage.ino example to work out what is needed.

    // Initialise the SD card
    SPI.setMOSI(SDCARD_MOSI_PIN);
    SPI.setSCK(SDCARD_SCK_PIN);
    if (!(SD.begin(SDCARD_CS_PIN)))
    {
        while (1)
        {
            Serial.println("Unable to access the SD card");
            delay(500);
        }
    }

    Serial.println("SD Access");
    playSdWav1.play("IGNO.WAV");
}

void loop()
{
    buttonsLoop();

    if (trigger1.pushed())
    {
        Serial.println("Button 1 Pressed");
        fire();
    }

    if (trigger2.pushed())
    {
        Serial.println("Button 2 Pressed");
        startDisco();
    }

    if (trigger3.on())
    {
        lights.torchOn();
    }
    else
    {
        lights.torchOff();
    }

    lights.loop();
}

void buttonsLoop()
{
    trigger1.poll();
    trigger2.poll();
    trigger3.poll();
}

void startDisco()
{
    playSdWav1.play("CANTINA.WAV");
    lights.startDiscoMode();
}

void fire()
{
    playSdWav1.play("FOBLAST.WAV");
    lights.startBlast();
}
I appreciate that you posted the working code. Good sport!
 
Back
Top