0

Music Maker Shield Intermittent Failure
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Music Maker Shield Intermittent Failure

by HaakeSack on Thu Sep 10, 2020 9:19 pm

Hi All,

I need some help on a music maker shield project. I have intermittent failures of the player and I can't seem to find the source of the bug.

The project is a jet pack prop with sounds, lights, air, and a faux fan. I'm using a Mega, 36 neopixels, and the Music Maker Shield in interrupt mode among other support hardware.
The intended operation is:
Button press > Fade in [Startup Sound play, fan ramps up, neopixels on] > Idle [Startup sound continues, fan to continuous speed, Neopixels flicker, air on] > Fade out [Shutdown sound plays, fan ramps down, neopixels fade out, air off]

Everything is working perfectly except that there is intermittent sound failures. Sometimes the sound fails and on the next button press comes back with a little ~100ms blip of the last audio file. Sometimes the sound doesn't return. I switched to a Mega to eliminate any potential memory issues, am currently using a wall wart to rule out current draw problems.

Thanks for looking,
Tom

Code: Select all | TOGGLE FULL SIZE
//neopixel library
#include <Adafruit_NeoPixel.h>

// audio shield header
#include <SPI.h>

// audio shield chip
#include <Adafruit_VS1053.h>

// SD card library
#include <SD.h>

// define the pins used
#define CLK 13       // SPI Clock, shared with SD card
#define MISO 12      // Input data, from VS1053/SD card
#define MOSI 11      // Output data, to VS1053/SD card

// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // SD card chip select pin
// DREQ should be an Interrupt pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            A0

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      36

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// assign other digital pins
#define buttonPin 2
#define motorPin  5
#define relayPin  A1

// neopixel constants
#define RAMPUPDELAY 5000
#define RAMPDOWNDELAY 4800
#define FLICKERDELAY 400

// working variables
int brightness = 0, fanSpeed = 0, redBright = 0, greenBright = 0, blueBright = 0, neoSwitch = 0, rCol = 255, gCol = 0, bCol = 180;
unsigned long startTime = 0, idleStartTime = 0, shutdownStart = 0, randBright = 0;
long startupDuration = 3300, idleDuration = 48000, shutdownDuration = 3907 ;
float percentBright = 0;
bool idleStarted = false, idlePlaying = false;

void setup() {
  // assign state of digital pins
  pinMode(buttonPin, INPUT);
  pinMode(motorPin, OUTPUT);
  digitalWrite(motorPin,LOW);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin,LOW);

  // allows serial console comms
  Serial.begin(115200);

  // seed random number generator
  randomSeed(analogRead(0));

  // initialise the music player
  if (! musicPlayer.begin()) {
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
  }
  else {
    Serial.println(F("VS1053 found"));
  }
 
  // check SD card installed
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
  }
  else {
    Serial.println(F("SD found"));
  }

  // open the SD card for reading
  SD.open("/");

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
 
  // initialize the NeoPixel library
  pixels.begin();
  // set the pixels to Off
  pixels.show();
 
  Serial.println(F("System Started..."));
}

void loop() {
  if(digitalRead(buttonPin) == HIGH) {
    Serial.println("Button Pressed");
    // begin startup sequence
    // play startup sound
    musicPlayer.startPlayingFile("track001.mp3");
   
    // save starting timestamp
    startTime = millis();
    idleStarted = false;
       
    // loop waiting for startup sound to conclude
    while(idleStarted == false) {
      if(millis() - startTime >= startupDuration) {
        // startup sound has concluded, exit loop
        idleStarted = true;
      }

      //fade in neopixels
      neoRampUp();

      //speed up fan
      fanRampUp();
    }     

    // begin idle sequence
    Serial.println(F("Starting Idle"));
    idlePlaying = true;

    // save idle start timestamp
    idleStartTime = millis();

    // start smoke
    digitalWrite(relayPin, HIGH);

    // loop during idle sound, wait for end of sound or button press
    while(idlePlaying && (digitalRead(buttonPin) == LOW)) {
      if((millis() - idleStartTime  >= idleDuration) || (digitalRead(buttonPin) == HIGH))  {
        // idle sound has concluded, exit loop
        idlePlaying = false;
      }
     
      // neopixel flicker effect
      neoFlicker();
    }

    // begin shutdown sequence
    Serial.println(F("Shutting Down"));
    shutdownStart = millis();

    // shutdown sound
    musicPlayer.startPlayingFile("track002.mp3");

    // stop smoke
    digitalWrite(relayPin, LOW);
   

    // loop during shutdown sound
    while((millis() - shutdownStart  <= shutdownDuration)) {
      //fade out neopixels
      neoRampDown();

      //slow down fan
      fanRampDown();
    }
  }


// slowly increase neopixel brightness
void neoRampUp() {
  if(neoSwitch >= RAMPUPDELAY) {        //neoswitch sets number of cycles to skip. Larger number = slower effect speed
    if(brightness < 100) {
      brightness++;
      rCol = 255;
      gCol = 0;
      bCol = 180;
      displayNeo(brightness, rCol, gCol, bCol);
    }
    neoSwitch = 0;
  } 
  else {
    neoSwitch++; 
  }
}

// slowly decrease neopixel brightness
void neoRampDown() {
  if(neoSwitch >= RAMPDOWNDELAY) {
    if(brightness > 0) {
      brightness--;
      rCol = 255;
      gCol = 0;
      bCol = 180;
      displayNeo(brightness, rCol, gCol, bCol);
    }
    neoSwitch = 0;
  } 
  else {
    neoSwitch++; 
  }
}

// make the neopixel flicker
void neoFlicker() {
  if(neoSwitch >= FLICKERDELAY) {
    randBright = random(0,99);
    rCol = 255;
    gCol = 0;
    bCol = 180;
    displayNeo(randBright, rCol, gCol, bCol);
    neoSwitch = 0;
  } 
  else {
    neoSwitch++; 
  }
}

// set neopixel color & brightness and turn them on
void displayNeo(int brightLevel, int redclr, int grnclr, int bluclr) {
  percentBright = (brightLevel / 100.0);
  redBright = (percentBright * redclr);
  greenBright = (percentBright * grnclr);
  blueBright = (percentBright * bluclr);

  for(int i = 0; i<36; i++) {
    if(i < 24) {
      pixels.setPixelColor(i,redBright,greenBright,0);
    }
    else {
      pixels.setPixelColor(i,0,0,blueBright);
    }
  }

  pixels.show();
}

// Function for ramping up fan 
void fanRampUp() {
  if(fanSpeed < 60) {
    fanSpeed++;
    analogWrite(motorPin, fanSpeed);
  }
}

// Function for ramping down fan
void fanRampDown() {
  if(fanSpeed > 0 ) {
    fanSpeed--;
    analogWrite(motorPin, fanSpeed);
  }
}



HaakeSack
 
Posts: 2
Joined: Thu Sep 10, 2020 9:06 pm

Re: Music Maker Shield Intermittent Failure

by HaakeSack on Sat Sep 19, 2020 12:34 am

Bump

Please help, support.

Is there a way to pull a log from just the shield? It works about 85% of the time. I've gone through the steps of commenting out all of the other aspects of the prgm and the failure persists Could this be a library problem? An SD problem? Has anyone else had this kind of intermittent failure?

HaakeSack
 
Posts: 2
Joined: Thu Sep 10, 2020 9:06 pm

Please be positive and constructive with your questions and comments.