Hello to all. I'm very new to Arduino. and I'm currently working on a voice interactive project. I'm using a mega 2560, a DFPlayer Mini mp3 module, and a Voice Recognition Module V3. My idea is to use the DFPlayer Mini mp3 module as a sound effect, and Voice Recognition Module V3 to save some pre-record commands. I could use these commands to active some movements and sounds. When I separately use any of the modules and they work fine. Unfortunately, when I tried to wire them together without any luck. The Voice Recognition Module is connected to a software port and the DFPlayer Mini mp3 module is on a hardware port. hope you guys could help me out. thses wires and PCBs drive me crazy. Thanks in advance.
My code
/**
******************************************************************************
@file vr_sample_control_led.ino
@author JiapengLi
@brief This file provides a demostration on
how to control led by using VoiceRecognitionModule
******************************************************************************
@note:
voice control led
******************************************************************************
@section HISTORY
2013/06/13 Initial version.
*/
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
#include <Servo.h>
//#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
//SoftwareSerial mySoftwareSerial(50, 51); // tX, rX
DFRobotDFPlayerMini myDFPlayer;
/**
Connection
Arduino VoiceRecognitionModule
11 -------> TX
10 -------> RX
*/
VR myVR(5, 6); // 11:RX 10:TX, you can choose your favourite pins.
uint8_t records[7]; // save record
uint8_t buf[64];
//int led = 13;// led function is disabled
Servo Servo1;
#define faceplateO (0)
#define faceplateC (1)
#define youthere (2)
/**
@brief Print signature, if the character is invisible,
print hexible value instead.
@param buf --> command length
len --> number of parameters
*/
void printSignature(uint8_t *buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf[i]>0x19 && buf[i]<0x7F){
Serial.write(buf[i]);
}
else{
Serial.print("[");
Serial.print(buf[i], HEX);
Serial.print("]");
}
}
}
/**
@brief Print signature, if the character is invisible,
print hexible value instead.
@param buf --> VR module return value when voice is recognized.
buf[0] --> Group mode(FF: None Group, 0x8n: User, 0x0n:System
buf[1] --> number of record which is recognized.
buf[2] --> Recognizer index(position) value of the recognized record.
buf[3] --> Signature length
buf[4]~buf[n] --> Signature
*/
void printVR(uint8_t *buf)
{
Serial.println("VR Index\tGroup\tRecordNum\tSignature");
Serial.print(buf[2], DEC);
Serial.print("\t\t");
if (buf[0] == 0xFF) {
Serial.print("NONE");
}
else if (buf[0] & 0x80) {
Serial.print("UG ");
Serial.print(buf[0] & (~0x80), DEC);
}
else {
Serial.print("SG ");
Serial.print(buf[0], DEC);
}
Serial.print("\t");
Serial.print(buf[1], DEC);
Serial.print("\t\t");
if (buf[3] > 0) {
printSignature(buf + 4, buf[3]);
}
else {
Serial.print("NONE");
}
Serial.println("\r\n");
}
void setup()
{
/** initialize */
myVR.begin(9600);
Serial1.begin(9600);
Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
//Serial1.begin(9600); //串口1,即Pin19及Pin18这里是mp3播放器阵脚
//pinMode(led, OUTPUT);// led is disabled
Servo1.attach(7);
Serial1.println();
Serial1.println(F("DFRobot DFPlayer Mini Demo"));
Serial1.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(Serial1)) { //Use softwareSerial to communicate with mp3.
Serial1.println(F("Unable to begin:"));
Serial1.println(F("1.Please recheck the connection!"));
Serial1.println(F("2.Please insert the SD card!"));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
//----Set volume----
myDFPlayer.volume(25); //Set volume value (0~30).
//myDFPlayer.volumeUp(); //Volume Up
//myDFPlayer.volumeDown(); //Volume Down
//----Set different EQ----
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
// myDFPlayer.EQ(DFPLAYER_EQ_POP);
// myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
// myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
// myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
// myDFPlayer.EQ(DFPLAYER_EQ_BASS);
//----Set device we use SD as default----
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);
//----Mp3 control----
// myDFPlayer.sleep(); //sleep
// myDFPlayer.reset(); //Reset the module
myDFPlayer.enableDAC(); //Enable On-chip DAC
// myDFPlayer.disableDAC(); //Disable On-chip DAC
// myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
//----Mp3 play----
/**myDFPlayer.next(); //Play next mp3
delay(1000);
myDFPlayer.previous(); //Play previous mp3
delay(1000);
myDFPlayer.play(1); //Play the first mp3
delay(1000);
myDFPlayer.loop(1); //Loop the first mp3
delay(1000);
myDFPlayer.pause(); //pause the mp3
delay(1000);
myDFPlayer.start(); //start the mp3 from the pause
delay(1000);
myDFPlayer.playFolder(15, 4); //play specific mp3 in SD:/15/004.mp3; Folder Name(1~99); File Name(1~255)
delay(1000);
myDFPlayer.enableLoopAll(); //loop all mp3 files.
delay(1000);
myDFPlayer.disableLoopAll(); //stop loop all mp3 files.
delay(1000);
myDFPlayer.playMp3Folder(4); //play specific mp3 in SD:/MP3/0004.mp3; File Name(0~65535)
delay(1000);
myDFPlayer.advertise(3); //advertise specific mp3 in SD:/ADVERT/0003.mp3; File Name(0~65535)
delay(1000);
myDFPlayer.stopAdvertise(); //stop advertise
delay(1000);
myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(1~10); File Name(1~1000)
delay(1000);
myDFPlayer.loopFolder(5); //loop all mp3 files in folder SD:/05.
delay(1000);
myDFPlayer.randomAll(); //Random play all the mp3.
delay(1000);
myDFPlayer.enableLoop(); //enable loop.
delay(1000);
myDFPlayer.disableLoop(); //disable loop.
delay(1000);
//----Read imformation----
Serial.println(myDFPlayer.readState()); //read mp3 state
Serial.println(myDFPlayer.readVolume()); //read current volume
Serial.println(myDFPlayer.readEQ()); //read EQ setting
Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read file counts in folder SD:/03**/
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)faceplateO) >= 0){
Serial.println("faceplateOpen loaded");
}
if(myVR.load((uint8_t)faceplateC) >= 0){
Serial.println("faceplateClose loaded");
}
if(myVR.load((uint8_t)youthere) >= 0){
Serial.println("Jarvis you there loaded");
}
}
void loop()
{
int ret;
ret = myVR.recognize(buf, 50);
if (ret > 0) {
switch (buf[1]) {
case faceplateO:
/** turn on LED */
Servo1.write(0);
myDFPlayer.playFolder(15, 2);
break;
case faceplateC:
/** turn off LED*/
//digitalWrite(led, LOW);// led is disabled
Servo1.write(90);
myDFPlayer.playFolder(15, 1);
break;
case youthere:
/** turn off LED*/
Servo1.write(170);
myDFPlayer.playFolder(15, 3);
default:
Serial.println("Record function undefined");
break;
}
/** voice recognized */
printVR(buf);
}
}
