Teensy crashes while playing audio (3.1)

Status
Not open for further replies.

nicnic

Member
Hi all.

I'm trying to play audio from the teensy 3.1. It works for a while, then erratically starts making a horrible buzzing sound, and the teensy crashes (the buzzing continues till I remove the power). Earlier in the day everything worked fine. Could the teensy have somehow blown (I don't suspect that this is the case because it will still play the audio for a few seconds before crashing)?

The teensy is driving a small amp via a 10uF cap.

This erratic buzzing has worked itself into three teensies, and I have tried two different SD cards with both FAT16 and FAT32.

Any help would be much appreciated, as I have little hair left to pull out.
 
Here's the code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>

AudioPlaySdWav     wav;
AudioOutputAnalog     dac;
AudioConnection c1(wav, 0, dac, 0);
AudioConnection c2(wav, 1, dac, 1);

const int chipSelect = 10;    

const int hydro = 3;
const int makeLib = 4;
const int projects = 5;
const int store = 6;


void setup(){
  pinMode(2, INPUT_PULLUP);
  pinMode(13,OUTPUT);
  for(int i=3;i<=6;++i){
    pinMode(i,OUTPUT);
    digitalWrite(i,HIGH);
    delay(10);
    digitalWrite(i,LOW);
  }
  AudioMemory(5);
  SPI.setMOSI(11);
  SPI.setSCK(13);
  SD.begin(10);
  
  Serial.begin(9600);
}

void loop(){
  if(digitalRead(2)==1){
    Serial.println("starting");
    wav.play("7.WAV");
    delay(6000);
    flash(hydro,7);
    flash(makeLib,12);
    flash(projects,7);
    flash(store,10);
    delay(7000);
    while(wav.isPlaying()){
      delay(1);
    }
    Serial.println("done");
  }
  
}

void flash(int pin,int times){
  for(int n=0;n<times;++n){
    digitalWrite(pin, HIGH);
    delay((times/2)*1000);
    digitalWrite(pin, LOW);
    delay((times/2)*1000);
  }
}

(I know there are some strange artifacts of past code that need not be there, such has the .isPlaying())

Thanks
 
Bug with digital pins and Audio Library?

I have noticed that use of pinMode(13,xxx) anywhere in setup() prevents the Audio library example PeakMeterStereo from working. I comment out pinMode() and digitalWrite() stuff, and it started working again. I changed to a different pin from 13 (the LED) to say, 6, and the PeakMeterStereo example works.

I can't find any reference to this issue anywhere on the forum.

Here's the PeakMeterStereo example I modified that works when the variable led is 6, and does not pass through audio from LineIn to headphones when led is 13.

Code:
/* Stereo peak meter example, assumes Audio adapter but just uses terminal so no more parts required.

This example code is in the public domain
*/

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

const int myInput = AUDIO_INPUT_LINEIN;
int led = 6;

AudioInputI2S        audioInput;         // audio shield: mic or line-in
AudioAnalyzePeak     peak_L;
AudioAnalyzePeak     peak_R;
AudioOutputI2S       audioOutput;        // audio shield: headphones & line-out

AudioConnection c1(audioInput,0,peak_L,0);
AudioConnection c2(audioInput,1,peak_R,0);
AudioConnection c3(audioInput,0,audioOutput,0);
AudioConnection c4(audioInput,1,audioOutput,1);

AudioControlSGTL5000 audioShield;


void setup() {
  AudioMemory(6);
  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(0.5);
  Serial.begin(9600);
  // Make LED pin OUTPUT causes Audio Library to fail to passthru audio when led is 13 but works when it is something else (6)
  pinMode(led, OUTPUT);   
}

// for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.

elapsedMillis fps;
uint8_t cnt=0;

void loop() {
  if(fps > 24) {
    if (peak_L.available() && peak_R.available()) {
      fps=0;
      uint8_t leftPeak=peak_L.read() * 30.0;
      uint8_t rightPeak=peak_R.read() * 30.0;

      // this block added by Backwoods_Engineer to light LED wnen audio input activity
      if ((leftPeak < 1) && (rightPeak < 1))
      {
        digitalWrite(led, LOW);
      }
      else
      {
        if ((leftPeak >= 5) || (rightPeak >= 5))
        {
          digitalWrite(led, HIGH);
        }
      }
     // end block

      for(cnt=0;cnt<30-leftPeak;cnt++) {
        Serial.print(" ");
      }
      while(cnt++<30) {
        Serial.print("<");
      }
      Serial.print("||");
      for(cnt=0;cnt<rightPeak;cnt++) {
        Serial.print(">");
      }
      while(cnt++<30) {
        Serial.print(" ");
      }
      Serial.println();
    }
  }
}
 
Last edited:
You can't use pin 13 when running the audio shield, because it needs pin 13 for incoming I2S data.

teensy3_audio_pins.png


Try using a different pin, which isn't consumed by the audio board.
 
You can't use pin 13 when running the audio shield, because it needs pin 13 for incoming I2S data.

teensy3_audio_pins.png


Try using a different pin, which isn't consumed by the audio board.

Thank you. I'm surprised an LED was put on an I2S data line, but maybe it can source enough current.

Should I pull the 470-ohm resistor and disconnect the LED when running with the audio shield? It does seem to be running now, but that's on the bench at 25 degrees C.
 
In designing Teensy 3.0, there were many conflicting requirements to get a pinout for best compatibility with Arduino sketches. One of the lessons I learned from Teensy 2.0 is how many tutorials and libraries and examples have Arduino Uno's pin assignment hard-coded.

Teensy 3.0 was designed to have many of the same signal assignments, particularly the SPI signals on pins 10-13. Only 2 pins can be SCK, and one had an analog signal, so it couldn't be pin 13, which must be digital only AND have a LED for the many Arduino sketches that assumed the LED is on pin 13.

It turned out that SCK without analog pin was the only pin able to receive I2S.

Fortunately, the SGTL5000 is easily able to drive the LED. I've verified the waveforms several times.

Hopefully most other I2S analog to digital converters will also be able to drive 3.2 mA for the LED. But if a chip without that drive capability is used, either a buffer chip will be needed, for the LED could be removed.
 
I asked in another thread w/o answer, but are any of these pins available to be used if not connected to the audioshield?

RX
MEMCS
VOL (what does this even do if volume is controllable w/o being connected?)

I am not using those pins and would like to use them for digital in/out pins/buttons.
 
I asked in another thread w/o answer, but are any of these pins available to be used if not connected to the audioshield?

RX
MEMCS
VOL (what does this even do if volume is controllable w/o being connected?)

I am not using those pins and would like to use them for digital in/out pins/buttons.

VOL -- yes. it's got nothing to do with volume per se. cf the PassThroughStereo.ino example.

Code:
if (volmsec > 50) {
…	
41	  if (volmsec > 50) {
42	    float vol = analogRead(15);
43	    vol = vol / 1023.0;

MEMCS -- ditto, it's just the chip select for the spi flash, which you probably aren't using then.

RX -- yes, if "not connected to the audioshield" implies no i2s RX signal is needed.

the pin is set in AudioInputI2S::begin(void), ie : CORE_PIN13_CONFIG = PORT_PCR_MUX(4);
 
VOL -- yes. it's got nothing to do with volume per se. cf the PassThroughStereo.ino example.

Code:
if (volmsec > 50) {
…	
41	  if (volmsec > 50) {
42	    float vol = analogRead(15);
43	    vol = vol / 1023.0;

MEMCS -- ditto, it's just the chip select for the spi flash, which you probably aren't using then.

RX -- yes, if "not connected to the audioshield" implies no i2s RX signal is needed.

the pin is set in AudioInputI2S::begin(void), ie : CORE_PIN13_CONFIG = PORT_PCR_MUX(4);

So when setting up the GUI, if you don't use the RX/mic, then the audio shield should not be using the RX pin and I can declare it later in code for general pin use correct?
 
So when setting up the GUI, if you don't use the RX/mic, then the audio shield should not be using the RX pin and I can declare it later in code for general pin use correct?

The audio shield will still drive pin 13, if you've soldered a pin or wire between the Teensy and audio shield.

If you don't put the I2S input object in your design AND if you do not solder a pin or wire between between RX and 13, then you can use pin 13 for other stuff. You must do both of these things: avoid using the I2S input object and avoid physically connecting the RX output of the audio shield.
 
Status
Not open for further replies.
Back
Top