Reputation: 101
The Bluetooth module(HC-05)and voice recognition module (V 3.1) work individually just fine with Arduino Uno but when I try to run them together then the one of them stops working that is the voice module stops working. I have't been able to figure out why. My code is as follows:
# include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
VR myVR(2,3); // 2:RX 3:TX
uint8_t buf[64];
SoftwareSerial bluetooth(4,5); //for Bluetooth module RX FOLLOWD BY TX
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]);
}
}
}
void setup() {
pinMode(A4,OUTPUT);// for VCC of voice module
digitalWrite(A4,HIGH);
myVR.begin(9600);
Serial.begin(9600);
myVR.load((uint8_t)0); //loading the data of voice module
myVR.load((uint8_t)1);
myVR.load((uint8_t)2);
myVR.load((uint8_t)3);
myVR.load((uint8_t)4);
bluetooth.begin(9600);
}
String one;
void loop() {
int ret = myVR.recognize(buf, 50);
if (bluetooth.available() > 0) {
one = bluetooth.readString();
Serial.println(one);
}
if (ret > 0) {
Serial.print("Voice module said ");
printSignature(buf+4, buf[3]); //priting the signature of command
Serial.println(""); //for new line
}
}
1)The problem is in communication because when I remove myVR.begin(9600) then bluetooth works and voice module does not.
2)when I remove bluetooth.begin(9600) then voice module works and bluetooth does not.
together they are not working ,only one works.
Upvotes: 0
Views: 374
Reputation: 1592
VoiceRecognitionV3
inherits SoftwareSerial
. It is possible to have multiple SoftwareSerial
instances in a program. However, only one can receive data at a time. So, you want to switch between your ports with listen()
(doc).
portOne.listen();
ret = portOne.read();
portTwo.listen();
ret = portTwo.read();
The Arduino site has an example. https://www.arduino.cc/en/Tutorial/TwoPortReceive
Upvotes: 1