error on led control with xbee

I try to do led control with xbee, my transmitter and receiver codes are as you see below.
In monitoring window i have problem on the side of receiver. Can you help me?

transmitter:

#if defined(ARDUINO) && ARDUINO >= 100

  #include "Arduino.h"

  #include "Platform.h"

  #include "SoftwareSerial.h"

#ifndef CDC_ENABLED

  // Shield Jumper on SW

  SoftwareSerial port(12,13);

#else

  // Shield Jumper on HW (for Leonardo)

  #define port Serial1

#endif

#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_0  = 0,
  GROUP_1  = 1,
};


enum Group0 
{
  G0_OPTIMUS = 0,
};

enum Group1 
{
  G1_LEDON = 0,
  G1_LEDOFF = 1,
};



EasyVRBridge bridge;



int8_t group, idx;



void setup()

{
#ifndef CDC_ENABLED

  // bridge mode?

  if (bridge.check())

  {

    cli();

    bridge.loop(0, 1, 12, 13);

  }

  // run normally

  Serial.begin(9600);

  Serial.println("Bridge not started!");

#else

  // bridge mode?

  if (bridge.check())

  {

    port.begin(9600);

    bridge.loop(port);

  }

  Serial.println("Bridge connection aborted!");

#endif

  port.begin(9600);



  while (!easyvr.detect())

  {

    Serial.println("EasyVR not detected!");

    delay(1000);

  }



  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)

    {

      Serial.print("Error ");

      Serial.println(err, HEX);

    }

  }

}



void action()

{

    switch (group){
    
    case GROUP_0:
      switch (idx){
        case G0_OPTIMUS:
          Serial.write(port.write('a'));
          group = GROUP_1; // <-- or jump to another group X for composite commands
          break;
        }
    break;
    
    case GROUP_1:
      switch (idx){
        case G1_LEDON:
          Serial.write(port.write('b'));
          group = GROUP_1;
          break;
        case G1_LEDOFF:
          Serial.write(port.write('c'));
          group = GROUP_0;
          break;
      }
      break;
    }

}

receiver:

void setup()
{
  pinMode(13,OUTPUT);
  Serial.begin(9600);
}

void loop(){
  while (Serial.available()>0) {
  int inByte = Serial.read();  
    switch(inByte){
      case 97:
        Serial.println("Say 'Optimus' to start!");
        break; 
      case 98:
        Serial.println("Led is ON");
        digitalWrite(13,HIGH);
        delay(3000); 
        break;      
      case 99:
        Serial.println("Led is OFF");  
        digitalWrite(13,LOW);
        delay(3000);
        break; 
    }
  }    
}

this is just happening on receiver monitoring.

Say ‘Optimus’ to start!
Say ‘Optimus’ to start!
Say ‘Optimus’ to start!
Say ‘Optimus’ to start!
Led is OFF
Say ‘Optimus’ to start!
Say ‘Optimus’ to start!
Say ‘Optimus’ to start!
Say ‘Optimus’ to start!
Led is OFF

You need to provide a lot more information. What kinds of XBees are you using? How are they connected to the Arduino(s)? Which Arduino(s)?

What are the arguments to bridge.loop()? The last two are the same as the SoftwareSerial instance pins. Is that correct?

What IS the problem?

I am using:

EasyVR Shield 2.0; for voice recognition,
Arduino Uno; for EasyVR
XBEE2; connected UNO; http://www.jayconsystems.com/timage/Jaycon_Systems_xbee2_wire2.png
Arduino MEGA2560; for control devices like led.
XBEE2; connected MEGA.

for UNO part 5V and GND are connected. RX to TX and TX to RX connected.
for MEGA part as well as same. moreover, led connected to pin 13.

"What are the arguments to bridge.loop()?" i dont have info about this.

thanks.

It appears that you are using the Serial port on the UNO to talk to the XBee AND the PC. How is the XBee supposed to know what to transmit and what to ignore?

Why isn't the voice recognition shield on the Mega?

          Serial.write(port.write('a'));

WTF? The write() method returns the number of bytes sent. How is sending THAT to the serial port useful?

You still have not explained what the problem is.

First, to be honest i am new for such a thing.
Xbees are communicate each other thanks to XCTU program.
UNO is super suitable for EasyVR.

i wrote this because

Serial.write(port.write('a'));

on receiver part, i guess it is reading serial thing.

  while (Serial.available()>0) {
  int inByte = Serial.read();  
    switch(inByte)

and my problem is that i didnt send data to receiver.

and my problem is that i didnt send data to receiver.

How is the UNO supposed to get data to the XBee?
What data is the UNO supposed to get to the XBee?

I supposed that xbees are using rx tx connections to get data and communicate. I expect from Xbee connected UNO send this "Serial.write(port.write('a'));" and MEGA get that 'a' and do operation on led.

I supposed that xbees are using rx tx connections to get data and communicate.

You are sending a lot of data to the RX/TX pins (the Serial instance). How is the XBee supposed to know what to transmit and what to ignore?

You really should have a software serial port set up to talk to the XBee. But, since you are using a software serial port to talk to the VR shield, using another one to talk to the XBee isn’t practical.

That’s why it makes more sense to have the VR shield and XBee on the Mega, with its 4 hardware serial ports.

I expect from Xbee connected UNO send this “Serial.write(port.write(‘a’));” and MEGA get that ‘a’ and do operation on led.

port.write() is sending the letter ‘a’ to the VR shield. I can’t imagine why. The method call returns the number of characters written to the (software) serial port (1). Why would you want to send that value to the XBee, to be transmitted to the other XBee?

You are sending a lot of data to the RX/TX pins (the Serial instance). How is the XBee supposed to know what to transmit and what to ignore?

I really don't know how can i tell this to XBee.

You really should have a software serial port set up to talk to the XBee. But, since you are using a software serial port to talk to the VR shield, using another one to talk to the XBee isn't practical.

That's why it makes more sense to have the VR shield and XBee on the Mega, with its 4 hardware serial ports.

I didn't realize that before so thank you for the info i immediately change UNO as MEGA.

Why would you want to send that value to the XBee, to be transmitted to the other XBee?

I actually would like to send my data to other arduino. While doing that i want to see what is happening using serial monitoring. It is obvious that i messed up to send and get data using codes.

Thanks a lot.

I really don't know how can i tell this to XBee.

The point is that you can't.

#if defined(ARDUINO) && ARDUINO >= 100

  #include "Arduino.h"

  #include "Platform.h"

  #include "SoftwareSerial.h"
SoftwareSerial mySerial(18, 19); // RX, TX

#ifndef CDC_ENABLED

  // Shield Jumper on SW

  SoftwareSerial port(12,13);

#else

  // Shield Jumper on HW (for Leonardo)

  #define port Serial1

#endif

#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_0  = 0,
  GROUP_1  = 1,
};


enum Group0 
{
  G0_OPTIMUS = 0,
};

enum Group1 
{
  G1_LEDON = 0,
  G1_LEDOFF = 1,
};



EasyVRBridge bridge;



int8_t group, idx;



void setup()

{
#ifndef CDC_ENABLED

  // bridge mode?

  if (bridge.check())

  {

    cli();

    bridge.loop(0, 1, 12, 13);

  }

  // run normally

  Serial.begin(9600);

  Serial.println("Bridge not started!");

#else

  // bridge mode?

  if (bridge.check())

  {

    port.begin(9600);

    bridge.loop(port);

  }

  Serial.println("Bridge connection aborted!");

#endif

  port.begin(9600);
  mySerial.begin(9600);


  while (!easyvr.detect())

  {

    Serial.println("EasyVR not detected!");

    delay(1000);

  }



  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)

    {

      Serial.print("Error ");

      Serial.println(err, HEX);

    }

  }

}



void action()

{

    switch (group){
    
    case GROUP_0:
      switch (idx){
        case G0_OPTIMUS:
          mySerial.write('a');
          group = GROUP_1; // <-- or jump to another group X for composite commands
          break;
        }
    break;
    
    case GROUP_1:
      switch (idx){
        case G1_LEDON:
          mySerial.write('b');
          group = GROUP_1;
          break;
        case G1_LEDOFF:
          mySerial.write('c');
          group = GROUP_0;
          break;
      }
      break;
    }

}

i changed transmitter part of my code like above. first thing that i confused is SoftwareSerial port(12,13); if that represent rx tx for mega rx tx numbers for vr 0 and 1.

now i wrote mySerial.write(‘a’); means i send the data xbee to send other xbee.

but i still have something incorrect.

Do not try to do SoftwareSerial on the hardware serial pins. Just use Serial1 in place of the software serial instance.

How can i do that? Can you lead me a little?

yubb:
How can i do that? Can you lead me a little?

Here's a start:

~~ #include "SoftwareSerial.h"~~
SoftwareSerial mySerial(18, 19); // RX, TX

#ifndef CDC_ENABLED
~~ // Shield Jumper on SW~~
~~ SoftwareSerial port(12,13);~~
#else
~~ // Shield Jumper on HW (for Leonardo)~~

#define port Serial1

#endif
Be sure that the VR shield is connected to the Serial1 pins.

You'll need to call Serial1.begin() in setup, too.

You'll also need to call Serial2.begin() and be sure that the XBee is connected to the Serial2 pins.

First, PaulS thank you for replies.

I puted EasyVR on mega where rx0 and tx0 are used. That’s why Serial port for EasyVR and Serial 1 which are pin 18 and 19 for Xbee. Then i arranged the code but i confuse about receiving part.

#if defined(ARDUINO) && ARDUINO >= 100

  #include "Arduino.h"

  #include "Platform.h"
  
  #define port Serial
  #define port Serial1


#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_0  = 0,
  GROUP_1  = 1,
};


enum Group0 
{
  G0_OPTIMUS = 0,
};

enum Group1 
{
  G1_LEDON = 0,
  G1_LEDOFF = 1,
};



EasyVRBridge bridge;



int8_t group, idx;



void setup()

{
#ifndef CDC_ENABLED

  // bridge mode?

  if (bridge.check())

  {

    cli();

    bridge.loop(0, 1, 12, 13);

  }

  // run normally

  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Bridge not started!");

#else

  // bridge mode?

  if (bridge.check())

  {

    port.begin(9600);

    bridge.loop(port);

  }

  Serial.println("Bridge connection aborted!");

#endif

  port.begin(9600);


  while (!easyvr.detect())

  {

    Serial.println("EasyVR not detected!");

    delay(1000);

  }



  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)

    {

      Serial.print("Error ");

      Serial.println(err, HEX);

    }

  }

}



void action()

{

    switch (group){
    
    case GROUP_0:
      switch (idx){
        case G0_OPTIMUS:
          Serial1.write('a');
          group = GROUP_1; // <-- or jump to another group X for composite commands
          break;
        }
    break;
    
    case GROUP_1:
      switch (idx){
        case G1_LEDON:
          Serial1.write('b');
          group = GROUP_1;
          break;
        case G1_LEDOFF:
          Serial1.write('c');
          group = GROUP_0;
          break;
      }
      break;
    }

}
void setup()
{
  pinMode(8,OUTPUT);
  Serial1.begin(9600);
}

void loop(){
  while (Serial1.available()>0) {
  int inByte = Serial1.read();  
    switch(inByte){
      case 97:
        Serial1.println("Say 'Optimus' to start!");
        break; 
      case 98:
        Serial1.println("Led is ON");
        digitalWrite(8,HIGH);
        delay(3000); 
        break;      
      case 99:
        Serial1.println("Led is OFF");  
        digitalWrite(8,LOW);
        delay(3000);
        break; 
    }
  }    
}

error for receiver part {even though i write #define Serial1 before void setup() }

reciever.ino: In function ‘void setup()’:
reciever:27: error: ‘Serial1’ was not declared in this scope
reciever.ino: In function ‘void loop()’:
reciever:31: error: ‘Serial1’ was not declared in this scope
‘Serial1’ was not declared in this scope

  #define port Serial
  #define port Serial1

A #define statements creates a name = value pair. Your second statement trashes your first one.

Your receiver is not a Mega, anymore, is it? It is now the Uno, which only has one hardware serial port.

A #define statements creates a name = value pair. Your second statement trashes your first one.

then i updated it like this.

#define port Serial1

Your receiver is not a Mega, anymore, is it? It is now the Uno, which only has one hardware serial port.

You are right my mind is wandering. I tried to do what we discussed but in code it has still softwareserial port parts. and it causes problem.

but in code it has still softwareserial port parts.

You need to get rid of them.

You need to concentrate on one problem at a time.

Start with getting the VR shield to be recognized when it is connected to a hardware serial port.

As you said i focus the problem and setup this code but i’ve “bbbbEasyVr not detected” warning.
Do i miss something? I really cant realize it.

  #include "Arduino.h"
  #include "Platform.h"
  #define port Serial
  #define com Serial1
  #include "EasyVR.h"
  EasyVR easyvr(port);
  
//Groups and Commands
enum Groups{
  GROUP_0  = 0,
  GROUP_1  = 1,
};
enum Group0{
  G0_OPTIMUS = 0,
};
enum Group1{
  G1_LEDON = 0,
  G1_LEDOFF = 1,
};

EasyVRBridge bridge;
int8_t group, idx;

void setup(){
#ifndef CDC_ENABLED
  // bridge mode?
  if (bridge.check()){
    cli();
    bridge.loop(0, 1, 12, 13);
  }
  // run normally
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Bridge not started!");
#else
  // bridge mode?
  if (bridge.check()) {
    port.begin(9600);
	com.begin(9600);
    bridge.loop(port);
  }
  Serial.println("Bridge connection aborted!");
#endif

  port.begin(9600);
  com.begin(9600);
  while (!easyvr.detect()) {
    Serial.println("EasyVR not detected!");
    delay(1000);
  }
  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){
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
  }
}

void action(){
    switch (group){
    
      case GROUP_0:
        switch (idx){
          case G0_OPTIMUS:
            Serial1.write('a');
            group = GROUP_1; // <-- or jump to another group X for composite commands
            break;
          }
        break;
    
      case GROUP_1:
        switch (idx){
          case G1_LEDON:
            Serial1.write('b');
            group = GROUP_1;
            break;
          case G1_LEDOFF:
            Serial1.write('c');
            group = GROUP_0;
            break;
        }
      break;
    }
}
    bridge.loop(0, 1, 12, 13);

You MUST look at the documentation for this function, to see what the arguments are. You have not changed these, even though the shield is now (supposedly) connected to different pins.