meesterstump
New member
Hello there,
I am using Teensy Audio Adaptor stacked on Teensy 3.2. Wav files are played with an Sandisk Ultra SD card. Twelve of these units have been playing for several days in a public space mostly without issue.
There have been two times now when one of these units crashed. The crash is accompanied by an extremely loud, ear-piercing buzzing that persists until the teensy is rebooted.
The only way I've been able to reproduce that crash is by yanking out the sd card during operation. What kind of safeguards in code or library modifications could I be making to try to avoid this issue? What might the cause be? Perhaps the SD card intermittently fails to be read correctly?
Any help is appreciated, thanks!
I am using Teensy Audio Adaptor stacked on Teensy 3.2. Wav files are played with an Sandisk Ultra SD card. Twelve of these units have been playing for several days in a public space mostly without issue.
There have been two times now when one of these units crashed. The crash is accompanied by an extremely loud, ear-piercing buzzing that persists until the teensy is rebooted.
The only way I've been able to reproduce that crash is by yanking out the sd card during operation. What kind of safeguards in code or library modifications could I be making to try to avoid this issue? What might the cause be? Perhaps the SD card intermittently fails to be read correctly?
Any help is appreciated, thanks!
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
#define SENSOR_PIN 1
#define LED_PIN 13
AudioPlaySdWav s1;
AudioPlaySdWav s2;
AudioPlaySdWav s3;
AudioMixer4 mix;
AudioOutputI2S headphones;
AudioConnection patchCord1(s1, 0, mix, 0);
AudioConnection patchCord2(s2, 0, mix, 1);
AudioConnection patchCord3(s3, 0, mix, 2);
AudioConnection patchCord4(mix, 0, headphones, 0);
AudioConnection patchCord5(mix, 0, headphones, 1);
AudioControlSGTL5000 audioShield;
int NUM_SOUNDS = 5;
int NUM_VARIANTS = 3;
byte lastVariant = 0;
unsigned int RETRIGGER_DURATION = 3000;
elapsedMillis lastActive;
void setup() {
Serial.begin(9600);
AudioMemory(10);
audioShield.enable();
audioShield.volume(0.5);
audioShield.autoVolumeEnable();
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);
}
}
pinMode(LED_PIN, OUTPUT);
pinMode(SENSOR_PIN, INPUT_PULLUP);
randomSeed(analogRead(0));
delay(1000);
}
void loop() {
// LED indicates active sound playing
if (random(5) == 1 ) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
if (lastActive > RETRIGGER_DURATION && digitalRead(SENSOR_PIN) == LOW) {
playSound();
lastActive = 0;
}
}
void playSound() {
char filename[] = "SOUND0_0.WAV"; // file name template
byte toneId = random(NUM_SOUNDS) + 48 + 1; // adding 48 for ascii conversion
byte variantId;
do {
variantId = random(NUM_VARIANTS) + 48 + 1; // adding 48 for ascii conversion
} while (variantId == lastVariant);
lastVariant = variantId;
filename[5] = toneId;
filename[7] = variantId;
Serial.print("Playing ");
Serial.print(filename);
if (!s1.isPlaying()) {
s1.play(filename);
Serial.println(" on 1");
} else if (!s2.isPlaying()) {
s2.play(filename);
Serial.println(" on 2");
} else if (!s3.isPlaying()) {
s3.play(filename);
Serial.println(" on 3");
} else {
Serial.println(" NOT");
}
delay(10); // wait for library to parse WAV info
}