Audio Output Without the Audio Shield, Teensy 3.5 Arduino

Status
Not open for further replies.

theperfectstraw

New member
Hi,

I've been looking for direction on how to get audio output to an amplifier without using the audio shield. From what I can tell I should be able to connect the DAC pinouts to the input of an amplifier and get some sound, but I'm looking for examples of code and circuitry.

As far as I have found, I need to add an AudioOutputAnalog dac, and have a 10uF capacitor between the pin and the amp, but I can't tell for sure if that's everything I need.

I'm running a Teensy 3.5 with Teensyduino.

Thanks for any advice you can give!
 
Perhaps the 'Audio Amplifier' section on this page will give enough detail? :: https://www.pjrc.com/store/prop_shield.html

The Prop or low cost Prop shield provides an amp that feeds from a DAC pin.

Scroll down to 'Technical Details' to see the pinout for reference - it pulls the DAC signal directly off the T_3.2 & T_LC pinout - for T_3.5 you would need to hand wire that from DAC0 or DAC1 pin and adjust accordingly. The Prop shield isn't need to do that - but it shows you how it can be done and links to sample software.
 
Last edited:
As far as I have found, I need to add an AudioOutputAnalog dac, and have a 10uF capacitor between the pin and the amp, but I can't tell for sure if that's everything I need.

Of course you need the rest of a program that actually generates some audio data. If using one that reads a SD card, you need a card with the files.

Best to start with one of the working examples and just replace the I2S output, and delete the SGTL5000 stuff.

If creating a program from scratch, the most common mistake is forgetting AudioMemory(). Even if you do everything else correctly, the audio library can't actually do anything until you give it some memory. Not an issue if you start from one of the working examples!
 
Below is the code I'm running, I'm still getting no sound. The code is running and printing the lines to the serial monitor, but I'm not getting audio.

Is there anything I'm missing in this setup? I ran my amp from my computer audio and it worked fine. I was running the audio board with 3.5mm output (which worked) but I would rather run the 3.5 directly pinned out to the amp.

I have the DAC0 and DAC1 pins running to the L and R inputs on my amp, and the grounds are connected.

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

AudioPlaySdWav playSdWav1;
AudioOutputAnalog dac;

#define SDCARD_CS_PIN BUILTIN_SDCARD

void setup() {

Serial.begin(9600);
Serial.println("Program Start");
AudioMemory(20);
delay(1000);
}

void loop() {
Serial.println("looping");
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("001test.WAV");
delay(1000); // wait for library to parse WAV info
}
// do nothing while playing...
}
 
you need to use the audio lib gui https://www.pjrc.com/teensy/gui to set up connections between components. for T3.5/3.5 DACs, use AudioOutputAnalogStereo

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

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=105,182
AudioOutputAnalogStereo  dacs1;          //xy=321,188
AudioConnection          patchCord1(playSdWav1, 0, dacs1, 0);
AudioConnection          patchCord2(playSdWav1, 1, dacs1, 1);
// GUItool: end automatically generated code

Use CODE tags (#) to retain indentation when posting code.

in setup() you also need
Code:
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
You could study the audio lib youtube and/or the audio workshop pdf,
https://www.pjrc.com/teensy/td_libs_Audio.html
https://www.pjrc.com/store/audio_tutorial_kit.html

Here's a working sketch. I changed the WAV file and got rid of the "flooding" Serial.println() in loop
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=105,182
AudioOutputAnalogStereo  dacs1;          //xy=321,188
AudioConnection          patchCord1(playSdWav1, 0, dacs1, 0);
AudioConnection          patchCord2(playSdWav1, 1, dacs1, 1);
// GUItool: end automatically generated code

#define SDCARD_CS_PIN BUILTIN_SDCARD

void setup() {

  Serial.begin(9600);
  Serial.println("Program Start");
  AudioMemory(20);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
}

void loop() {
 // Serial.println("looping");
  if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing");
    playSdWav1.play("TOPGUN.WAV");
    delay(1000); // wait for library to parse WAV info
  }
  // do nothing while playing...
}
 
Last edited:
I've determined that the problem is reading the WAV file on the SD card. The teensy is reading the SD, but it's not playing the file with the command. Is there a proper file format and/or naming format for WAV files in the audio codec? Are there parameters in the WAV file that might not be supported?
 
In addition to requiring 44.1 kHz 16 bit PCM format (either mono or stereo is ok), there's a known limitation where the "fmt " section must immediately follow the RIFF header. Almost all programs create WAV files this way, but there are some exceptions. Pro Tools is known to add a "JUNK" section. Details here:

https://forum.pjrc.com/threads/5053...ge-in-terminal?p=172945&viewfull=1#post172945

One simple workaround (if your files have the JUNK section at offset 12) involves opening your files in Audacity and then saving them as new WAV files.
 
In addition to requiring 44.1 kHz 16 bit PCM format (either mono or stereo is ok), there's a known limitation where the "fmt " section must immediately follow the RIFF header. Pro Tools is known to add a "JUNK" section.

Opening your files in Audacity and then saving them as new WAV files.

My files were running 48 kHz. Changing them to 44.1 kHz in Audacity worked with the code Manitou posted.

Thanks!
 
Status
Not open for further replies.
Back
Top