Go Down

Topic: First Arduino + EasyVR project - Need Help Please (Read 5 times) previous topic - next topic

scorpi00n

Hi, ive been fiddling around with my Arduino and Easyvr for a few nights but am facing some problems.
All im trying to do is give digital pin 12 an output of either high or low and the easyvr starts listening again for the next command.

I want to control some light with this as I also have a relay for it to turn on and off. But all this code does at the moment is turns the relay off and wont listen to any more commands.

Im not asking for a whole arduino tutorial or anything, just for someone to give me a kick start on how to get this to work.

Heres the code;
Code: [Select]


#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif

#include "EasyVR.h"
#include <Servo.h>

#define SND_Access_denied            1
#define SND_Access_granted           2
#define SND_Hello                    3
#define SND_Please_repeat            4
#define SND_Yess_boss                6
#define SND_Please_talk_louder       5

Servo myservo;
int ledPin = 13;
int relayPin = 12;
EasyVR easyvr(port);
EasyVRBridge bridge;

uint32_t mask = 0;
int8_t group = 0;
uint8_t train = 0;
char name[32];


void setup()
{
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
 
 
  Serial.begin(9600);
  port.begin(9600);
 
 
  myservo.attach(9);
  myservo.write(90); 
 
  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(EasyVR::ITALIAN);
 
 
  int16_t count = 0;
 
 
  if (easyvr.getGroupMask(mask)) // get trained user names and passwords
  {
    uint32_t msk = mask; 
    for (group = 0; group <= EasyVR::PASSWORD; ++group, msk >>= 1)
    {
      if (!(msk & 1)) continue;
      if (group == EasyVR::TRIGGER)
        Serial.print("Trigger: ");
      else if (group == EasyVR::PASSWORD)
        Serial.print("Password: ");
      else
      {
        Serial.print("Group ");
        Serial.print(group);
        Serial.print(": ");
      }
      count = easyvr.getCommandCount(group);
      Serial.println(count);
      for (int8_t idx = 0; idx < count; ++idx)
      {
        if (easyvr.dumpCommand(group, idx, name, train))
        {
          Serial.print(idx);
          Serial.print(" = ");
          Serial.print(name);
          Serial.print(", Trained ");
          Serial.print(train, DEC);
          if (!easyvr.isConflict())
            Serial.println(" times, OK");
          else
          {
            int8_t confl = easyvr.getWord();
            if (confl >= 0)
              Serial.print(" times, Similar to Word ");
            else
            {
              confl = easyvr.getCommand();
              Serial.print(" times, Similar to Command ");
            }
            Serial.println(confl);
          }
        }
      }
    }
  }
  easyvr.setLevel(EasyVR::HARDER);
  easyvr.playSound(SND_Hello, EasyVR::VOL_FULL);
}

void loop()
{
  int idx_cmd;
  int idx_pwd;
 
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
 
  Serial.println("Say a name in Group 1"); 
  easyvr.recognizeCommand(1); // recognise command in group 1
  while (!easyvr.hasFinished()); // wait for user name
 
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx_cmd = easyvr.getCommand(); // get recognised user name

  if (idx_cmd >= 0)
  {   
    Serial.print("Name: ");   
    if (easyvr.dumpCommand(1, idx_cmd, name, train))
      Serial.println(name);
    else
      Serial.println();   
   
    easyvr.playSound(SND_Yess_boss , EasyVR::VOL_FULL);  // ask for password
   
    easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening) 
   
    Serial.println("Say the password");   
    easyvr.recognizeCommand(EasyVR::PASSWORD); // set group 16
    while (!easyvr.hasFinished()); // wait for password
 
    easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off   
   
    idx_pwd = easyvr.getCommand(); // get recognised password
   
    if (idx_pwd >= 0)
    {
      Serial.print("Password: ");     
     
      if (easyvr.dumpCommand(EasyVR::PASSWORD, idx_pwd, name, train))
      {
        Serial.print(" = ");
        Serial.println(name);
      }
      else
        Serial.println();     
     
      if ( idx_pwd == idx_cmd) // index of username and password are the same, access granted
      {

        Serial.println("Access granted");
        easyvr.playSound(SND_Access_granted , EasyVR::VOL_FULL);   
        pinMode(relayPin, OUTPUT);
       
        digitalWrite(ledPin, HIGH); // set the LED pin High
        digitalWrite(relayPin, LOW); // set the relay pin High
       
     
       
        }
      else // index of username and password differ, access is denied
      {
        Serial.println("Access denied");
        easyvr.playSound(SND_Access_denied , EasyVR::VOL_FULL);
           
      }
     
    }   
   
    int16_t err = easyvr.getError();
   
    if (easyvr.isTimeout() || (err >= 0)) // password timeout, access is denied
    {
     
      Serial.println("Error, try again...");
      easyvr.playSound(SND_Please_talk_louder , EasyVR::VOL_FULL);
     
    }
  }
 
  else
  {
    if (easyvr.isTimeout())
        Serial.println("Timed out, try again...");
     
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);         
    }
  }
}


zoomkat

1). What is an Easyvr?, and 2). did you do a google search of the forum for Easyvr?
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Steg

Hey scorpi00n,
I have just started a first project with both Arduino and EasyVR. Im not to the level yet to where I can look at a code and tell you whats what lol.
But heres my code, maybe it will help out a bit.
Code: [Select]
#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif

#include "EasyVR.h"
EasyVR easyvr(port);

#define SND_COMMANDERROR    1

//Groups and Commands
int count = 0;
int pin7 = 7;
int pin8 = 8;
int pin4 = 4;
int val;
enum Groups
{
  GROUP_0  = 0,
  GROUP_1  = 1,
};

enum Group0
{
  G0_COMPUTER = 0,
};

enum Group1
{
  G1_KITCHEN = 0,
  G1_LIVINGROOM = 1,
};


EasyVRBridge bridge;

int8_t group, idx;

void setup()
{
  pinMode(pin8, OUTPUT);
  pinMode(pin4, OUTPUT);
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
  // run normally
  Serial.begin(9600);
  port.begin(9600);

  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(0);

  group = EasyVR::TRIGGER; //<-- start group (customize)
}

void action();

void loop()
{
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
  Serial.print("Say a command in Group ");
  Serial.println(group);
  easyvr.recognizeCommand(group);

  do
  {
    // can do some processing while waiting for a spoken command
  }
  while (!easyvr.hasFinished());
 
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx = easyvr.getWord();
  if (idx >= 0)
  {
    // built-in trigger (ROBOT)
    // group = GROUP_X; <-- jump to another group X
    return;
  }
  idx = easyvr.getCommand();
  if (idx >= 0)
  {
    // print debug message
    uint8_t train = 0;
    char name[32];
    Serial.print("Command: ");
    Serial.print(idx);
    if (easyvr.dumpCommand(group, idx, name, train))
    {
      Serial.print(" = ");
      Serial.println(name);
    }
    else
      Serial.println();
    easyvr.playSound(0, EasyVR::VOL_FULL);
    // perform some action
    action();
  }
  else // errors or timeout
  {
    if (easyvr.isTimeout())
      Serial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      count++;
      easyvr.playSound(1, EasyVR::VOL_FULL);
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
    if (count == 3)     //if 3 errors are sent do something
    {
      group = GROUP_0;
      switch (idx)
      {
        case G0_COMPUTER:
        group = GROUP_1;
      }
      count = 0;
    }
  }
}

void action()
{
    switch (group)
    {
    case GROUP_0:
      switch (idx)
      {
      case G0_COMPUTER:
        group = GROUP_1;
       
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_KITCHEN:
        group = GROUP_0;
        val = digitalRead(pin8);
        if (val == LOW)
        {
          digitalWrite(pin8, HIGH);
        }
         else
         {
           digitalWrite(pin8, LOW);
         }
          count = 0;         
        break;
      case G1_LIVINGROOM:
        group = GROUP_0;
        val = digitalRead(pin4);
        if (val == LOW)
        {
          digitalWrite(pin4, HIGH);
        }
        else
        {
          digitalWrite(pin4, LOW);
        }
        count = 0;
        break;
      }
      break;
    }
}


This program will turn (livingroom, kitchen) lights on or off. Both can be on at the same time. If 3 errors are accumulated, it will got back to GROUP_0 (trigger).

I guess my first question is did you generate the code in EasyVR Commander?

Steg

Oh and pay no attention to my ( int pin7 = 7; ). Its no longer in use.

Neo22

Is it necessary to use "aurdino shield" with easyVR bot to connect it to aurdino board plz help

spcomputing


Is it necessary to use "aurdino shield" with easyVR bot to connect it to aurdino board plz help


Nope, just power, D12 and D13.  Some just like the convenience of a shield.
http://www.spcomputing.com

nytro81

hi, can you help me? i can't try my easyvr shield with arduino... in commander, with jumper in pc position it's all ok, but when i try to test it on arduino, set the jumper on sw position, load the easyvr test sketch from examples, on serial monitor says "easyvr not detect!" What can be wrong!?!?!? Please heeeeellllllllp!!!!!!!!!!!

spcomputing

In commander and PC jumper, it actually recognizes your voice and highlights the appropriate command?
http://www.spcomputing.com

michael004

sir, I'm using EasyVR in my current project. What is the purpose of this code? newbie in EasyVR



EasyVRBridge bridge;

int8_t group, idx;

void setup()
{
  pinMode(pin8, OUTPUT);
  pinMode(pin4, OUTPUT);
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
  // run normally
  Serial.begin(9600);
  port.begin(9600);

  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(0);

  group = EasyVR::TRIGGER; //<-- start group (customize)
}

void action();

void loop()
{
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
  Serial.print("Say a command in Group ");
  Serial.println(group);
  easyvr.recognizeCommand(group);

  do
  {
    // can do some processing while waiting for a spoken command
  }
  while (!easyvr.hasFinished());
 
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx = easyvr.getWord();
  if (idx >= 0)
  {
    // built-in trigger (ROBOT)
    // group = GROUP_X; <-- jump to another group X
    return;
  }
  idx = easyvr.getCommand();
  if (idx >= 0)
  {
    // print debug message
    uint8_t train = 0;
    char name[32];
    Serial.print("Command: ");
    Serial.print(idx);
    if (easyvr.dumpCommand(group, idx, name, train))
    {
      Serial.print(" = ");
      Serial.println(name);
    }
    else
      Serial.println();
    easyvr.playSound(0, EasyVR::VOL_FULL);
    // perform some action
    action();
  }
  else // errors or timeout
  {
    if (easyvr.isTimeout())
      Serial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      count++;
      easyvr.playSound(1, EasyVR::VOL_FULL);
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
    if (count == 3)     //if 3 errors are sent do something
    {
      group = GROUP_0;
      switch (idx)
      {
        case G0_COMPUTER:
        group = GROUP_1;
      }
      count = 0;

MikeTate

Hi all! New to Arduino, EasyVR, and this forum. First post :)

I'm not sure if any problems above have been solved but after a few days of trouble shooting and almost returning my EasyVR Shield 2.0(because I could not get my EasyVR to connect to Commander no matter what i tried) I finally found that my problem was that I was trying to run everything within a 64 bit version of Windows 7 inside a VMware virtual machine inside of my Mac. Now I don't know if it's supposed to run fine on a 64 bit Windows platform on a PC, but for me it only worked once I installed a 32 bit version of Windows 7 inside VMware inside of my Mac. Once I installed a 32 bit version everything was fine. I am finally up and running and on my way to learning both platforms :)

I hope this helps someone who was having problems connecting to Commander like I was.

I'm totally new to all of this and I just thought I'd share some help before I start asking for it.
Because I most definitely will be soon.

Cactusface

Hi,
     Windows  in VMware on a Mac! Oh so slow, and yes Virtual, not real, real ports etc. I dual boot Windows-7 on my Mac as I need Windows (Soryy to say, as I hate it) for PCB cad, etc.

Regards

Mel..
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

Go Up