Pages: [1]   Go Down
Author Topic: Ethernet shield and mega 2560 + Easy Vr Module  (Read 751 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all the assistance I received so far.

Good day I am having problems getting the Easyvr module working on any other port than 12 & 13 on the Mega.I need the ports for the ethernet shield.
The problem is my code works fine on the Uno on almost any port I specify (Have used port 13 & 13 / 9 & 8 / 2 & 3 / all works.
I am using the module not the shield so I can basically use any combination I wan't.
Have anyone been able to get easyvr working on other pins on the mega.(cant use pin 9 on the mega as it is reserved for IR).

It is the 1s time I am using the Mega, am I understanding the board wrong, so you use the pin assignment printed on the board or do you uses the pin names ie PG5 for digital pin 4. 

I have used the easyvr test demo and the generated sketch both work on uno and on pin 13 & 12 on mega.
 
Code:
#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13); // Tested on uno port 2 & 3 / 8 & 9 / 12 & 13 all works | Mega only 12 & 13 seems to work.
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);// Tested on uno port 2 & 3 / 8 & 9 / 12 & 13 all works | Mega only 12 & 13 seems to work.
#endif

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

//Groups and Commands
enum Groups
{
  GROUP_0  = 0,
  GROUP_1  = 1,
  GROUP_2  = 2,
};

enum Group0
{
  G0_COMPUTER = 0,
};

enum Group1
{
  G1_TV_ON_OFF = 0,
  G1_LIGHT_ON_OFF = 1,
  G1_FAN_PM_OFF = 2,
  G1_STORE_LIGHT = 3,
  G1_ALL_OFF = 4,
  G1_SABC = 5,
  G1_XBMC = 6,
  G1_DSTV = 7,
  G1_MACTION = 8,
  G1_KYKNET = 9,
  G1_NICOLADION = 10,
  G1_ETV = 11,
  G1_DISC = 12,
  G1_NAGEO = 13,
  G1_FTV = 14,
  G1_SLEEP = 15,
  G1_BATHROOM = 16,
  G1_KITCHEN = 17,
  G1_LOUNGE = 18,
  G1_PROJECTROR = 19,
  G1_OUTSIDE = 20,
};

enum Group2
{
  G2_15MIN = 0,
  G2_30MIN = 1,
  G2_60MIN = 2,
  G2_ONE = 3,
  G2_TWO = 4,
  G2_THREE = 5,
  G2_MOVIE = 6,
  G2_TV = 7,
  G2_OFF = 8,
};


EasyVRBridge bridge;

int8_t group, idx;

void setup()
{
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);// Tested on uno port 2 & 3 / 8 & 9 / 12 & 13 all works | Mega only 12 & 13 seems to work.
  }
  // 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)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
  }
}

void action()
{
    switch (group)
    {
    case GROUP_0:
      switch (idx)
      {
      case G0_COMPUTER:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    case GROUP_1:
      switch (idx)
      {
      case G1_TV_ON_OFF:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_LIGHT_ON_OFF:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_FAN_PM_OFF:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_STORE_LIGHT:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_ALL_OFF:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_SABC:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_XBMC:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_DSTV:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_MACTION:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_KYKNET:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_NICOLADION:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_ETV:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_DISC:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_NAGEO:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_FTV:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_SLEEP:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_BATHROOM:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_KITCHEN:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_LOUNGE:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_PROJECTROR:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G1_OUTSIDE:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    case GROUP_2:
      switch (idx)
      {
      case G2_15MIN:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_30MIN:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_60MIN:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_ONE:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_TWO:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_THREE:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_MOVIE:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_TV:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      case G2_OFF:
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      }
      break;
    }
}

Anyone managed to get the EasyVr working on the mega on pins other than 12 & 13

Any assistance would be apreciated

Thanks
Logged

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

Thanks I solved it

The software serial library was the issue.



http://arduino.cc/en/Reference/SoftwareSerial
"Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)."

so I can use most of the analogue pins in my application.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Good day I am having problems getting the Easyvr module working on any other port than 12 & 13 on the Mega.I need the ports for the ethernet shield.
The SPI pins, used by the Ethernet shield are not on pins 12 and 13 on the Mega.

Quote
The software serial library was the issue.
No. Your insistence on using software serial on a device with 4 hardware serial ports, and then using it incorrectly, is.
Logged

Pages: [1]   Go Up
Jump to: