Magic band player.play issue

Working on some code (not mine) for a magic band reader and having an issue.
Any time i scan a rfid, it plays the mp3 and lights as expected but if i scan it again or any other rfid the leds just go to 5 white lights and no sound or color sequence is played. I have to power cycle the arduino to get it to play again.

if i comment out the player.play the loops run perfect as many times as i use it. only issue is i want sound as well! Tried wav file instead of mp3 no luck, tried delay before and after, tried serial.println... no luck yet. Welcome thoughts.

Code:

#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Adafruit_NeoPixel.h>

#define PIN 8
#define N_LEDS 54
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN);

static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
DFRobotDFPlayerMini player;

#define SS_PIN 10
#define RST_PIN 9
#define ACCESS_DELAY 2000
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

//sound 
 int ariel = 1; //labled 2
 int imperialmarch = 2; //labled  6
 int JungleCruise = 3; //labled 3
 int MagicBand = 4; //labled 4
 int MagicBandSound = 5; //labled 5
 int Pirates = 6; //labled 5
 int RocknRoll = 7; //labled 7
 int SpaceMountain = 8; //labled 8
 int Tangled =9; //labled 7
 


void setup() 
{
  strip.begin(); //Needs to be before SPI.begin
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();          // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  softwareSerial.begin(9600); //need this to keep speaker working
  
  player.begin(softwareSerial);
  
  Serial.println("Put your card to the reader...");
  Serial.println();
}

void loop() {

  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  MFRC522::MIFARE_Key key;
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

  //some variables we need
  byte block;
  byte len;
  MFRC522::StatusCode status;
//-------------------------------------------

  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  Serial.println(F("**Card Detected:**"));

   //-------------------------------------------
  
  //Show UID on serial monitor
  Serial.print("UID tag :");
    String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();

  if (content.substring(1) == "04 43 2B 22 76 66 80") // Greg
  {
    Serial.println("Authorized Access Greg");
    Serial.println();
    delay(500);
    SpiralupDown(strip.Color(100, 100, 100));
    player.volume(30); //volume 1 to 30
    player.play(5); //play file in 1st spot
    player.play(5);
    //brightFade(75);
    brightFadeFast(1);
    brightFadeFast(1);
    brightFadeFast(1);
    brightFadeFast(1);
    colorWipe(strip.Color(0, 0, 0), 10); //RGB
  }

FYI this is a Christmas gift and appreciate any expedited advice! :slightly_smiling_face:

It's been awhile since I've tinkered with a RC522, but isn't there a mfrc522.PICC_HaltA(); call missing in loop()?

so i did try that and it seemed to be hit or miss. one time it allowed the sequence to run 4 times before stopping, but still stopped me eventually and that is frustrating considering its for the family and i hate to say "turn it off and back on again".. lol

I'll give it another shot though. should it be in each of the if else statements or just after the else?

I'd be guessing. Best to check the library docs and perhaps look at some of the example sketches.

ok, appreciate the quick response!

else   {
    Serial.println("Authorized Access"); //0E 40 8C B9 is for Puck
    Serial.println();
    delay(500);
    SpiralupDown(strip.Color(100, 100, 100));
    player.volume(20); //volume 1 to 30
    player.play(MagicBandSound); //play file in 1st spot
    player.play(MagicBandSound);
    delay(20);
    colorWipe(strip.Color(0, 100, 0), 2500); //RGB
    colorWipe(strip.Color(0, 0, 0), 10); //Blank
  }
  mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
}

realized i had it at the end of the else but still wasn't working

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.