FrankRuisch
Member
Hi !
I have a project of 11 audio players running in a small theme park. It is mounted in a boatride and it reads RFID data from the serial input and plays files on different locations. Everything is running fine except that the files (or SDHC card) will get corrupt after 3 weeks of usage. When the park's maintenance team replaces the files on the same SDHC, everything is fine again. (for about 3 weeks lol)
I used the read-only simplified SD library from Mr. Stoffregen and i formatted all the cards using SDFormatter before putting anything on the cards. (mac)
I also produced the sound files and it's very unlikely there's something incorrect with the encoding. I used quality Sandisk 8GB SDHC cards. I am also using a quality Meanwell 5v power supply.
I must add that every ride cycle (about 10 minutes) the units will be disconnected for 30 secs. This is because the boat will recharge the on-board battery. The environment is very humid and warm but i couldn't imagine this is why the files become corrupt.
Hopefully you can find something incorrect in my code.... (?)
I have a project of 11 audio players running in a small theme park. It is mounted in a boatride and it reads RFID data from the serial input and plays files on different locations. Everything is running fine except that the files (or SDHC card) will get corrupt after 3 weeks of usage. When the park's maintenance team replaces the files on the same SDHC, everything is fine again. (for about 3 weeks lol)
I used the read-only simplified SD library from Mr. Stoffregen and i formatted all the cards using SDFormatter before putting anything on the cards. (mac)
I also produced the sound files and it's very unlikely there's something incorrect with the encoding. I used quality Sandisk 8GB SDHC cards. I am also using a quality Meanwell 5v power supply.
I must add that every ride cycle (about 10 minutes) the units will be disconnected for 30 secs. This is because the boat will recharge the on-board battery. The environment is very humid and warm but i couldn't imagine this is why the files become corrupt.
Hopefully you can find something incorrect in my code.... (?)
Code:
#include <SD.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
// GUItool: begin automatically generated code
AudioPlaySdWav B_Player; //xy=79,257
AudioPlaySdWav A_Player; //xy=81,172
AudioEffectFade B_Fader_L; //xy=264,244
AudioEffectFade B_Fader_R; //xy=264,277
AudioEffectFade A_Fader_L; //xy=265,142
AudioEffectFade A_Fader_R; //xy=265,178
AudioMixer4 mixer_Left ; //xy=464,164
AudioMixer4 mixer_Right; //xy=468,261
AudioOutputI2S audioOutput; //xy=649,211
AudioConnection patchCord1(B_Player, 0, B_Fader_L, 0);
AudioConnection patchCord2(B_Player, 1, B_Fader_R, 0);
AudioConnection patchCord3(A_Player, 0, A_Fader_L, 0);
AudioConnection patchCord4(A_Player, 1, A_Fader_R, 0);
AudioConnection patchCord5(B_Fader_L, 0, mixer_Left, 1);
AudioConnection patchCord6(B_Fader_R, 0, mixer_Right, 1);
AudioConnection patchCord7(A_Fader_L, 0, mixer_Left, 0);
AudioConnection patchCord8(A_Fader_R, 0, mixer_Right, 0);
AudioConnection patchCord9(mixer_Left, 0, audioOutput, 0);
AudioConnection patchCord10(mixer_Right, 0, audioOutput, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=94,523
// GUItool: end automatically generated code
// Pinout for SDCARD on audio adaptor board
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
// Program variables
String inMessage ; // Holds the latest incoming serial message
int parseTimer = 30; // Timeout for WAV parsing after call
int fadeTime = 3000; // Global fade time
int cpuCurrent ; // Holds the current cpu value when 'cpu' command has been called
int cpuMax; // Holds the max cpu when 'cpu' command has been called
int memoryCurrent; // Holds the current memory value when 'mem' command has been called
int memoryMax; // Holds the max memory when 'mem' command has been called
int cpuCounter ; // used for incrementing in do-Loop (yes i know we can do this differently)
int memoryCounter ; // used for incrementing in do-Loop (yes i know we can do this differently)
int show1Cycles ; // Holds the number of shows played
int show2Cycles ; // Holds the number of shows played
int show3Cycles ; // Holds the number of shows played
int show4Cycles ; // Holds the number of shows played
int show5Cycles ; // Holds the number of shows played
int show6Cycles ; // Holds the number of shows played
int showStatus = 0; // Keeps track of the show state, so the same show isn't triggered again
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
Serial.setTimeout(50);
Serial1.setTimeout(50);
// Audio memory allocation
AudioMemory(16);
// Activate the chip and default volume settings
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
// Default mixer settings
mixer_Left.gain(0, 0.6);
mixer_Left.gain(1, 0.6);
mixer_Right.gain(0, 0.6);
mixer_Right.gain(1, 0.6);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
// Stop here, but print a message repetitively
while (1) {
Serial.println(F("Unable to access the SD card"));
delay(500);
}
}
}
void loop() {
// Read from the UART serial
if (Serial.available()) {
inMessage = Serial.readString();
Serial.print(F("USB : "));
Serial.println(inMessage);
msgEval();
}
// Read from the hardware port (RFID reader)
if (Serial1.available()) {
inMessage = Serial1.readString();
Serial.print(F("Serial : "));
Serial.println(inMessage);
msgEval();
}
}
Code:
void msgEval() {
// Player A
if (inMessage == "01\r" && showStatus != 1) {
Serial.println(F("Playing TR01"));
Serial1.println(F("Playing TR01"));
showStatus = 1;
show1Cycles++ ;
inMessage = "" ;
// Mixer settings
A_Fader_L.fadeIn(fadeTime);
A_Fader_R.fadeIn(fadeTime);
B_Fader_L.fadeOut(fadeTime);
B_Fader_R.fadeOut(fadeTime);
// Play the files
A_Player.play("1.WAV"); // Player A
delay(fadeTime + 100);
B_Player.stop(); // Player
delay(parseTimer);
}
// Player B
if (inMessage == "02\r" && showStatus != 2) {
Serial.println(F("Playing TR02"));
showStatus = 2;
show2Cycles++ ;
inMessage = "" ;
// Track 2
delay(3000);
B_Player.play("2.WAV");
delay(parseTimer);
// Mixer settings
A_Fader_L.fadeOut(fadeTime);
A_Fader_R.fadeOut(fadeTime);
B_Fader_L.fadeIn(fadeTime);
B_Fader_R.fadeIn(fadeTime);
// Stop the previous track
delay(fadeTime + 100);
A_Player.stop();
}
// Player A
if (inMessage == "03\r" && showStatus != 3) {
Serial.println(F("Playing TR03"));
delay(5000);
showStatus = 3;
show3Cycles++ ;
inMessage = "" ;
// Track 3
A_Player.play("3.WAV");
delay(parseTimer);
// Mixer settings
B_Fader_L.fadeOut(fadeTime);
B_Fader_R.fadeOut(fadeTime);
A_Fader_L.fadeIn(fadeTime);
A_Fader_R.fadeIn(fadeTime);
// Stop the previous track
delay(2000);
B_Player.stop();
}
// Player B
if (inMessage == "04\r" && showStatus != 4) {
// Play the new track
Serial.println(F("Playing TR04"));
showStatus = 4;
show4Cycles++ ;
inMessage = "" ;
// Track04
B_Player.play("4.WAV");
delay(parseTimer);
// Mixer settings
A_Fader_L.fadeOut(fadeTime);
A_Fader_R.fadeOut(fadeTime);
B_Fader_L.fadeIn(fadeTime);
B_Fader_R.fadeIn(fadeTime);
// Stop the previous track
delay(fadeTime + 100);
A_Player.stop();
}
// Player A
if (inMessage == "05\r" && showStatus != 5) {
Serial.println(F("Playing TR05"));
showStatus = 5;
show5Cycles++ ;
inMessage = "" ;
// Track 05
A_Player.play("5.WAV");
delay(parseTimer);
// Mixer settings
B_Fader_L.fadeOut(fadeTime);
B_Fader_R.fadeOut(fadeTime);
A_Fader_L.fadeIn(fadeTime);
A_Fader_R.fadeIn(fadeTime);
// Stop the previous track
delay(fadeTime + 100);
B_Player.stop();
delay(22000);
// Player B
Serial.println(F("Playing TR06"));
showStatus = 5;
show6Cycles++ ;
inMessage = "" ;
// Track06
B_Player.play("6.WAV");
delay(parseTimer);
// Mixer settings
A_Fader_L.fadeOut(fadeTime);
A_Fader_R.fadeOut(fadeTime);
B_Fader_L.fadeIn(fadeTime);
B_Fader_R.fadeIn(fadeTime);
// Stop the previous track
delay(fadeTime + 100);
A_Player.stop();
}
if (inMessage == "stop\r" && showStatus != 0) {
Serial.println(F("Stopped !"));
showStatus = 0;
A_Fader_L.fadeOut(1000);
B_Fader_L.fadeOut(1000);
A_Fader_R.fadeOut(1000);
B_Fader_R.fadeOut(1000);
delay(1100);
A_Player.stop();
B_Player.stop();
}
if (inMessage == "?\r") {
Serial.println(F("---Show Cycles---"));
Serial.print(F("Show 1 : "));
Serial.println(show1Cycles);
Serial.print(F("Show 2 : "));
Serial.println(show2Cycles);
Serial.print(F("Show 3 : "));
Serial.println(show3Cycles);
Serial.print(F("Show 4 : "));
Serial.println(show4Cycles);
Serial.print(F("Show 5 : "));
Serial.println(show5Cycles);
Serial.println(F("-----------------"));
}
if (inMessage == "clearshows\r") {
Serial.println(F("---Show Cycles---"));
show1Cycles = 0;
show2Cycles = 0;
show3Cycles = 0;
show4Cycles = 0;
show5Cycles = 0;
Serial.print(F("Show 1 : "));
Serial.println(show1Cycles);
Serial.print(F("Show 2 : "));
Serial.println(show2Cycles);
Serial.print(F("Show 3 : "));
Serial.println(show3Cycles);
Serial.print(F("Show 4 : "));
Serial.println(show4Cycles);
Serial.print(F("Show 5 : "));
Serial.println(show5Cycles);
Serial.println(F("-----------------"));
}
if (inMessage == "cpu\r") {
Serial.println(F("-----CPU test started-----"));
do {
cpuCurrent = AudioProcessorUsage();
Serial.print(F("CPU : "));
Serial.println(cpuCurrent);
cpuCounter++ ;
delay(75);
} while (cpuCounter < 100);
cpuCounter = 0;
cpuMax = AudioProcessorUsageMax();
Serial.println(F("-----CPU test complete !-----"));
Serial.println(F("-----------------------------"));
Serial.print(F("Max CPU : "));
Serial.println(cpuMax);
AudioProcessorUsageMaxReset();
}
if (inMessage == "mem\r") {
Serial.println(F("-----MEMORY test started-----"));
do {
memoryCurrent = AudioMemoryUsage();
Serial.print(F("Memory : "));
Serial.println(memoryCurrent);
memoryCounter++ ;
delay(75);
} while (memoryCounter < 100);
memoryCounter = 0;
memoryMax = AudioMemoryUsageMax();
Serial.println(F("-----MEMORY test complete !-----"));
Serial.println(F("--------------------------------"));
Serial.print(F("Max Memory : "));
Serial.println(memoryMax);
AudioMemoryUsageMaxReset();
}
}