Problem in verify / compile a "test" with amarino.

Hello everyone... I'm new on arduino and I'm trying to create a project with a BTmodule using the amarino(http://www.amarino-toolkit.ne).
I'm following a tutorial in amarino's webpage but when I verify or compile the code in arduino IDE have a problem:

In file included from Test.cpp:6:
C:\arduino-1.0\libraries\MeetAndroid/MeetAndroid.h:104: error: conflicting return type specified for 'virtual void MeetAndroid::write(uint8_t)'
C:\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

Code in arduino IDE is:

/*
  Receives Test Events from your phone.
  After it gets a test message the led 13 will blink.
*/
 
#include <MeetAndroid.h>

MeetAndroid meetAndroid;
int onboardLed = 13;

void setup()  
{
  // use the baud rate your bluetooth module is configured to 
  // not all baud rates are working well, i.e. ATMEGA168 works best with 57600
  Serial.begin(57600); 
  
  // register callback functions, which will be called when an associated event occurs.
  // - the first parameter is the name of your function (see below)
  // - match the second parameter ('A', 'B', 'a', etc...) with the flag on your Android application
  meetAndroid.registerFunction(testEvent, 'A');  

  pinMode(onboardLed, OUTPUT);
  digitalWrite(onboardLed, HIGH);

}

void loop()
{
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
}

/*
 * This method is called constantly.
 * note: flag is in this case 'A' and numOfValues is 1 (since test event sends a random int)
 */
void testEvent(byte flag, byte numOfValues)
{
  // the test event in Amarino generates a random value between 0 and 255
  int randomValue = meetAndroid.getInt();
  
  flushLed(300);
  flushLed(300);
  flushLed(randomValue);
}

void flushLed(int time)
{
  digitalWrite(onboardLed, LOW);
  delay(time);
  digitalWrite(onboardLed, HIGH);
  delay(time);
}

If someone know... help me to solve it plx!
Thx everyone and sorry my english! :slight_smile:

EDIT: I try with IDE 022 and 1.0... In 022 was show me more errors... in 1.0 was only this post.

Better edit MeetAndroid.h and at around line 104 change the return type for MeetAndroid::write from void to size_t.

Hello Nick.
Thanks for your help, but I don'r understand it so good... in line 104 I have:

102 - void getDoubleValues(float[]); // in Arduino double and float are the same
103 - 
104 - void write(uint8_t);
105 - 
106 - void send(char);

What's about "write from void to size_t" ?

Thx!

Right there on line 104, it says that write()'s return type is void. It isn't supposed to be void, anymore. It is now supposed to be size_t.

Don't forget that the function is supposed to actually return a meaningful value, too.

Hey PaulS thx man!
So I have that change "void" for a type "size_t" ?
size_t is a type like void, int, float ?

And my line 104 will be like:
104 - void size_t(uint8_t);
?

Thx!

So I have that change "void" for a type "size_t" ?

Yes. That's what you've been told several times now.

size_t is a type like void, int, float ?

Yes.

And my line 104 will be like:

No. You need to change the return type, not the function name.

Sorry PaulS, I wrote it wrong...
Will be: size_t write(uint8_t);
?

Thx for ur patience! :l

Will be: size_t write(uint8_t);

Yes.

You need, of course, to make a corresponding change to the source file and add a return statement to the function.

I try run it and IDE show me a long list of errors...
Can you give me a sample of add a return statement to the function?
Infinitely grateful!

I try run it and IDE show me a long list of errors...
Can you give me a sample of add a return statement to the function?

Post the code you modified.

Adding a return statement is trivial.

size_t write(uint8_t val)
{
// Do something with val
return 1;
}

Edit: this code is from librarie MeetAndroid_h if a send to u the code that IDE is trying compile u can try run in your pc and look if it works?

the code is:

#ifndef MeetAndroid_h
#define MeetAndroid_h

#include <inttypes.h>
#include "Print.h"


/******************************************************************************
* Definitions
******************************************************************************/

class MeetAndroid : public Print

{
#define ByteBufferLenght 64
#define FunctionBufferLenght 75 // 48-122 (in ascii: 0 - z)
#define FunctionBufferOffset 48  // offset to calc the position in the function buffer ('0' should be stored in intFunc[0])
#define _MEET_ANDROID_VERSION 2 // software version of this library
private:
	// per object data
	uint8_t bufferCount;
	uint8_t buffer[ByteBufferLenght];
	
	int numberOfValues;
	
	char abord;
	char ack;
	char delimiter;
	char startFlag; // used to communicate with Android (leads each msg to Android)
	
	bool customErrorFunc;

	typedef void (*H_voidFuncPtr)(uint8_t, uint8_t);
	H_voidFuncPtr intFunc[FunctionBufferLenght];
	H_voidFuncPtr errorFunc;

	// static data

	// private methods
	void processCommand(void);
	void init(void);
	int getArrayLength();

public: 
	// public methods
	MeetAndroid(H_voidFuncPtr err);
	MeetAndroid(void);
	
	void flush(void);
	bool receive(void);
	void registerFunction(void(*)(uint8_t, uint8_t),uint8_t);
	void unregisterFunction(uint8_t);
	int bufferLength(){return bufferCount;} // buffer withouth ACK
	int stringLength(){return bufferCount;} // string without flag but '/0' at the end
	void getBuffer(uint8_t[]);
	
	void getString(char[]);
	int getInt();
	long getLong();
	float getFloat();
	double getDouble();
	void getIntValues(int[]);
	void getFloatValues(float[]);
	void getDoubleValues(float[]); // in Arduino double and float are the same
	
	size_t write(uint8_t);

	void send(char);
    void send(const char[]);
    void send(uint8_t);
    void send(int);
    void send(unsigned int);
    void send(long);
    void send(unsigned long);
    void send(long, int);
    void send(double);
    void sendln(void);


	uint16_t waitTime;
	
	static int library_version() { 
		return _MEET_ANDROID_VERSION;} 
};

// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round 

#endif

jpvr:
I try run it and IDE show me a long list of errors...
Can you give me a sample of add a return statement to the function?
Infinitely grateful!

Did you make the change PaulS suggested?

... long list of errors ...

Well, post them. At least the first ones.

Hello Nick... I don't know if I make it right... but IDE return me it:
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:22:24: error: WConstants.h: No such file or directory
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp: In member function 'bool MeetAndroid::receive()':
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:86: error: 'boolean' was not declared in this scope
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:86: error: expected `;' before 'timeout'
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:87: error: 'timeout' was not declared in this scope
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:108: error: 'delayMicroseconds' was not declared in this scope
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:112: error: 'timeout' was not declared in this scope
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp: At global scope:
C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:252: error: prototype for 'void MeetAndroid::write(uint8_t)' does not match any in class 'MeetAndroid'
C:\arduino-1.0\libraries\MeetAndroid/MeetAndroid.h:104: error: candidate is: virtual size_t MeetAndroid::write(uint8_t)

I modify my file MeetAndroid.cpp to:

void MeetAndroid::write(uint8_t b){
	Serial.print(b);
	return 1;
}

:S

Thx for help friends! :slight_smile:

Change:

  #include "WConstants.h"

to:

  #include "Arduino.h"

Done, now have only its error msg:

C:\arduino-1.0\libraries\MeetAndroid\MeetAndroid.cpp:252: error: prototype for 'void MeetAndroid::write(uint8_t)' does not match any in class 'MeetAndroid'
C:\arduino-1.0\libraries\MeetAndroid/MeetAndroid.h:104: error: candidate is: virtual size_t MeetAndroid::write(uint8_t)

:D:D:D:D

You have also got to change that word "void" to "size_t". This is the implementation, the other one was the prototype.

Ahhhh now I'm understanding :slight_smile:

Now I'm geting a new msg error:

java.lang.NullPointerException
at processing.app.debug.Compiler.execAsynchronously(Compiler.java:326)
at processing.app.debug.Compiler.compileFiles(Compiler.java:274)
at processing.app.debug.Compiler.compile(Compiler.java:166)
at processing.app.Sketch.build(Sketch.java:1569)
at processing.app.Sketch.build(Sketch.java:1546)
at processing.app.Editor$DefaultRunHandler.run(Editor.java:1845)
at java.lang.Thread.run(Thread.java:619)

some problem with java compiler?

Thx :slight_smile:

It does that at times. I usually just try again.

:smiley: I restarted my machine and it's work!
Thank PaulS and Nick for your help! I hope one day to give it back.

Very thxxx! :smiley: