-1

I am using the EasyVR Arduino Shield with Uno.

What i am trying to do is train a custom phrase like a name.

I want to be able to train the phrase directly with arduino whilst it is not connected a pc. I have noticed in the documentation there are some references to commands like it, but i'm not sure how to go around writing code for such a thing.

thank you

1

Hi a bit late but I thought it could be useful to someone, I successed to train SD commands without pc easyvr commander with this code:

// ARDUINO 1.6.6
// EasyVR Shield 2.0
// EasyVR library v1.7

#include "Arduino.h"
#if !defined(SERIAL_PORT_MONITOR)
#error "Arduino version not supported. Please update your IDE to the latest version."
#endif

#define pcSerial SERIAL_PORT_MONITOR

#include "SoftwareSerial.h"
SoftwareSerial port(12, 13);

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

//

char label[33];
uint8_t data;

bool train = false;
bool recog = false;

int8_t group = EasyVR::PASSWORD;
int8_t index = 0;

void setup()
{
  pcSerial.begin(9600);
  port.begin(9600);

  while (!easyvr.detect())
  {
    pcSerial.println(F("EasyVR not detected!"));
    delay(1000);
  }

  //

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  pcSerial.print(F("EasyVR detected, version "));
  pcSerial.println(easyvr.getID());
  easyvr.setTimeout(5);
  //  easyvr.setLevel(EasyVR::HARD);

  //

  printCommands();
}

void printCommands()
{
  pcSerial.print(F("Password: "));
  int16_t count = easyvr.getCommandCount(group);
  pcSerial.print(count);
  pcSerial.println(F(" command(s)"));
  for (int8_t idx = 0; idx < count; ++idx) {
    if (easyvr.dumpCommand(group, idx, label, data)) {
      pcSerial.print(idx);
      pcSerial.print(F(" = "));
      pcSerial.print(label);
      pcSerial.print(F(", Trained "));
      pcSerial.print(data, DEC);
      if (!easyvr.isConflict()) pcSerial.println(F(" times, OK"));
    }
  }
}

bool checkMonitorInput()
{
  if (pcSerial.available() <= 0) return false;

  int16_t rx = pcSerial.read();
  //  pcSerial.print(rx);

  if (rx == 's')
  {
    easyvr.removeCommand(group, index);
    easyvr.addCommand(group, index);
    easyvr.setCommandLabel(group, index, "cuss");

    printCommands();
  }

  if (rx == 't')
  {
    recog = false;
    pcSerial.print("say something");
    train = true;
  }

  if (rx == 'r')
  {
    train = false;
    pcSerial.print("start recognition");
    recog = true;
  }

  //

  if (rx >= 0)
  {
    easyvr.stop();
    pcSerial.flush();
    return true;
  }
  return false;
}

void loop()
{
  checkMonitorInput();

  if (train) {
    pcSerial.println("Train a word");
    easyvr.trainCommand(group, index);
  }

  if (recog) {
    pcSerial.println("Say the word");
    easyvr.recognizeCommand(group);
  }

  //

  do {
    if (checkMonitorInput()) return;
  }
  while (!easyvr.hasFinished());

  //

  int16_t idx = easyvr.getCommand();
  if (idx >= 0) {
    if (easyvr.dumpCommand(EasyVR::PASSWORD, idx, label, data)) {
      pcSerial.print("recognized = ");
      pcSerial.println(label);
    }
    easyvr.playSound(0, EasyVR::VOL_FULL);

  } else {
    if (easyvr.isTimeout()) pcSerial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0) {
      pcSerial.print("Error 0x");
      pcSerial.println(err, HEX);
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.