Music maker VS1053 and RFID reader ID-20

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Cyril
 
Posts: 7
Joined: Fri Aug 08, 2014 9:15 am

Music maker VS1053 and RFID reader ID-20

Post by Cyril »

Hi, I am working on a music player activated by RFID cards. Each card should start the reading of a MP3 file. I use the Music Maker VS1053 shield and RFID reader ID-20 connected to an Arduino UNO. I made a short test code to show you the problem I have.

When the Music Maker shield is not playing music I can scan RFID cards with accuracy. For example, here is the result I get reading several times the same card :
1300494C4D5B
1300494C4D5B
1300494C4D5B
But when the Music Maker shield is playing music, the transmitted ID is "scrambled".
1300494C4D513&­˜°à1300494CFF­3hÅ1300
1300494C4D5B
BANNED
1300494C4130049ÁF–F63´f¡
When I pause the music reading, the RFID ID transmitted come back normal.

Code: Select all

#include <SoftwareSerial.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define SHIELD_CS       7     // VS1053 chip select pin (output)
#define SHIELD_DCS      6     // VS1053 Data/command select pin (output)
#define CARDCS          4     // Card chip select pin
#define DREQ            3     // VS1053 Data request, ideally an Interrupt pin

SoftwareSerial id20(5, 11); // virtual serial port

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

void setup()
{
  
 Serial.begin(9600);
 id20.begin(9600);
   if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
     }
  Serial.println(F("VS1053 found"));
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");
   // 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
    
     if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
    Serial.println(F("DREQ pin is not an interrupt pin"));
    
 Serial.println(F("Playing track 001"));
 musicPlayer.startPlayingFile("track001.mp3");
 
}

void loop () 
{
 if(id20.available()) {
   char i;
 i = id20.read(); // receive character from ID20
 Serial.print(i); // send character to serial monitor

 }
   if (Serial.available()) {
    char c = Serial.read();
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }
}
If anybody can help me, it would be fantastic!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Music maker VS1053 and RFID reader ID-20

Post by adafruit_support_rick »

You can't use pin 11 for software serial - it's an SPI pin, used by the VS1053.

Also, you probably don't want to use software serial at all. You should configure your RFID board to use I2C instead.

User avatar
Cyril
 
Posts: 7
Joined: Fri Aug 08, 2014 9:15 am

Re: Music maker VS1053 and RFID reader ID-20

Post by Cyril »

I change SoftwareSerial pin from 11 to 10 but it's exactly the same!
My ID-20 RFID work very with SoftwareSerial but only if Music maker is not playing something.
Is there an incompatiblity ?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Music maker VS1053 and RFID reader ID-20

Post by adafruit_support_rick »

Software Serial timing is very critical. An interrupt by the VS1053 can easily throw the timing off and corrupt an incoming character.
You really should switch your RFID to use I2C. I doubt that you can make software serial work reliably alongside the VS1053

User avatar
Cyril
 
Posts: 7
Joined: Fri Aug 08, 2014 9:15 am

Re: Music maker VS1053 and RFID reader ID-20

Post by Cyril »

I remove the SoftwareSerial library but the problem persist!
I don't know how and even if it is possible to use the ID-20 RFID reader with I2C.

Code: Select all

}
void loop() {
  // File is playing in the background
  if (Serial.available() > 0) {
    char c = Serial.read();
    Serial.print(c);
  }
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Music maker VS1053 and RFID reader ID-20

Post by adafruit_support_rick »

I'm sorry - I was thinking that you were using the Adafruit RFID reader. I don't know anything about an ID-20 reader.

Try connecting the reader TX to Digital 0 and the reader RX to Digital 1. Use Serial to read instead of SoftwareSerial.

User avatar
Cyril
 
Posts: 7
Joined: Fri Aug 08, 2014 9:15 am

Re: Music maker VS1053 and RFID reader ID-20

Post by Cyril »

It's what I made but even without using SoftwareSerial AND connecting the RFID reader ID-20 TX to Digital 0 and RX to Digital 1 the problem persist! It's very strange…

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Music maker VS1053 and RFID reader ID-20

Post by adafruit_support_rick »

I have one last suggestion. Try using the AltSoftSerial library:
https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

AND change the VS1053 to use the timer0 interrupt instead of the external interrupt:

Code: Select all

 musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
 
AltSoftSerial uses pin-change interrupts (like Software Serial) but doesn't rely on software bit timing. Pin-change interrupts are higher-priority than Timer0 interrupts, so maybe this will solve your problem.

User avatar
Cyril
 
Posts: 7
Joined: Fri Aug 08, 2014 9:15 am

Re: Music maker VS1053 and RFID reader ID-20

Post by Cyril »

I switch from DREQ interrupt to TIMER interrupt but even with the startPlayingFile command, the file IS NOT played in "background" and the code in the loop() is not executed…

Code: Select all

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>


// 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     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = 
   Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

void setup() {
  
   Serial.begin(9600);
  // initialise the music player
   musicPlayer.begin();
   SD.begin(CARDCS);
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  /***** Two interrupt options! *******/ 
   // musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
    musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
    
    
    musicPlayer.startPlayingFile("track001.mp3");
    Serial.println("Adafruit VS1053 Test");

  }



void loop() {
  // File is playing in the background
  if (Serial.available()) {
    char c = Serial.read();
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }
}



User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Music maker VS1053 and RFID reader ID-20

Post by adafruit_support_rick »

Hmmm ... you're right. The timer interrupt doesn't seem to work. I'll have to investigate that.

User avatar
syndic
 
Posts: 16
Joined: Tue Jul 22, 2014 4:34 am

Re: Music maker VS1053 and RFID reader ID-20

Post by syndic »

Is it possible that both the timer and the shield are using the same interrupt signal? Like maybe the shield overwrites the timer ISR?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Music maker VS1053 and RFID reader ID-20

Post by adafruit_support_rick »

syndic wrote:Is it possible that both the timer and the shield are using the same interrupt signal? Like maybe the shield overwrites the timer ISR?
Actually, that's the idea - the shield is supposed to piggy-back on the timer event by requesting an additional interrupt. The GPS examples do the same thing.

User avatar
syndic
 
Posts: 16
Joined: Tue Jul 22, 2014 4:34 am

Re: Music maker VS1053 and RFID reader ID-20

Post by syndic »

Oh /ha/. I thought the timer interrupt was supposed to be triggering something in addition to the shield, instead of triggering it directly. Sorry for the confusion.

User avatar
Cyril
 
Posts: 7
Joined: Fri Aug 08, 2014 9:15 am

Re: Music maker VS1053 and RFID reader ID-20

Post by Cyril »

I try to use the sparkfun MP3 Player library, SFEMP3Shield, and it works. I can read MP3 and read RFID tag at the same time.
I don't know why it's working and I have not the time and the knowledge to explore the library, unfortunately. Maybe you can use some ideas of that library to put in your…

User avatar
jeremypw
 
Posts: 6
Joined: Tue Oct 21, 2014 12:22 am

Re: Music maker VS1053 and RFID reader ID-20

Post by jeremypw »

Cyril - Have you made any progress on this? I ran into a similar issue with the adafruit library and an IR receiver. I developed a workaround and thought you may be interested.

http://forums.adafruit.com/viewtopic.ph ... 12#p313612

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”