Dear ALL
I am doing my senor year project and I am working on an arduino uno and an easy vr board along with a servo motor HS755 .
i tried to turn servo motor but it refused to work and the COM window(serial monitor) of the arduino asks for command from group 0 and I give it but it stops right there.
However when I unplug the servo motor, the COM window (serial monitor )asks me to say the commands as it is supposed to do if servo motor is plugged ( asking for a command from group 0 then a command for group 1 ) and when i dont give it a command it keep asking for it the command on and on.
PS: I already tried a code on a LED and it worked perfectly .
this is the motor Code:
#include "Servo.h"
#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"
Servo myservo;
EasyVR easyvr(port);
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_ARDUINO = 0,
};
enum Group1
{
G1_UN= 0,
G1_DEUX = 1,
};
EasyVRBridge bridge;
int servo_pos ;
int8_t group, idx;
void setup()
{
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
// run normally
Serial.begin(9600);
port.begin(9600);
myservo.attach(9);
if (!easyvr.detect())
{
Serial.println("EasyVR not detected!");
for (;;);
}
easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.print("EasyVR detected, version ");
Serial.println(easyvr.getID());
easyvr.setTimeout(5);
easyvr.setLanguage(0);
group = EasyVR::TRIGGER;
}
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)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_ARDUINO:
// write your action code here
group = GROUP_1;
// group = GROUP_X; <– or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_UN:
group = GROUP_0; //<-- or jump to another group X for composite commands
servo_pos -= 8;
//servo_pos--;
myservo.write(servo_pos); // set the LED on
group = GROUP_0;
// write your action code here
// group = GROUP_X; <– or jump to another group X for composite commands
break;
case G1_DEUX:
group = GROUP_0; //<-- or jump to another group X for composite commands
servo_pos+=1;
myservo.write(servo_pos);
group = GROUP_0;
// write your action code here
// group = GROUP_X; <– or jump to another group X for composite commands
break;
}
break;
}
}