Cytron MP3 Shield and I2C link between two arduinos

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Cytron MP3 Shield and I2C link between two arduinos

Postby bestpak85 » Sun Jan 17, 2016 12:01 am

Hi,

I just buy the Cytron MP3 Shield but i have a issue when i use it with I2C (Wire standard library).
can i do that ? or they have some I2C are already use by the shield ?

My code :
CODE: SELECT_ALL_CODE
#include <SdFat.h>
#include <MP3Player.h>
#include <Wire.h> // Librairie pour la communication I2C


//Declarations des entrées/sorties
//*********************************************************************
int dataMP3 = 2;    //bus de données MP3
int clockMP3 = 3;   //bus d'horloge MP3
int MP3Shield = A0; //Port MP3 A0
String Folder = "mp3";

int val = 0;           // variable to store the value read
int vol = 220;
int state = -1;
int temps = 0;
int value = -1;

void setup()
{
  //Initialisation MP3
  pinMode(MP3Shield, INPUT);
  randomSeed(analogRead(MP3Shield));

  Serial.begin(9600);
  if (!mp3.Init(clockMP3, dataMP3))
  {
    while (1);
  }
  vol = 220;
  mp3.setVolume(220);
  val = 0;

  Wire.begin(4); // Rejoindre le bus à l'adresse #4
  Wire.onReceive(receiveEvent); // Preparer une fonction spécifique a la reception de donnee
}

void loop()
{
  delay(100);
  if (state != value)
  {
    state = value;
    Serial.println(">>>");
    Serial.println(state);
    switch (state)
    {
      case 0:
        mp3.Stop();
        break;
      case 1:
      mp3.PlayTrack("cloud", "1.mp3");
        break;
      case 2:
        mp3.setVolume(++vol);
        break;
      case 3:
        mp3.setVolume(--vol);
        break;
      case 4:
        mp3.Next();
        break;
      case 5:
        mp3.Previous();
        break;
      case 6:
        if (mp3.isPlaying())
        {
          mp3.Stop();
        }
        else
        {
          mp3.PlayFolder(Folder.c_str());
        }
        break;
    }
  }


}

// Fonction qui s execute si quelque chose est present sur l interface
void receiveEvent(int howMany)
{
  int x = Wire.read();
  Serial.println(x);
  switch (x)
  {
    case 0:
      value = 0;
      break;
    case 1:
      value = 1;
      break;
    case 2:
      value = 2;
      break;
    case 3:
      value = 3;
      break;
    case 4:
      value = 4;
      break;
    case 5:
      value = 5;
      break;
    case 6:
      value = 6;
      break;

  }
}
bestpak85
Fledgling
 
Posts: 1
Joined: Sat Jan 16, 2016 11:56 pm

Re: Cytron MP3 Shield and I2C link between two arduinos

Postby bengchet » Sun Jan 17, 2016 5:30 pm

Hi,

Yes, Arduino communicates with MP3 decoder chip on MP3 shield using I2C communication too and join the bus as master. In this case, you are using Arduino as I2C slave as well. So it will not work.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 6 guests

cron