No audio from TRS with Teensy 3.2 & Audio Shield after reseating mini usb cable

Status
Not open for further replies.
Hey, not sure what's going on here, I have a 3.2 with soldered audio shield on a breadboard. My code works, but if I am to unplug the USB cable and plug it back in, audio stops working. I can tell the code is still working because the LED lights when I press the button, but no sound. The workaround I've found is to load the Audio > Synthesis > Waveforms example sketch which will cause a "pop" and the audio comes back, then I am able to load my own project back in and it works. Pretty strange!

Seems like possibly not code-related but I'll include it anyway. It just triggers an FM synth drum and lights the LED from a button press.
Code:
//LIBRARIES
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>

// GUItool: begin automatically generated code
AudioSynthWaveform       FMwaveform1;      //xy=77,500
AudioSynthWaveformSine   FMsine2;          //xy=78,374
AudioSynthWaveformSine   FMsine1;          //xy=92,320
AudioSynthWaveformModulated FMwaveformMod1;   //xy=91.5,550
AudioMixer4              mixer_FM;         //xy=235,432
AudioSynthWaveformSineModulated sine_fm1;       //xy=372,433
AudioEffectEnvelope      FM1envelope;      //xy=628,430
AudioMixer4              mixer_R;        //xy=775,483
AudioMixer4              mixer_L;        //xy=777,368
AudioOutputI2S           aux_out;        //xy=897,400
AudioConnection          patchCord1(FMwaveform1, 0, mixer_FM, 2);
AudioConnection          patchCord2(FMsine2, 0, mixer_FM, 1);
AudioConnection          patchCord3(FMsine1, 0, mixer_FM, 0);
AudioConnection          patchCord4(FMwaveformMod1, 0, mixer_FM, 3);
AudioConnection          patchCord5(mixer_FM, sine_fm1);
AudioConnection          patchCord6(sine_fm1, FM1envelope);
AudioConnection          patchCord7(FM1envelope, 0, mixer_L, 3);
AudioConnection          patchCord8(FM1envelope, 0, mixer_R, 0);
AudioConnection          patchCord9(mixer_R, 0, aux_out, 1);
AudioConnection          patchCord10(mixer_L, 0, aux_out, 0);
// GUItool: end automatically generated code

const int led = 13;
const int bdelay = 15; // (orig 10-15) bounce delayy
Bounce butt = Bounce(0, bdelay); //ARCADE BUTTON

void setup() {
  pinMode(led, OUTPUT);
  pinMode(0, INPUT_PULLUP); //ARCADE BUTTON

  Serial.begin(115200);
  
  // audio library init
  AudioMemory(15);

  AudioNoInterrupts();

	FMsine1.frequency(.5);
	FMsine1.amplitude(.1);

	FMsine2.frequency(800);
	FMsine2.amplitude(0.3);

  FMwaveform1.begin(0.3, 240, WAVEFORM_SAWTOOTH);

  //FMwaveformMod1.begin(0.3, 5, WAVEFORM_SINE);
  //FMwaveformMod1.frequencyModulation(12);

	sine_fm1.frequency(80);
	sine_fm1.amplitude(1);

  FM1envelope.attack(1);
  FM1envelope.hold(0);
  FM1envelope.decay(500);
  FM1envelope.sustain(0.0);
  FM1envelope.release(500);
  FM1envelope.releaseNoteOn(5);

  AudioInterrupts();
}

void loop() {

   butt.update();
   if (butt.fallingEdge()){
     digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
     FMsine1.phase(90);
     FM1envelope.noteOn();
   }
   if (butt.risingEdge()){
     digitalWrite(led, LOW);   // turn the LED off (LOW is the voltage level)
     FM1envelope.noteOff();
   }

}
 
So I've went and got a Teensy 3.6 and whole new audio board, just soldered them together and ran the code, exact same problem. Loading my code the first time I plugged it in I could light the LED but no sound. Loaded Waveforms example, heard a "pop" and then sound. Then re-loaded my code which then produced sound. BUT if USB cable gets disconnected then it's back to square 1 and I have to load in Waveforms for it to work again. Tried a couple different usb cables and ports. Any ideas at all?
 
Alright well as soon as I post a second time and having eliminated it being any sort of hardware problem by using a whole new set of boards, of course I managed to figure it out mere moments later. Posting my solution in case anyone might be googling for an answer in the future. Started pasting bits of code from the Waveforms example to see if any element I was not using in my code would fix it and looks like I didn't include the sgtl5000 control object which allows the Teensy to control the sgtl5000 chip on the audio shield. D'oh. I suppose that would explain why it would still be enabled even after loading a new bit of code and would stop acting as slave once power was disconnected. Live and learn!

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

// GUItool: begin automatically generated code
AudioSynthWaveformSine   FMsine2;          //xy=78,374
AudioSynthWaveform       FMwaveform1;      //xy=80,500
AudioSynthWaveformSine   FMsine1;          //xy=92,320
AudioSynthWaveformModulated FMwaveformMod1;   //xy=91.5,550
AudioMixer4              mixer_FM;         //xy=235,432
AudioSynthWaveformSineModulated sine_fm1;       //xy=372,433
AudioEffectEnvelope      FM1envelope;      //xy=628,430
AudioMixer4              mixer_R;        //xy=775,483
AudioMixer4              mixer_L;        //xy=777,368
AudioOutputI2S           aux_out;        //xy=897,400
AudioConnection          patchCord1(FMsine2, 0, mixer_FM, 1);
AudioConnection          patchCord2(FMwaveform1, 0, mixer_FM, 2);
AudioConnection          patchCord3(FMsine1, 0, mixer_FM, 0);
AudioConnection          patchCord4(FMwaveformMod1, 0, mixer_FM, 3);
AudioConnection          patchCord5(mixer_FM, sine_fm1);
AudioConnection          patchCord6(sine_fm1, FM1envelope);
AudioConnection          patchCord7(FM1envelope, 0, mixer_L, 3);
AudioConnection          patchCord8(FM1envelope, 0, mixer_R, 0);
AudioConnection          patchCord9(mixer_R, 0, aux_out, 1);
AudioConnection          patchCord10(mixer_L, 0, aux_out, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=461,269
// GUItool: end automatically generated code

const int led = 13;
const int bdelay = 15; // (orig 10-15) bounce delayy
Bounce butt = Bounce(0, bdelay); //ARCADE BUTTON

void setup() {
  pinMode(led, OUTPUT);
  pinMode(0, INPUT_PULLUP); //ARCADE BUTTON

  Serial.begin(115200);
  
  // audio library init
  AudioMemory(15);
  
  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.8); // caution: very loud - use oscilloscope only!

  AudioNoInterrupts();

	FMsine1.frequency(.5);
	FMsine1.amplitude(.1);

	FMsine2.frequency(800);
	FMsine2.amplitude(0.3);

  FMwaveform1.begin(0.3, 240, WAVEFORM_SAWTOOTH);

  //FMwaveformMod1.begin(0.3, 5, WAVEFORM_SINE);
  //FMwaveformMod1.frequencyModulation(12);

	sine_fm1.frequency(80);
	sine_fm1.amplitude(1);

  FM1envelope.attack(1);
  FM1envelope.hold(0);
  FM1envelope.decay(500);
  FM1envelope.sustain(0.0);
  FM1envelope.release(500);
  FM1envelope.releaseNoteOn(5);

  AudioInterrupts();
}

void loop() {

   butt.update();
   if (butt.fallingEdge()){
     digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
     FMsine1.phase(90);
     FM1envelope.noteOn();
   }
   if (butt.risingEdge()){
     digitalWrite(led, LOW);   // turn the LED off (LOW is the voltage level)
     FM1envelope.noteOff();
   }

}
 
Status
Not open for further replies.
Back
Top