Pages: 1 [2] 3   Go Down
Author Topic: Voice Recognition Module programming issue  (Read 4793 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
If you are referring to an example called "StateChangeDetection", the pin doesn't matter.

All you need to do is keep track of whether the red LED is on or off. When you get a "red", change the state to the other state, and write the new state to the red LED's pin.

Quote
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.
We'd need to see your code. You can define loops in a case, but you must provide a way for that loop to end.
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

okay iv had a rethink on the way i want the VR module code to work. in the manual it states that the VR unit can handle 3 groups of 5 words each , and only one group can be used at a time, this seems like an issue but it is not, see i have desided to break my code into 3 groups.

group 1 is environmental group ie which room in the house do i want to control ,

group 2 is for which appliance in that room do i want to select

group 3 is the control action i want to apply to that appliance.

currently i have all 3 groups in a switch case , but because i can only have one group imported at a time only that words that imported works out of the whole switch case.

in my code below i used "bar" in group 1  "lights" in group 2 and "start" in group 3
so what should happen is i call out "bar lights start" and the bar lights should switch on, now my problem is when i declare in setup what the bar lights pin is it does switch on as intended and off but because i want to use group 3 as a control group of words, the pinout  must be vairable and be int. each time I enter that appliance void function. I have tried creating a global vairable called " int SwitchPin = Pin; " and "int Pin =0;" then when i enter group 2 "lights" in the lights void i " int Pin =9; " and then when i say "start" it should switch on ... it doesnt
Code:
#include <SoftwareSerial.h> // use for software serial tobe able to monitor serial output will speaking into the VR module
                   
SoftwareSerial mySerial(2, 3); // RX, TX software serial pin selection

// Variables declaration
int SwitchPin = Pin;
int Pin = 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

// Program Setup
void setup()
{
  // Serial communication Speed
  Serial.begin(38400);
  mySerial.begin(38400);

 // PinMode declaration
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
pinMode(Pin,OUTPUT);

 //Device Setup via AT commands
    delay(1000);
  mySerial.write(0xAA);
  mySerial.write(0x37); // Switch module into compact mode
    delay(1000);
  mySerial.write(0xAA);
  mySerial.write(0x21); // Import Group1 of 5 words
      delay(1000);
}

// Program starts

void loop()
{ while(mySerial.available())
{ com =  mySerial.read();
     Serial.println(com,HEX);
     switch(com)
// Rooms
{
  case 0x11:
break;
  case 0x12:
break;
  case 0x14:
break;
  case 0x13:
break;
  case 0x15:
    barGroup(); // turn the RGB LED off
break;

// Appliance
  case 0x31:
    Serial.println("BAR");
break;
  case 0x32:
    Serial.println("lights");
    lights();
break;
  case 0x33:
    Serial.println("Garage");
break;
  case 0x34:
    Serial.println("Music");
break;
  case 0x35:
    Serial.println("Strobe");
   
// Control
break;
  case 0x21:
    Serial.println("start");
  Start();
break;
  case 0x22:
    Serial.println("off");
break;
  case 0x23:
    Serial.println("dim");
break;
  case 0x24:
    Serial.println("stop");
break;
  case 0x25:
    Serial.println("all off");
    off();
break;

}
}
}


void barGroup()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
      delay(1000);
       Serial.println("bargroup activated");
      while(mySerial.available())
     { com =  mySerial.read();
      Serial.println("reading serail");
      Serial.println(com,HEX);
     }}
     
void CtrlGroup()

  mySerial.write(0xAA);
  mySerial.write(0x22); // Import Group2 of 5 words
      delay(1000);
       Serial.println("controls activated");
      while(mySerial.available())
     { com =  mySerial.read();
      Serial.println("reading serail");
      Serial.println(com,HEX);
     }

  }
void Start()
{
   digitalWrite(SwitchPin,HIGH);
}

void off()
{
   digitalWrite(SwitchPin,LOW);
}

void lights()
{
int Pin = 9;
 
  CtrlGroup();
}



 


how do i create function that switches pin outs for a function like start() and Stop()
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

LOL murhpy is a bastard , as i finished posting i found the answer
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: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
as i finished posting i found the answer
But, you don't want to share it?
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

yes i will just want to finish it for all 5 groups ,  question when im a switch case and i want to reset to go back to the main loop is there a Arduino function to reset the code or go back to the start ?
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

got the answer , by sending
 mySerial.write(0xAA);
  mySerial.write(0x21); // Import Group1 of 5 words
      delay(500);

i directly kick the loop back to the first group of words  so the above is in a void called exit() and exit is one of the commands in the 3 group of words
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

90% finished code its working but needs cleaning up 


#include <SoftwareSerial.h> // use for software serial tobe able to monitor serial output will speaking into the VR module
                   
SoftwareSerial mySerial(2, 3); // RX, TX software serial pin selection

// Variables declaration

int Pin;
int redPin = 9;   // R petal on RGB LED module connected to digital pin 11
int greenPin = 8;  // G petal on RGB LED module connected to digital pin 9
int bluePin = 7;  // B petal on RGB LED module connected to digital pin 10
int barPin =  11;
int lightPin =  12;
int garagePin = 10;
int musicPin = 6;
int strobePin = 5;
byte com = 0;      // Reply from voice recognition

// Program Setup
void setup()
{
  // Serial communication Speed
  Serial.begin(38400);
  mySerial.begin(38400);

 // PinMode declaration
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
pinMode(Pin,OUTPUT);

 //Device Setup via AT commands
  mySerial.write(0xAA);
  mySerial.write(0x37); // Switch module into compact mode
    delay(500);
  mySerial.write(0xAA);
  mySerial.write(0x21); // Import Group1 of 5 words
      delay(1000);
  Serial.println(" Please say which environment you would like to control");
}

// Program starts

void loop()
{ while(mySerial.available())
{ com =  mySerial.read();
     Serial.println(com,HEX);
     switch(com)
/////////////////////////////////////////////////////////////////////////// Rooms set
{
  case 0x11:
  Serial.println("Jarvis");
  jarvis();
break;

  case 0x12:
  Serial.println("Lounge");
   lounge();
break;

  case 0x13:
  Serial.println("Garden");
  garden();
break;

  case 0x14:
  Serial.println("All off");
   all_off();
break;

  case 0x15:
  Serial.println("Bar");
    barGroup(); // turn the RGB LED off
break;

/////////////////////////////////////////////////////////////////////// Appliance  set
  case 0x31:
    Serial.println("BAR");
    Pin = barPin;
    CtrlGroup();
    break;

  case 0x32:
    Serial.println("lights");
    Pin = lightPin;
    CtrlGroup();
   break;
   
   case 0x33:
    Serial.println("Garage");
    Pin = garagePin;
    CtrlGroup();
   
   break;
   case 0x34:
    Serial.println("Music");
    Pin = musicPin;
    CtrlGroup();
   
  break;
  case 0x35:
    Serial.println("Strobe");
    Pin = strobePin;
    CtrlGroup();
    break;
/////////////////////////////////////////////////////////////////////// Control set

  case 0x21:
    Serial.println("started Device");
  Start();
break;
  case 0x22:
    Serial.println("off");
  off();
break;
  case 0x23:
    Serial.println("dim");
    Dim();
break;
  case 0x24:
    Serial.println("stop");
    Stop();
break;
  case 0x25:
    Serial.println("all off");
    off();
break;

}
}
}

//////////////////////////////////////////////Group 1 void functions////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void jarvis()//0x11
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
      delay(1000);
       Serial.println("jarvis selected");
      while(mySerial.available())
     { com =  mySerial.read();
      Serial.print("voice results:");
      Serial.println(com,HEX);
     }}
   
void lounge()//0x12
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
      delay(1000);
       Serial.println("lounge selected");
      while(mySerial.available())
     { com =  mySerial.read();
     Serial.print("voice results:");
      Serial.println(com,HEX);
     }}
     
  void garden()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
      delay(1000);
       Serial.println("Garden selected");
      while(mySerial.available())
     { com =  mySerial.read();
     Serial.print("voice results:");
      Serial.println(com,HEX);
     }}
     
     void all_off()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
      delay(1000);
       Serial.println("all off ");
      while(mySerial.available())
     { com =  mySerial.read();
     Serial.print("voice results:");
      Serial.println(com,HEX);
     }}
   
     
void barGroup()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
      delay(1000);
       Serial.println("bar Selected");
      while(mySerial.available())
     { com =  mySerial.read();
     Serial.print("voice results:");
      Serial.println(com,HEX);
     }}
   
/////////////////////////////////////////////////////////////////Group 2 void functions //////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
void CtrlGroup()

  mySerial.write(0xAA);
  mySerial.write(0x22); // Import Group2 of 5 words
      delay(1000);
       Serial.println("controls active");
      while(mySerial.available())
     { com =  mySerial.read();
     Serial.print("voice results:");
      Serial.println(com,HEX);
     }

  }
 
 


//////////////////////////////////////////////////////////////////////Group 3 void functions /////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void Start()//0x21
{
  Serial.print("output pin :");
  Serial.println(Pin);
   digitalWrite(Pin,HIGH);
}

void off()//0x23 and 0x25
{
   digitalWrite(Pin,LOW);
    mySerial.write(0xAA);
    mySerial.write(0x21); // Import Group1 of 5 words
      delay(500);
}

void Dim()//0x24
{
   analogWrite(Pin,150);// object to be dimmed must be connected to analog pin
}

void Stop()//0x22
{
   digitalWrite(Pin,LOW);
}





 
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: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
90% finished code its working but needs cleaning up 
And to be posted properly. Check out the Tools + Auto Format menu item, too.

Also, take a look at some C or C++ books. There are two main styles concerning placement of open and close curly braces.

Either:
Code:
if(someCondition) {
  // code goes here
}
or, what I prefer:
Code:
if(someCondition)
{
  // code goes here
}

There are no recognized styles that allow for code on the same line as the curly brace, following the curly brace. There are no styles that allow two close braces on the same line, or any that allow the close brace on the same line as any other code.

Whichever style you adopt, apply it consistently. It will make your code easier to read.
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

thanx for the heads up , i was going to do that the last 10% i needed to do. for future is there any advantages of writing code like this other then ease of readability ?
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

a other question that i have that i think you might be the correct person to ask is. is there any difference in  power consumption/cycle time and program size programming in Arduino vs C++ vs  C#?
 so lets say i take a program and write the same program for Arduino C++ and C# which is better to use when speaking in terms of the 3 points of concerns mentioned above ?
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: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
for future is there any advantages of writing code like this other then ease of readability ?
Isn't ease of readability a sufficient goal in and of itself? It certainly is for me. Proper indenting, judicious use of white space, sufficient, but not over use of, comments, consistent naming conventions, etc. can make it easy to remember what code is doing when you look at it again later.

You may not think that that will happen, but I have code I wrote in 2001 that I still look at at least once a month. That class is 14,000 lines long. For me, ease of readability is a huge help in maintaining that code.
Logged

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

Quote
is there any difference in  power consumption/cycle time and program size programming in Arduino vs C++ vs  C#?
Since you can't program the Arduino using C#, this is a rhetorical question. There is an answer, though. By the time the compiler gets done, the object files that the C++, the C, and the C# compiler produce are nearly indistinguishable.

By the time the linker gets done, they hex files are indistinguishable.

So, the language doesn't matter.
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

so having libraries and classes imported via arduino vs writting all the code in C# does not matter at the end of the day the compiled size and performance would be the same . just the compilation would take longer i geuss.
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: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
just the compilation would take longer i geuss.
Yes, it will take longer to compile C# code for the Arduino. First, you need to write the compiler...
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 thank you  Paul.

here is the code again formatted properly.
Code:
#include <SoftwareSerial.h> // use for software serial tobe able to monitor serial output will speaking into the VR module

SoftwareSerial mySerial(2, 3); // RX, TX software serial pin selection

// Variables declaration

int Pin;
int redPin = 9;   // R petal on RGB LED module connected to digital pin 11
int greenPin = 8;  // G petal on RGB LED module connected to digital pin 9
int bluePin = 7;  // B petal on RGB LED module connected to digital pin 10
int barPin =  11;
int lightPin =  12;
int garagePin = 10;
int musicPin = 6;
int strobePin = 5;
byte com = 0;      // Reply from voice recognition

// Program Setup
void setup()
{
  // Serial communication Speed
  Serial.begin(38400);
  mySerial.begin(38400);

  // PinMode declaration
  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
  pinMode(Pin,OUTPUT);

  //Device Setup via AT commands
  mySerial.write(0xAA);
  mySerial.write(0x37); // Switch module into compact mode
  delay(500);
  mySerial.write(0xAA);
  mySerial.write(0x21); // Import Group1 of 5 words
  delay(1000);
  Serial.println(" Please say which environment you would like to control");
  Serial.println(" Jarvis,Lounge,Garden,Bar ");

}

// Program starts

void loop()
{
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.println(com,HEX);
    switch(com)
      /////////////////////////////////////////////////////////////////////////// Rooms set
    {
    case 0x11:
      Serial.println("Jarvis");
      jarvis();
      break;

    case 0x12:
      Serial.println("Lounge");
      lounge();
      break;

    case 0x13:
      Serial.println("Garden");
      garden();
      break;

    case 0x14:
      Serial.println("All off");
      all_off();
      break;

    case 0x15:
      Serial.println("Bar");
      barGroup(); // turn the RGB LED off
      break;

      /////////////////////////////////////////////////////////////////////// Appliance  set
    case 0x31:
      Serial.println("BAR");
      Pin = barPin;
      CtrlGroup();
      break;

    case 0x32:
      Serial.println("lights");
      Pin = lightPin;
      CtrlGroup();
      break;

    case 0x33:
      Serial.println("Garage");
      Pin = garagePin;
      CtrlGroup();

      break;
    case 0x34:
      Serial.println("Music");
      Pin = musicPin;
      CtrlGroup();

      break;
    case 0x35:
      Serial.println("Strobe");
      Pin = strobePin;
      CtrlGroup();
      break;
      /////////////////////////////////////////////////////////////////////// Control set

    case 0x21:
      Serial.println("started Device");
      Start();
      break;
    case 0x22:
      Serial.println("off");
      off();
      break;
    case 0x23:
      Serial.println("dim");
      Dim();
      break;
    case 0x24:
      Serial.println("stop");
      Stop();
      break;
    case 0x25:
      Serial.println("all off");
      off();
      break;

    }
  }
}

//////////////////////////////////////////////Group 1 void functions/////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void jarvis()//0x11
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
  delay(1000);
  Serial.println("jarvis selected");
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.print("voice results:");
    Serial.println(com,HEX);
    Serial.println(" Please say which Appliance you would like to control");
    Serial.println("Options: Lights, BAR lights,Garage door, Music, Strobe ");
  }
}

void lounge()//0x12
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
  delay(1000);
  Serial.println("lounge selected");
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.print("voice results:");
    Serial.println(com,HEX);
    Serial.println(" Please say which Appliance you would like to control");
    Serial.println("Options: Lights, Music, Strobe ");
  }
}

void garden()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
  delay(1000);
  Serial.println("Garden selected");
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.print("voice results:");
    Serial.println(com,HEX);
    Serial.println(" Please say which Appliance you would like to control");
    Serial.println("Options: Lights,pool light,Garage door, Music ");
  }
}

void all_off()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
  delay(1000);
  Serial.println("all off ");
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.print("voice results:");
    Serial.println(com,HEX);
  }
}


void barGroup()
{
  mySerial.write(0xAA);
  mySerial.write(0x23); // Import Group3 of 5 words
  delay(1000);
  Serial.println("bar Selected");
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.print("voice results:");
    Serial.println(com,HEX);
    Serial.println(" Please say which Appliance you would like to control");
    Serial.println("Options: Lights, Pool table lights,Garage door, Music, Strobe ");
  }
}

/////////////////////////////////////////////////////////////////Group 2 void functions /////////////////////////////////////////////
////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////

void CtrlGroup()
{  
  mySerial.write(0xAA);
  mySerial.write(0x22); // Import Group2 of 5 words
  delay(1000);
  Serial.println("controls active");
  while(mySerial.available())
  {
    com =  mySerial.read();
    Serial.print("voice results:");
    Serial.println(com,HEX);
  }

}
//////////////////////////////////////////////////////////////////////Group 3 void functions ////////////////////////////////////////
////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////

void Start()//0x21
{
  Serial.print("output pin :");
  Serial.println(Pin);
  digitalWrite(Pin,HIGH);
}

void off()//0x23 and 0x25
{
  digitalWrite(Pin,LOW);
  mySerial.write(0xAA);
  mySerial.write(0x21); // Import Group1 of 5 words
  delay(500);
}

void Dim()//0x24
{
  analogWrite(Pin,150);// object to be dimmed must be connected to analog pin
}

void Stop()//0x22
{
  digitalWrite(Pin,LOW);
}



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: