Arduino Uno - error msg: expected initializer before 'bridge' - plus another sim

Using EasyVR, I got a program off the internet, to turn an LED off, and on, with voice commands.
Compiling gave many error messages, and I was able to correct them all, except the following two:

  • expected initilalizer before 'bridge'

  • In function 'void setup()': 'bridge was not declared in this scope

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
	SoftwareSerial port(12,13);
#endif
	
  #include "EasyVR.h"
	
EasyVR easyvr(port);

//Groups and Commands
enum Groups
{  
  GROUP_0 = 0,
	GROUP_1 = 1,
	}
	
enum Group0
{
  G0_ARDUINO = 0,	
}
	
enum Group1
{
  G1_LED_AN = 0,
	G1_LED_AUS = 1,
}

EasyVRBridge bridge;
int8_t group, idx;

void setup()
{
  // bridge mode?
	if (bridge.check())

I have searched in the forum for "expected initializing before ..." and found nothing helpful but,
as I am new to this, I may easily have overlooked something.

Any suggestions appreciated.
Thanks,
Don Oliver

Hi,
There is a library dedicated to EasyVR and in this library 2 classes are defined

  • EasyVR and
  • EasyVRBridge

Therefore you have to include the file EasyVRBridge.h and
add create the object bridge with the following line:
EasyVRBridge bridge;

Take care as I'm not familiar with this library, maybe additional parameters are needed

Hope this will help

You don't have semicolons on your enum statements.

enum Groups
{  
  GROUP_0 = 0,
	GROUP_1 = 1,
	}
	
enum Group0
{
  G0_ARDUINO = 0,	
}
	
enum Group1
{
  G1_LED_AN = 0,
	G1_LED_AUS = 1,
}

GDV0:
Hi,
There is a library dedicated to EasyVR and in this library 2 classes are defined

  • EasyVR and
  • EasyVRBridge

Therefore you have to include the file EasyVRBridge.h and
add create the object bridge with the following line:
EasyVRBridge bridge;

Take care as I'm not familiar with this library, maybe additional parameters are needed

Hope this will help

Thanks for your answer.
Two things:

  • I included EasyVRBridge.h, and still get the same error message.
  • TestEasyVR.pde does not include this file, and works perfectly

Don

dxw00d:
You don't have semicolons on your enum statements.

enum Groups


  GROUP_0 = 0,
GROUP_1 = 1,
}

enum Group0
{
  G0_ARDUINO = 0,
}

enum Group1
{
  G1_LED_AN = 0,
G1_LED_AUS = 1,
}

I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???

Thanks, Don

dayo30:
I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???

Thanks, Don

You believe wrongly then. You need a semicolon after the closing curly brace on each one.

I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???

How long would it have taken to test?

dxw00d:

I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???

How long would it have taken to test?

Thanks for the replies.
You are right, of course, I should have tried it.
So, today I did, and got the error message: "expected identifier before ';' token" on each one.
The original errors,regarding 'bridge', however, did not show.

I did not make the program, I am only trying to run it.

As I said, I am new to this, so maybe did not do it correctly?

Modified code:

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

enum Group0
{
  G0_ARDUINO = 0,
};

enum Group1
{;
  G1_LED_AN = 0,
	G1_LED_AUS = 1,
};

As I said, I am new to this, so maybe did not do it correctly?

I'm sure that the compiler had something to say about this:

enum Groups
{;

And, I'm sure that it was not "Nice job!".

PaulS:

As I said, I am new to this, so maybe did not do it correctly?

I'm sure that the compiler had something to say about this:

enum Groups {;

And, I'm sure that it was not "Nice job!".

It was not :slight_smile:

As I included in my last message, it said: expected identifier before ';' token

I do not know where to go from here.
Thanks,
Don

I do not know where to go from here.

Perhaps you should look at some code that does compile. You'll notice that there are hardly ever semicolons in the middle of a statement. The sole exception that I can think of is the for statement.

enum Groups
{
  GROUP_0 = 0,
	GROUP_1 = 1,
};

PaulS:

I do not know where to go from here.

Perhaps you should look at some code that does compile. You'll notice that there are hardly ever semicolons in the middle of a statement. The sole exception that I can think of is the for statement.

enum Groups

{
  GROUP_0 = 0,
GROUP_1 = 1,
};

The only examples that I could find, using enum, did not use semicolons.

OK, I changed the section to:

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

enum Group0
{
  G0_ARDUINO = 0,
};

enum Group1
{
  G1_LED_AN = 0,
	G1_LED_AUS = 1,
};

Now, it compiles, and runs, without error but, instead of the Serial Monitor displaying "Say a command in Group 0", then Group1, Group2,
it just displays "Say a command in Group"

The TestEasyVR program, which similar, but does not use enum, runs perfectly.
It uses the following instead:

EasyVR easyvr(port);

int8_t set = 0;
int8_t group = 0;
uint32_t mask = 0;  
uint8_t train = 0;
char name[32];
bool useCommands = true;

EasyVRBridge bridge;

It seems to me that my problem is with the use of enum?

Thanks to all for your patience,
Don

Now, it compiles, and runs, without error but, instead of the Serial Monitor displaying "Say a command in Group 0", then Group1, Group2,
it just displays "Say a command in Group"

You have not posted all of your code, so it is impossible to say what is wrong.

It seems to me that my problem is with the use of enum?

An enum is simply a way of assigning names to numbers, and using the names in place of the numbers, is cases where names make more sense. For instance, the days of the week are either Sunday, Monday, Tuesday, etc. or 0, 1, 2, etc. If you want to remember that Thursday is equal to 4, that's fine, but most people would rather use a name.

So, it is unlikely that your problem is with the use of enum. It is more likely that your problem is with the misuse of enum.

So, it is unlikely that your problem is with the use of enum. It is more likely that your problem is with the misuse of enum.

I believe that you may be right, but I find it confusing.

You have not posted all of your code, so it is impossible to say what is wrong.

Complete code:

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
	SoftwareSerial port(12,13);
#endif
	
#include "EasyVR.h"
	
EasyVR easyvr(port);

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

enum Group0
{
  G0_ARDUINO = 0,
};

enum Group1
{
  G1_LED_AN = 0,
	G1_LED_AUS = 1,
};

EasyVRBridge bridge;
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);
	
	if (!easyvr.detect())
	{
	  Serial.println("EasyVR not detected!"); 
		for (;;);
	}
	
	easyvr.setPinOutput(EasyVR::IO1, LOW);
	Serial.println("EasyVR detected!");
	easyvr.setTimeout(5);
	easyvr.setLanguage(3);
	
	group = EasyVR::TRIGGER; // -- start group (customize)
	
	pinMode(11, OUTPUT);
	digitalWrite(11, LOW);  // set the LED off
	
}

void action ();

void loop()
{
  easyvr.setPinOutput(EasyVR::IO1, HIGH);  // LED on (listening)
	
	Serial.print("Say a command in 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);
		  }
			
			group = GROUP_0;
		}
	}
	
	void action()
	{
		switch (group) 
	  {
		case GROUP_0:
		  switch (idx)
			{
			case G0_ARDUINO:
			  // write your action code here
				  group = GROUP_1; // -- or jump to another group X for composite command
				break;
			case GROUP_1:
			  switch (idx)
				{
				case G1_LED_AN:
				  // write your action code here
					group = GROUP_0; //-- or jump to another group X for composite command
					
					digitalWrite(11, HIGH); // set the LED on
					
					break;
				case G1_LED_AUS:
				  // write your action code here
					group = GROUP_0; //	- or jump to another group X for composite command
					digitalWrite(11, LOW);  //set the LED off
					
					break;
				}
				break;
			}								
	  }
	}

it just displays "Say a command in Group"

That's because that is what you told it to do:

	Serial.print("Say a command in Group");
	easyvr.recognizeCommand(group);

group was initialized to 0. I'm not sure what this function does, but it seems to me that the value passed in would be an index into a 2D array of words that the thing is supposed to compare what it hears to.

	if (idx = 0)
	if (idx = 0)
	{
			if (err  = 0)
			{

These are assignments, not equality tests. The result of the assignment is 0 (false), so the if test never evaluates to true.

PaulS,

I think that the problem could be here:

	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)

Where // group = GROUP_X; -- jump to another group X
is commented out, so nothing happens.

In any case, GROUP_X is not defined anywhere.

Trying to debug someone elses code is maybe too difficult for a beginner.
I will try to find another example, to do the same thing, that works,
so that I can follow the logic, before going further with this now.

Thanks very much for your patience and your help.,
Don