This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 1 voto(s) - 2 Media
  • 1
  • 2
  • 3
  • 4
  • 5
APORTE mp3 catalex y bluetooth hc 06
#1
Hola compañeros, os traigo aquí un MP3 basado en  el módulo Catalex TX5300 y bluetooth hc 06, junto con una app desarrollada con appinventor.

El módulo hc 06, lo tengo reconfigurado de cómo viene de fábrica, cambiándole el nombre y los pins.

Para solucionar un problema inicial que me encontré con la comunicación entre ambos módulos, gracias al ejemplo de  Software serial, para usar dos puertos de comunicación lo solucione, sino el código de catalex funcionaba y la parte de hc 06 también pero por separado, al unirlo solo funcionaba el MP3. Lo de desarrollado haciendo pequeños trozos funcionales de código y luego uniéndolo, pero lo dicho dos puertos de comunicación y listo.

Os dejo el esquema, el código de arduino, los esquemas del appinventor
Lo que aquí presento es la versión 0.1, el inicio, ahora queda ponerle más funciones a la app, pero es la base por si alguien lo quiere desarrollar. Por ahora play y stop básico.
El arranque es un poco lento.
Doy las gracias por la ayuda a
LUIS DE VALLE, de www.programarfacil.com
 (gracias a su campus y alguna pista lo he logrado. Para ser un novato principiante estoy muy satisfecho)
JOAN info de uso de Catalex en https://joanruedapauweb.com/blog/index.p...yx5300-es/
Juan Antonio Villalpando,  información para bluetooth y appinventor http://kio4.com/appinventor/index.htm#indice PUNTO 9

esquema modulos arduino Uno

[Imagen: mp3-CATALEX-Y-HC-06-bb.jpg]

diseño app (appinventor)

[Imagen: app-dise-o.png]

Bloques appinventor

[Imagen: blocks.png]

código Arduino (placa arduino Uno)
Código:
/*
*

Texto:

  ____      _      _____      _      _       _____  __  __   __   __ __  __  ____    _____    ___     ___                ____    _       _   _   _____   _____    ___     ___    _____   _   _
 / ___|    / \    |_   _|    / \    | |     | ____| \ \/ /   \ \ / / \ \/ / | ___|  |___ /   / _ \   / _ \       _      | __ )  | |     | | | | | ____| |_   _|  / _ \   / _ \  |_   _| | | | |
| |       / _ \     | |     / _ \   | |     |  _|    \  /     \ V /   \  /  |___ \    |_ \  | | | | | | | |    _| |_    |  _ \  | |     | | | | |  _|     | |   | | | | | | | |   | |   | |_| |
| |___   / ___ \    | |    / ___ \  | |___  | |___   /  \      | |    /  \   ___) |  ___) | | |_| | | |_| |   |_   _|   | |_) | | |___  | |_| | | |___    | |   | |_| | | |_| |   | |   |  _  |
 \____| /_/   \_\   |_|   /_/   \_\ |_____| |_____| /_/\_\     |_|   /_/\_\ |____/  |____/   \___/   \___/      |_|     |____/  |_____|  \___/  |_____|   |_|    \___/   \___/    |_|   |_| |_|
                                                                                                                               
VERSION 0.1 // 14 ABRIL 2020

bibliografía

Doy las gracias a Luis del valle, por su ayuda en https://programarfacil.com/ por su campus con el que he aprendido a desarrollar la primera versión de este proyecto y por las pistas facilitadas en el proceso de aprender.
También agradecer a Joan y a José Antonio por compartir la información en sus blogs tanto para el uso de catalex como para appinventor y el módulo hc 06
                                                                                                                                                               
*
*
*
  info de uso en https://joanruedapauweb.com/blog/index.php/2017/02/07/arduino-serial-mp3-player-yx5300-es/
 // Demo for the Serial MP3 Player Catalex (YX5300 chip)
 // Hardware: Serial MP3 Player *1
 // Board:  Arduino UNO
 // http://www.dx.com/p/uart-control-serial-mp3-music-player-module-for-arduino-avr-arm-pic-blue-silver-342439#.VfHyobPh5z0
 //
 //


 // INFORMACIÓN BLUETOOTH http://kio4.com/appinventor/index.htm#indice PUNTO 9
 // Juan Antonio Villalpando
 // juana1991@yahoo.com
 // kio4.com

*/
#include <SoftwareSerial.h>


/*
  bluetooth
*/

#define BLUETOOTH_TX 9 //AZUL
#define BLUETOOTH_RX 8 //AMARRILLO

/*
 PUERTO 1 //BLUETOOTH
*/
SoftwareSerial SerialBT(BLUETOOTH_TX, BLUETOOTH_RX);

int pin_led = 7;
char val;
String palabra;

String accion;
String rpm2;

int k1;
int k2;
int k3;
int k4;


/*
  PUERTO 2 // MP3
*/

// El pin de entrada donde está conectado el pulsador
byte pinPulsador = 6;

byte valor = 0; // variable que almacenará la lectura del pulsador
byte old_valor = 0; //variable que almacenará la lectura anterior del pulsador. Comparandolas sabremos si ha cambiado
byte estado_pulsador = 0; // Variable que almacena el estado del pulsador


#define MP3_RX 10  //CABLE VERDE RX should connect to TX of the Serial MP3 Player module
#define MP3_TX 11  //CABLE NARANJA TX connect to RX of the module

SoftwareSerial mp3(MP3_TX, MP3_RX);
//#define mp3 Serial3    // Connect the MP3 Serial Player to the Arduino MEGA Serial3 (14 TX3 -> RX, 15 RX3 -> TX)

static int8_t Send_buf[8] = {0}; // Buffer for Send commands.  // BETTER LOCALLY
static uint8_t ansbuf[10] = {0}; // Buffer for the answers.    // BETTER LOCALLY

String mp3Answer;           // Answer from the MP3.

boolean autoResume = true;

/************ Command byte **************************/
#define CMD_NEXT_SONG     0X01  // Play next song.
#define CMD_PREV_SONG     0X02  // Play previous song.
#define CMD_PLAY_W_INDEX  0X03
#define CMD_VOLUME_UP     0X04
#define CMD_VOLUME_DOWN   0X05
#define CMD_SET_VOLUME    0X06

#define CMD_SNG_CYCL_PLAY 0X08  // Single Cycle Play.
#define CMD_SEL_DEV       0X09
#define CMD_SLEEP_MODE    0X0A
#define CMD_WAKE_UP       0X0B
#define CMD_RESET         0X0C
#define CMD_PLAY          0X0D
#define CMD_PAUSE         0X0E
#define CMD_PLAY_FOLDER_FILE 0X0F

#define CMD_STOP_PLAY     0X16
#define CMD_FOLDER_CYCLE  0X17
#define CMD_SHUFFLE_PLAY  0x18 //
#define CMD_SET_SNGL_CYCL 0X19 // Set single cycle.

#define CMD_SET_DAC 0X1A
#define DAC_ON  0X00
#define DAC_OFF 0X01

#define CMD_PLAY_W_VOL    0X22
#define CMD_PLAYING_N     0x4C
#define CMD_QUERY_STATUS      0x42
#define CMD_QUERY_VOLUME      0x43
#define CMD_QUERY_FLDR_TRACKS 0x4e
#define CMD_QUERY_TOT_TRACKS  0x48
#define CMD_QUERY_FLDR_COUNT  0x4f

/************ Opitons **************************/
#define DEV_TF            0X02


/*********************************************************************/

void setup()
{
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }
 // ARRANCAMOS PUERTO MP3
 mp3.begin(9600);

 sendCommand(CMD_SEL_DEV, DEV_TF);
 
 pinMode(pinPulsador, INPUT);

 // ARRANCAMOS PUERTO BLUETOOTH
 SerialBT.begin(9600);

 // Ponemos el pin en modo salida (OUTPUT)
 pinMode(pin_led, OUTPUT);
}


void loop()
{
 
 char c = ' ';

 if (SerialBT.available())
 {
   val = SerialBT.read();
   palabra = palabra + val;

   if (val == '*') {

     Serial.println(palabra);
     //busco la posición primera coma
     k1 = palabra.indexOf(',');
     //el dato es ente la posición 0 y la posicion k1
     accion = palabra.substring(0, k1);

     Serial.println(accion);
     palabra = "";
     if (accion == "play") {
       digitalWrite(pin_led, HIGH);
      sendCommand(CMD_PLAY, 0);
     }

     if (accion == "stop") {
       digitalWrite(pin_led, LOW);
      sendCommand(CMD_STOP_PLAY, 0);

     }
   }
 }


 // If there a char on Serial call sendMP3Command to sendCommand
 if ( Serial.available() )
 {
   c = Serial.read();
   sendMP3Command(c);
 }

 // Check for the answer.
 if (mp3.available())
 {
   Serial.println(decodeMP3Answer());
 }
 delay(100);

}


/********************************************************************************/
/*Function sendMP3Command: seek for a 'c' command and send it to MP3  */
/*Parameter: c. Code for the MP3 Command, 'h' for help.                                                                                                         */
/*Return:  void                                                                */

void sendMP3Command(char c) {
 switch (c) {
   case '?':
   case 'h':
     Serial.println("HELP  ");
     Serial.println(" p = Play");
     Serial.println(" P = Pause");
     Serial.println(" > = Next");
     Serial.println(" < = Previous");
     Serial.println(" + = Volume UP");
     Serial.println(" - = Volume DOWN");
     Serial.println(" c = Query current file");
     Serial.println(" q = Query status");
     Serial.println(" v = Query volume");
     Serial.println(" x = Query folder count");
     Serial.println(" t = Query total file count");
     Serial.println(" 1 = Play folder 1");
     Serial.println(" 2 = Play folder 2");
     Serial.println(" 3 = Play folder 3");
     Serial.println(" 4 = Play folder 4");
     Serial.println(" 5 = Play folder 5");
     Serial.println(" S = Sleep");
     Serial.println(" W = Wake up");
     Serial.println(" r = Reset");
     break;


   case 'p':
     Serial.println("Play ");
     sendCommand(CMD_PLAY, 0);
     break;

   case 'P':
     Serial.println("Pause");
     sendCommand(CMD_PAUSE, 0);
     break;


   case '>':
     Serial.println("Next");
     sendCommand(CMD_NEXT_SONG, 0);
     sendCommand(CMD_PLAYING_N, 0x0000); // ask for the number of file is playing
     break;


   case '<':
     Serial.println("Previous");
     sendCommand(CMD_PREV_SONG, 0);
     sendCommand(CMD_PLAYING_N, 0x0000); // ask for the number of file is playing
     break;

   case '+':
     Serial.println("Volume Up");
     sendCommand(CMD_VOLUME_UP, 0);
     break;

   case '-':
     Serial.println("Volume Down");
     sendCommand(CMD_VOLUME_DOWN, 0);
     break;

   case 'c':
     Serial.println("Query current file");
     sendCommand(CMD_PLAYING_N, 0);
     break;

   case 'q':
     Serial.println("Query status");
     sendCommand(CMD_QUERY_STATUS, 0);
     break;

   case 'v':
     Serial.println("Query volume");
     sendCommand(CMD_QUERY_VOLUME, 0);
     break;

   case 'x':
     Serial.println("Query folder count");
     sendCommand(CMD_QUERY_FLDR_COUNT, 0);
     break;

   case 't':
     Serial.println("Query total file count");
     sendCommand(CMD_QUERY_TOT_TRACKS, 0);
     break;

   case '1':
     Serial.println("Play folder 1");
     sendCommand(CMD_FOLDER_CYCLE, 0x0101);
     break;

   case '2':
     Serial.println("Play folder 2");
     sendCommand(CMD_FOLDER_CYCLE, 0x0201);
     break;

   case '3':
     Serial.println("Play folder 3");
     sendCommand(CMD_FOLDER_CYCLE, 0x0301);
     break;

   case '4':
     Serial.println("Play folder 4");
     sendCommand(CMD_FOLDER_CYCLE, 0x0401);
     break;

   case '5':
     Serial.println("Play folder 5");
     sendCommand(CMD_FOLDER_CYCLE, 0x0501);
     break;

   case 'S':
     Serial.println("Sleep");
     sendCommand(CMD_SLEEP_MODE, 0x00);
     break;

   case 'W':
     Serial.println("Wake up");
     sendCommand(CMD_WAKE_UP, 0x00);
     break;

   case 'r':
     Serial.println("Reset");
     sendCommand(CMD_RESET, 0x00);
     break;
 }
}



/********************************************************************************/
/*Function decodeMP3Answer: Decode MP3 answer.                                  */
/*Parameter:-void                                                               */
/*Return: The                                                  */

String decodeMP3Answer() {
 String decodedMP3Answer = "";

 decodedMP3Answer += sanswer();

 switch (ansbuf[3]) {
   case 0x3A:
     decodedMP3Answer += " -> Memory card inserted.";
     break;

   case 0x3D:
     decodedMP3Answer += " -> Completed play num " + String(ansbuf[6], DEC);
     break;

   case 0x40:
     decodedMP3Answer += " -> Error";
     break;

   case 0x41:
     decodedMP3Answer += " -> Data recived correctly. ";
     break;

   case 0x42:
     decodedMP3Answer += " -> Status playing: " + String(ansbuf[6], DEC);
     break;

   case 0x48:
     decodedMP3Answer += " -> File count: " + String(ansbuf[6], DEC);
     break;

   case 0x4C:
     decodedMP3Answer += " -> Playing: " + String(ansbuf[6], DEC);
     break;

   case 0x4E:
     decodedMP3Answer += " -> Folder file count: " + String(ansbuf[6], DEC);
     break;

   case 0x4F:
     decodedMP3Answer += " -> Folder count: " + String(ansbuf[6], DEC);
     break;
 }

 return decodedMP3Answer;
}


/********************************************************************************/
/*Function: Send command to the MP3                                         */
/*Parameter:-int8_t command                                                     */
/*Parameter:-int16_ dat  parameter for the command                              */

void sendCommand(int8_t command, int16_t dat)
{
 delay(20);
 Send_buf[0] = 0x7e;   //
 Send_buf[1] = 0xff;   //
 Send_buf[2] = 0x06;   // Len
 Send_buf[3] = command;//
 Send_buf[4] = 0x01;   // 0x00 NO, 0x01 feedback
 Send_buf[5] = (int8_t)(dat >> 8);  //datah
 Send_buf[6] = (int8_t)(dat);       //datal
 Send_buf[7] = 0xef;   //
 Serial.print("Sending: ");
 for (uint8_t i = 0; i < 8; i++)
 {
   mp3.write(Send_buf[i]) ;
   Serial.print(sbyte2hex(Send_buf[i]));
 }
 Serial.println();
}



/********************************************************************************/
/*Function: sbyte2hex. Returns a byte data in HEX format.                 */
/*Parameter:- uint8_t b. Byte to convert to HEX.                                */
/*Return: String                                                                */


String sbyte2hex(uint8_t b)
{
 String shex;

 shex = "0X";

 if (b < 16) shex += "0";
 shex += String(b, HEX);
 shex += " ";
 return shex;
}




/********************************************************************************/
/*Function: sanswer. Returns a String answer from mp3 UART module.          */
/*Parameter:- uint8_t b. void.                                                  */
/*Return: String. If the answer is well formated answer.                        */

String sanswer(void)
{
 uint8_t i = 0;
 String mp3answer = "";

 // Get only 10 Bytes
 while (mp3.available() && (i < 10))
 {
   uint8_t b = mp3.read();
   ansbuf[i] = b;
   i++;

   mp3answer += sbyte2hex(b);
 }

 // if the answer format is correct.
 if ((ansbuf[0] == 0x7E) && (ansbuf[9] == 0xEF))
 {
   return mp3answer;
 }

 return "???: " + mp3answer;
}
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  CONSULTA DFPlayer vs YX5300 de Catalex, reproducir mp3 katxarix 4 1,606 18-04-2020, 10:30 AM
Último mensaje: katxarix
  CONSULTA AUMENTAR ALCANCE MÓDULO BLUETOOTH AT-09 CON ANTENA Alvaro Braca 3 2,704 14-03-2019, 09:12 AM
Último mensaje: Merenat
  APORTE Control de Persiana por bluetooth kuadri 0 1,467 16-06-2018, 11:33 PM
Último mensaje: kuadri
  Problema con bluetooth y comandos AT sejiozosky 41 17,481 06-05-2018, 11:48 AM
Último mensaje: Iván
  CONSULTA ayuda con modulo bluetooth f-6188 kcho26 0 1,405 25-02-2018, 07:29 PM
Último mensaje: kcho26