My project is an MP3 player controlled by voice recognition. I know that I need Mega so that each module has its own HW serial port but before it arrives I'm curious whether it could work with UNO as well.
I know two modules can't communicate using SoftwareSerial at the same time but what if I don't need them to work simoultanously?
/1/ Start listenning for voice command, process it
/2/ Stop listenning
/3/ Play MP3
/4/ Stop playing MP3
/5/ Start listenning for the next voice command
Is this possible using SoftwareSerial?
Each module works fine individually but not together.
Modules:
- ELECHOUSE Voice Recognition Modul Modul rozpoznávání hlasu V3 | dratek.cz
- UART MP3 modul YX5300 v1.2 UART MP3 modul YX5300 V1.3.2 | dratek.cz
Code:
#include "SerialMP3Player.h"
#include "VoiceRecognitionV3.h"
// MP3
#define TX 10
#define RX 11
#define CMD_PLAY_W_INDEX 0X03
#define CMD_PLAY_FOLDER_FILE 0X0f
SerialMP3Player mp3(RX, TX);
// VOICEC RECOGNITION
VR myVR(3, 2);
uint8_t records[7];
uint8_t buf[64];
#define meRecord (0)
#define himRecord (1)
#define undoRecord (2)
#define scoreRecord (3)
#define serveRecord (4)
void setup() {
/* MP3 START */
Serial.begin(9600);
mp3.begin(9600);
delay(500);
mp3.sendCommand(CMD_SEL_DEV, 0, 2);
delay(500);
/* MP3 END */
/* VR START */
myVR.begin(9600);
Serial.begin(115200);
Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
if (myVR.clear() == 0) {
Serial.println("Recognizer cleared.");
} else {
Serial.println("Not find VoiceRecognitionModule.");
Serial.println("Please check connection and restart Arduino.");
while (1)
;
}
if (myVR.load((uint8_t)meRecord) >= 0) {
Serial.println("meRecord loaded");
}
if (myVR.load((uint8_t)himRecord) >= 0) {
Serial.println("himRecord loaded");
}
if (myVR.load((uint8_t)scoreRecord) >= 0) {
Serial.println("scoreRecord loaded");
}
if (myVR.load((uint8_t)serveRecord) >= 0) {
Serial.println("serveRecord loaded");
}
/* VR END */
}
void loop() {
mp3.sendCommand(CMD_PLAY_FOLDER_FILE, 02, 0x01);
delay(2000);
int ret;
ret = myVR.recognize(buf, 50);
//Serial.println(String(ret));
if (ret > 0) {
switch (buf[1]) {
case meRecord:
Serial.println("ME POINT");
//addPoint(player1, player2);
break;
case himRecord:
Serial.println("HIM POINT");
break;
default:
Serial.println("Record function undefined");
break;
}
}
}