Trouble With Getting DAC to Work

aminafoxdye

New member
Howdy all,

I'm just getting started with using the audio library for the Teensy 3.2 and am having some issues getting the DAC to work. I'm trying to produce a simple 440Hz sine wave using the DAC, but can't seem to get it to output.

Here is the code below:

Code:
#include <Audio.h>

AudioSynthWaveformSine   sine;
AudioAmplifier           amp;
AudioOutputAnalog        dac;
AudioConnection          patchCord1(sine, amp);
AudioConnection          patchCord2(amp, dac);

void setup(){
  dac.analogReference(EXTERNAL);

  amp.gain(1.0);

  sine.frequency(440.0);
  sine.amplitude(1.0);
  sine.phase(0.0);
};

void loop(){};

Is there something basic that I'm missing? I've looked at a few example and demo videos- however I've yet to see one that uses the DAC, specifically, and not an I2S bus with a separate audio board.

Any suggestions or input is very much appreciated!

Thanks,
Amina
 
Thanks for the post! I was having trouble with the 'Part_1_02_Hardware_Test' project and couldn't see anything on the DAC pin. I copy/pasted your code to a new project, added the 'AudioMemory(10);' line from the 'Part_1_02_Hardware_Test', and voila! A nice 440Hz sinewave on my O'scope.

For anyone else who comes across this post, here is the complete - working - .INO file:

Code:
/*
    Name:       DAC_SineWave.ino
    Created:    3/12/2024 8:31:37 PM
    Author:     FRANKNEWXPS15\Frank
*/
#include <Audio.h>

AudioSynthWaveformSine   sine;
AudioAmplifier           amp;
AudioOutputAnalog        dac;
AudioConnection          patchCord1(sine, amp);
AudioConnection          patchCord2(amp, dac);

void setup() {
  dac.analogReference(EXTERNAL);
  AudioMemory(10);

  amp.gain(1.0);

  sine.frequency(440.0);
  sine.amplitude(1.0);
  sine.phase(0.0);
};

void loop() {};
 
Back
Top