Please Help friend,
I am trying to connect two serial communication device (voice recognition and Bluetooth) so for that, I am using Altsofserial (8,9) pin for Bluetooth and Softserial (2,3) pin for voice recognition.
here I am attaching my code,
#include<AltSoftSerial.h>
#include "VoiceRecognitionV3.h"
AltSoftSerial BTSerial(8,9);
VR myVR(2,3); // you can any pin for VR Module
int led1;
int led2;
int led;
String BTS;
char inchar;
String string;
String onchar;
#define OnRecord (0)
#define OffRecord (1)
/**
Connection
Arduino VoiceRecognitionModule
2 -------> TX
3 -------> RX
*/
uint8_t records[7]; // save record
uint8_t buf[64];
/**
@brief Print signature, if the character is invisible,
print hexable 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 > 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() {
myVR.begin(9600);
//BTSerial.begin(9600);
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
string.reserve(200);
Serial.begin(15200);
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("startRecord loaded");
}_
if (myVR.load((uint8_t)OffRecord) >= 0) {
_ Serial.println("endRecord loaded");
}
}
int VRy()
{
int ret;
ret = myVR.recognize(buf, 50);
if (ret > 0) {//checks for incoming voice input*
* switch (buf[1]) {
case OnRecord://the functions to be performed when I say "on"
OnRecord;
// displaySensor();
return 0;
break;
case OffRecord://the functions to be performed when I say "off"
OnRecord;
//display.clearDisplay();//clears display*
* // display.display();
return 1;
break;
default:
Serial.println("Record function undefined");
break;
exit(1);
}
//printVR(buf);
}
else if (OnRecord)
return 2;
}
void loop() {
// put your main code here, to run repeatedly:*
int result = VRy();_
delay(500);
* Serial.print(result);*
* //Dspi();*
}
void Dspi(){
* if (BTSerial.available()) //checks for incoming data*
* {*
* inchar = BTSerial.read();*
* if (inchar != '\n' && inchar != '\r' )*
* {*
* string += inchar;*
* }*
* if (inchar == '\r')*
* {*
*// *
// display.display();
* string = " ";*
* }*
* }*
}
The code is running properly but the problem is in serial monitor its showing garbage value like (please check the attachement .
but if I remove the Bluetooth function from void dispi...then serial printer showing proper result