Pages: [1]   Go Down
Author Topic: First Arduino + EasyVR project - Need Help Please  (Read 4602 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

#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);         
    }
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

anybody?
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1). What is an Easyvr?, and 2). did you do a google search of the forum for Easyvr?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

California
Offline Offline
God Member
*****
Karma: 14
Posts: 629
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


0
Offline Offline
Full Member
***
Karma: 2
Posts: 213
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!!!!!!!!!!
Logged

California
Offline Offline
God Member
*****
Karma: 14
Posts: 629
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In commander and PC jumper, it actually recognizes your voice and highlights the appropriate command?
Logged


Pages: [1]   Go Up
Jump to: