need help : project voice recognition module and bluetooth with arduino mega

Dear All ,

I am in great trouble , I need assistance as soon as possible, and need help quickly

I work on a project with a arduino mega , with voice recognition module and bluetooth .

my problem

When you run full code, the voice recognition module and Bluetooth never work.(all never work , but the connection power is ok But without responding )

When you run each separate code that works normally, or when you hide the following sentence myVR.begin(9600); BT.begin(9600); , the voice recognition module segment works but does not respond to commands

code bluetooth :

#include <SoftwareSerial.h>
SoftwareSerial BT(52,53);

void setup()
{

pinMode(13, OUTPUT);
BT.begin(9600);
}

char a;
void loop()
{
if (BT.available())
{
a=(BT.read());
switch (a)
{
case 'A' : {digitalWrite(13, HIGH); }break ;
case 'B' : {digitalWrite(13, LOW); }break ;

}}}

code : voice recognition module (The commands were recorded in the past and are working correctly)

#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"

VR myVR(10,11); // 10:RX 11:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

int led = 13;

#define onRecord (0)
#define offRecord (1)

void printSignature(uint8_t buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf_>0x19 && buf
<0x7F){_
_ Serial.write(buf);
}
else{
Serial.print("[");
Serial.print(buf, HEX);
Serial.print("]");
}
}
}
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);
_

* Serial.begin(115200);*
* Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");*

* pinMode(led, OUTPUT);*

* 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)onRecord) >= 0){
_ Serial.println("onRecord loaded");
}*_

* if(myVR.load((uint8_t)offRecord) >= 0){
_ Serial.println("offRecord loaded");
}
}
void loop()
{
int ret;
ret = myVR.recognize(buf, 50);
if(ret>0){
switch(buf[1]){
case onRecord:
/** turn on LED /
digitalWrite(led, HIGH);

* break;
case offRecord:
/** turn off LED/

* digitalWrite(led, LOW);
break;
default:
Serial.println("Record function undefined");
break;
}
/** voice recognized /
printVR(buf);

* }
}
all code (but not working)
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
SoftwareSerial BT(52,53);
VR myVR(10,11); // 10:RX 11:TX, you can choose your favourite pins.
uint8_t records[7]; // save record
uint8_t buf[64];
#define onRecord (0)
#define offRecord (1)
void printSignature(uint8_t *buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf>0x19 && buf<0x7F){
Serial.write(buf);
}
else{
Serial.print("[");
Serial.print(buf, HEX);
Serial.print("]");
}
}
}
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()
{

pinMode(13, OUTPUT);
BT.begin(9600);
/** initialize /
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)onRecord) >= 0){
_ Serial.println("onRecord loaded");
}*_

* if(myVR.load((uint8_t)offRecord) >= 0){
_ Serial.println("offRecord loaded");
}
}
char a;
void loop()
{
int ret;
ret = myVR.recognize(buf, 50);
if(ret>0){
switch(buf[1]){
case onRecord:
/** turn on LED /
digitalWrite(13, HIGH);

* break;
case offRecord:
/** turn off LED/

* digitalWrite(13, LOW);
break;
default:
Serial.println("Record function undefined");
break;
}
/** voice recognized /
printVR(buf);

* }*_

* if (BT.available())*
* {*
* a=(BT.read());*
* switch (a)*
* {*
case 'A' : {digitalWrite(13, HIGH); }break ;
case 'B' : {digitalWrite(13, LOW); }break ;

* }}}*

I am in great trouble , I need assistance as soon as possible, and need help quickly

wow that sounds so bad you could not take the time to read the rules on how to post here...

You are probably trying to use 2 SoftwareSerial Ports at the same time and that's not a great idea.

See the documentation

Limitations

The library has the following known limitations:
If using multiple software serial ports, only one can receive data at a time.
...

As you get an arduino with multiple Hardware Serial ports like a mega --> use those, or attach at least one of the module to the hardware Serial line and your life will be easier

What do you think is the solution ?
I'm in big trouble
This is the final code he used.

#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
SoftwareSerial BT(52,53);

VR myVR(10,11); // 10:RX 11:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

#define onRecord (0)
#define offRecord (1)

void printSignature(uint8_t *buf, int len)
{
int i;
for(i=0; i<len; i++){
if(buf>0x19 && buf<0x7F){
Serial.write(buf);
}
else{
Serial.print("[");
Serial.print(buf, HEX);
Serial.print("]");
}
}
}

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()
{

pinMode(13, OUTPUT);
BT.begin(9600);
/** initialize */
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)onRecord) >= 0){
Serial.println("onRecord loaded");
}

if(myVR.load((uint8_t)offRecord) >= 0){
Serial.println("offRecord loaded");
}
}

char a;
void loop()
{
int ret;
ret = myVR.recognize(buf, 50);
if(ret>0){
switch(buf[1]){
case onRecord:
/** turn on LED /
digitalWrite(13, HIGH);
break;
case offRecord:
/
* turn off LED*/
digitalWrite(13, LOW);
break;
default:
Serial.println("Record function undefined");
break;
}
/** voice recognized */
printVR(buf);
}

if (BT.available())
{
a=(BT.read());
switch (a)
{
case 'A' : {digitalWrite(13, HIGH); }break ;
case 'B' : {digitalWrite(13, LOW); }break ;

}}}

What do you think is the solution ?

Go read how to use the forum please.

Okay ,

I do not want a solution to the problem, but I want help where I look or search for a solution ??

I'll provide a hint if you fix all your posts by adding code tags :slight_smile:

J-M-L:
You are probably trying to use 2 SoftwareSerial Ports at the same time and that's not a great idea.

Indeed, and since a Mega has four hardware serial ports, it is a very bad one.

The problem has been resolved

1 Like

Qusaialhaj:
The problem has been resolved

No... all your post are still looking ugly....