Pages: [1] 2 3   Go Down
Author Topic: Voice Recognition Module programming issue  (Read 4782 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Guys
I bought a voice recognition from ebay for about $25 so far im very happy with the performance with regards to recognizing words recorded , the only problem I find is that i can not seem to get a action to be processed from a  word being said, and i have track the problem down to my comparison coding.

below is the code
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
int ledPin = 0;
int redPin = 11; // R petal on RGB LED module connected to digital pin 11
int greenPin = 9; // G petal on RGB LED module connected to digital pin 9
int bluePin = 10; // B petal on RGB LED module connected to digital pin 10
byte com = 0; //reply from voice recognition

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);

pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
delay(1000);
mySerial.write(0xAA);
mySerial.write(0x21);
delay(1000);
}

void loop() // run over and over again
{

while(mySerial.available())
{
com = Serial.write(mySerial.read());
switch(com)
{
case 0x11:
color(255,255,255); // turn RGB LED on -- white
break;

case 0x12:
color(255, 0, 0); // turn the RGB LED red
break;

case 0x13:
color(0,255, 0); // turn the RGB LED green
break;

case 0x14:
color(0, 0, 255); // turn the RGB LED blue
break;

case 0x15:
color(0,0,0); // turn the RGB LED off
break;

}
}

}

void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, red*102/255);
analogWrite(bluePin, blue*173/255);
analogWrite(greenPin, green*173/255);
}

I have added software serial library to the code because i wanted to see if i get my commands into the arduino from the voice module and it works.
the problem area i think is the next few lines.
Code:
while(mySerial.available())
{
com = Serial.write(mySerial.read());
switch(com)
{
case 0x11:
color(255,255,255); // turn RGB LED on -- white
break;

case 0x12:
color(255, 0, 0); // turn the RGB LED red
break;

case 0x13:
color(0,255, 0); // turn the RGB LED green
break;

case 0x14:
color(0, 0, 255); // turn the RGB LED blue
break;

case 0x15:
color(0,0,0); // turn the RGB LED off
break;

}

See when you speak into the module it will return the word spoken in a form of "Result:12" or "Result:13" and so on so I try and compare an do a action with a switch/case  so when the module reports "Result:12" the comparison on 0x12 should be made and the red light should switch on.... it doesn't.


any help ?... please
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
com = Serial.write(mySerial.read());
The Serial.write() method returns the number of characters it has written. How is that useful information for switching on?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul

would Serial.println be the correct way then  and not Serial.write? 

Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
would Serial.println be the correct way then
No. The println() method also returns the number of characters it wrote.

It seems to me that you want to do more with the value read from the serial port than just print it. To do that, you need to save the value read in a variable of the correct type, then print that value and switch based on that value.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanx Paul

I see what you are saying but what doesnt makes sence to me then is that the example code that i started with will also not work
original
Code:
void loop() // run over and over again
{

while(Serial.available())
{
com = Serial.read();
switch(com)

and he has videos up on youtube of it working
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your first code was reading from a software serial port and writing to a hardware serial port. This last code has you reading from the hardware serial port. Did you move the VR module? Why?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No The code I posted last is the original code as from the module supplier, the code i posted first is my code modified to work on software serial so i can view serial monitor . but when i first tried with the original code it also didn't work
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand what you are doing. If you didn't move the VR module to the hardware serial pins, how can you expect to read from it?

With the hardware connected to the software serial pins, what are you seeing in the Serial Monitor application?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think we miss understood each other, at first i tried the original code form the supplier which forced me to disconnect the VR module each time i uploaded the code so i added the software serial so i didnt have to anymore , so i moved the pins to the 2,and 3 for software serial. now when i speak into the VR module i get what i expect in the serial monitor . when i say any of the given 5 words i get "Result: 11" "Result :12" exc. so the software serial read works fine . its just the comparison that doesn't seem to work.

here is the link to the manual and product page (scross down)
http://www.ebay.com/itm/Voice-Recognition-Module-Arduino-Compatible-Control-your-devices-by-voice-/140613022031?pt=LH_DefaultDomain_0&hash=item20bd30714f 

http://www.elechouse.com/elechouse/images/product/Voice%20Recognition%20Module/Manual.pdf
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so the software serial read works fine . its just the comparison that doesn't seem to work.
Show the Serial Monitor output, please.

The reason that the comparison doesn't work is because you are comparing the wrong things. What the code you first posted compares is the number of characters written to the serial monitor to some values. None of them match, of course. because each call to Serial.write(), Serial.println(), or Serial.print() with an int writes or prints different numbers of characters, depending on the value being printed. "1" has one character. "102<cr><lf>" is 5 characters. None of the values returned by the serial output methods has anything to do with the value that was put on the port - only the number of characters involved.

What it appears that you need to do is to read AND STORE data from the software serial port, until an end of packet marker (what that would be requires some discovery on your part - possibly a <cr> or and <lf>) and then compare that stored value to some known strings, using strcmp().

In the middle of the 3rd page, there is mention of compact mode. In this mode, the device will return 0x11 or 0x12 corresponding to "Result: 11" or "Result: 12". Dealing with one byte will be far easier than dealing with a string.

I'd look into what it takes to get the module into compact mode.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay this toke me while now.

when the VR module is in common mode i get the following in Serial monitor

Group1 Imported !
Common Mode
Result:12
Result:14
Result:11
Result:13
Result:15
Result:12

then When in Compact mode I get



thats all  even when i speak there is no other output on the serial monitor

Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

UPDATE: the " Ì " is HEX for "cc" whichin compact mode means " successfully setup compact mode"
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul

thanx for your help I got the unit to work as intended , and i let the supplier know that there example code does not work, next step is to program a better library to be able to do word learning via arduino without a PC

will post a video later when in better working order
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I got the unit to work as intended
That's great.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 132
http://roverduino.blogspot.com/ http://uhebeuav.co.za
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul

Im onto the next issue now but im looking for an idea of how to do it rather then a the way im doing it now.

there is two things i need help with.

1) i have my VR module now truning on a LED when i say "red" and they off when i say " off" but this takes up an extra command for one action as in on and of for one LED , i want to do StateChangeDetection with the word "red" so when i say red the led goes high and when i say red again the "led" goes "low" my problem is the statechangedetection reads from a pin which i dont have in the software. how do i go about this ? i know i can run a wire from the red light to another input and just read the input if its high or low but thats wasting pins.

2) How do i program the unit to go into a specific Case and stay looping in that case untill i give it a command to exit back to the main program? currently it keeps reverting back to the top of the code.
Logged

He who does not try ,does not fail ,does not learn not to fail again http://powerduino.blogspot.com/

Pages: [1] 2 3   Go Up
Jump to: