Problem with MP3 Shield and IR Remote on UNO R3

Hello

I’m trying to make a simple MP3 player with

  • Arduino Uno

  • one MP3 shield Sparkfun

  • a remote control and an IR receiver

The MP3 shield was plugged into the Arduino Uno card.

9 MP3 tracks have been saved on the SD card inserted into the MP3 shield.

My aim is to select the keys 1 through 9 with the remote control and then start tracking tracks from track001.mp3 to track009.mp3, following the “Hookup Guide”.

The problem is with the remote control.

In fact, once the first key is selected (eg key 2), the track associated with key 2 (track002.mp3) is played correctly. And so all right.

When I press a different button on the remote control, the decoding of the signal sent by the remote control is incorrect and therefore no new play is played.

As you can see in the image below, only the first decoding (FD9867) is correct (consisting of 6 hexadecimal characters identical to those of the pressed button, which was previously verified with a sketch of the key setup).

Other are all wrong,

Yet, if they are displayed with the “” Serial.println (results.value, HEX) command; “” means that the decoding has been, that is, the “decode” method of the “irrecv” object has decoded and saved it in “results”.

As you can see, as a IR receiver pin, I have set an analog pin (14, which, as you know, can also work as a digital pin). Anyway, the problem is not this. Sparkfun’s MP3 shield lets only the digital pin 5 and 10 be free, and even using these pins the problem occurs in the same way.

Choosing an analogue pin is due to the fact that the free digital feet (5 and 10) are next to other pins used by the MP3 shield. Therefore, having initially hypothesized an interference problems (signal coupling) of the IR signal with the neighboring pins, I moved to analog ones, completely unused by the MP3 shield. Some idea?

#include <IRremote.h>
#include <SPI.h>           // SPI library
#include <SdFat.h>         // SDFat Library
#include <SdFatUtil.h>     // SDFat Util Library
#include <SFEMP3Shield.h>  // Mp3 Shield Library


long comando = 0;
int scelta = 0;
int sceltan = 0;

#define receiver 14      

IRrecv irrecv(receiver); // create istance of 'irrecv'
decode_results results;

SdFat sd; // Create object to handle SD functions
SFEMP3Shield MP3player; // Create Mp3 library object
const uint8_t volume = 20; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max

void setup() {

#if defined(USE_MP3_REFILL_MEANS) \
    && ( (USE_MP3_REFILL_MEANS == USE_MP3_SimpleTimer) \
    ||   (USE_MP3_REFILL_MEANS == USE_MP3_Polled)      )

  MP3player.available();
#endif
  
  Serial.begin(9600);    
  irrecv.enableIRIn();  // Initialize IR Sensor
  initSD();  // Initialize the SD card
  initMP3Player(); // Initialize the MP3 Shield
}

void loop(){
  if (irrecv.decode(&results))           
  {
    Serial.println(results.value, HEX); 

    comando = results.value;

   if (comando == 0xFD30CF) {
      scelta=0;
    } 
      else if (comando == 0xFD08F7) {
      scelta=1;
    } 
      else if (comando == 0xFD8877) {
      scelta=2;
    } 
    else if (comando == 0xFD48B7) {
      scelta=3;
    } 
    else if (comando == 0xFD28D7) {
      scelta=4;
    } 
    else if (comando == 0xFDA857) {
      scelta=5;
    } 
    else if (comando == 0xFD6897) {
      scelta=6;
    } 
    else if (comando == 0xFD18E7) {
      scelta=7;
    } 
    else if (comando == 0xFD9867) {
      scelta=8;
    } 
      else if (comando == 0xFD58A7) {
      scelta=9;
    } 
      else 
    {
        scelta=-10;   // no correct remote control signal
    }


    if ((scelta!=sceltan)&&(scelta!=-10)) 
    // If the choice is different from the previous one and the key is correct
    // stops any playback being played
    // start the new play
    // Stores the value of the current song in "sceltan" for later comparison
    {
     MP3player.stopTrack();
     uint8_t result = MP3player.playTrack(scelta);
     sceltan=scelta;
    } 
  
  irrecv.resume();
 }    // close -- if (irrecv.decode(&results))       
}     // close -- void loop()


void initSD()
{
  //Initialize the SdCard.
  if(!sd.begin(SD_SEL, SPI_HALF_SPEED)) 
    sd.initErrorHalt();
  if(!sd.chdir("/")) 
    sd.errorHalt("sd.chdir");
}
void initMP3Player()
{
  uint8_t result = MP3player.begin(); // init the mp3 player shield
  if(result != 0) // check result, see readme for error codes.
  {
    // Error checking can go here!
  }
  MP3player.setVolume(volume, volume);
  MP3player.setMonoMode(monoMode);
}

http://imageshack.com/a/img922/7726/aAm61k.png

To what I said in the previous post, I want to add that the problem also occurs if, instead of an infrared receiver, I use an ultrasonic sensor connected to the Arduino pin left free from the MP3 shield (5,10, Analog pin). In this case, the Pulsein command, which is used to calculate the duration of a pulse, provide negative values, which is absurd. All this happens if I run Arduino commands while playing a MP3 file. It would seem that there are problems managing timing operations. on left free Arduino pin, during playback of the MP3 shield.