VRbot + RF module using Arduino

Hi,
I am trying to recognize words using the VR Shield, and send a character through the RF module. I am using the virtual wire 1.9 library for the RF module.
The VR Shield stops working when I setup the RF module using the command: vw_setup(2000);
Is it because VR Bot is using up all the pins on my Arduino?
Can any one suggest me a solution?

#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round

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

//Groups and Commands
enum Groups
{
  GROUP_1  = 1,
};

enum Group1 
{
  G1_ON = 0,
  G1_OFF = 1,
  G1_NIKHIL = 2,
};


EasyVRBridge bridge;

int8_t group, idx;

void setup()
{
  // bridge mode?
  pinMode(11, OUTPUT);
  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)
  
  // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for RF Link module
    //vw_setup(2000);                 // Bits per sec
    vw_set_tx_pin(3);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs. 
  
}

void action();

void loop()
{
  //const char *msg1 = "A";//message to be sent
  //const char *msg2 = "B";
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
  group = 1;
  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(idx == 0)
    digitalWrite(11,HIGH);
    else if(idx == 1) digitalWrite(11,LOW);
    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_1:
      switch (idx)
      {
      case G1_ON:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        //const char *msg1 = "A";//message to be sent
        digitalWrite(11,HIGH);
        break;
      case G1_OFF:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        digitalWrite(11,LOW);
        break;
      case G1_NIKHIL:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    }
}

test2.ino (2.93 KB)

Links to the hardware in question will be needed in order to answer your questions. It is unlikely that the shield uses ALL the pins. Using some of the pins that the VirtualWire library defaults to IS a possibility. Fortunately, VirtualWire can use any two pins.

The vr bot module has been connected to the 434MHz RF transmitter through the 3rd pin, the photo of which has been attached.
Note that the jumper on the vr bot module is set to MS(and not PC).

The jumper appears to be in the SW position, which means that the shield is using pins 12 and 13 to communicate with the Arduino. The radio appears to be connected to pin 3.

The virtual wire library defaults to pins 10, 11, and 12. So, the use of pin 12 is in conflict. Which explains your problem. Even though you are not using the tx pin to transmit, you still need to tell the virtual wire instance to use another pin, and you need to do that BEFORE you tell the EasyVR shield to use pins 12 and 13.

Thanks. This solved my problem. :slight_smile: