New library for eDIPTFT displays - some troubles - help needed

Hi all,

I'm fairly new to Arduino and I'm just a hobby-coder, not a professional by a long shot. I'm working on my first bigger project and I have written a bunch of convenience functions to control eDIPTFT-series intelligent displays from Electronic Assembly. With the help of the forum, I now converted this collections of functions in a .ino file into a libray.

Now, my problem. Those displays use serial communication and I want to hand over the serial port to use for communications in a parameter in the constructor:

EDIPTFT::EDIPTFT(int port, int smallprotocol) {
  _port = port;
  _smallprotocol = smallprotocol;
}

Then, the sendData() function checks this parameter and decides which
port to use:

void EDIPTFT::sendData(char* data, int len) {
  if (_smallprotocol > 0) {
  }
  else {
    unsigned char i;
    for(i=0; i < len; i++) {
      switch (_port) {
	case 0 : {
	  Serial.write(data[i]);
	  break;
	}
	case 1 : {
	  Serial1.write(data[i]);
	  break;
	}
	case 2 : {
	  Serial2.write(data[i]);
	  break;
	}
	case 3 : {
	  Serial3.write(data[i]);
	  break;
	}
      }
    }
  }
}

Trouble is, I can't get it compiled. The sketch I'm writing in my main project includes the FastSerial library which is needed by some other libraries I also use. Now, when I try to compile my sketch with my EDIPTFT library, I get these errors:

core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_25'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
/opt/arduino-1.0.3/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_36'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_51'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_54'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `Serial'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
/opt/arduino-1.0.3/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: Warning: size of symbol `Serial' changed from 29 in UxV_CS.cpp.o to 34 in core.a(HardwareSerial.cpp.o)
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `Serial1'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
/opt/arduino-1.0.3/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: Warning: size of symbol `Serial1' changed from 29 in UxV_CS.cpp.o to 34 in core.a(HardwareSerial.cpp.o)
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `Serial2'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
/opt/arduino-1.0.3/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: Warning: size of symbol `Serial2' changed from 29 in UxV_CS.cpp.o to 34 in core.a(HardwareSerial.cpp.o)
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `Serial3'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
/opt/arduino-1.0.3/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/bin/ld: Warning: size of symbol `Serial3' changed from 29 in UxV_CS.cpp.o to 34 in core.a(HardwareSerial.cpp.o)
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_26'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_37'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_52'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here
core.a(HardwareSerial.cpp.o): In function `global constructors keyed to rx_buffer':
/opt/arduino-1.0.3/hardware/arduino/cores/arduino/HardwareSerial.cpp:515: multiple definition of `__vector_55'
UxV_CS.cpp.o:/opt/arduino-1.0.3/UxV_CS.ino:79: first defined here

Could somebody help me out with that, please?
The complete code of my library is at

-Stefan

The problem is solved meanwhile :). I had to remove the inclusion of Arduino.h and additionally include FastSerial.h in my library's .cpp-file. As I understood it, the appeareance of Serial.write() in my lib caused Arduino to automatically include the "wrong" hardwareserial code which collided with the FastSerial lib which is included by the sketch.

hi,

first of all, thank you! :slight_smile:

i would like to use your library with a 7" eDIPTFT display in my next little project.

can you add a small simple example code on GITHUB to show how your library should
be implemented in the main program and how you read back touch-events?

thanks!

with best regards,
martin lang - austria

Hi,

I haven't got time to think about an example yet.

You include it basically with

#include <FastSerial.h>
#include <EDIPTFT.h>

FastSerialPort0(Serial);
FastSerialPort1(Serial1);
FastSerialPort2(Serial2);
FastSerialPort3(Serial3);

EDIPTFT ea(0,1);   //port = 0, smallprotocol on = 1, off = 0

void setup() {
  Serial.begin(115200,256,256);
  ea.smallProtoSelect(7); // send the select command with the matching ID, otherwise the display might not talk to us
  ea.clear();
  ea.cursor(false);
  ...
}

There are a few limitations which I haven't got around yet. One is the need to declare all ports, another the dependance on FastSerial.

Then parsing input, e.g. like this...:

void loop() {
  ...
  if (ea.datainBuffer() >0) parseSerial();                       // If the display has data for us, go and get it
  ...
}


void parseSerial() {
  char i;
  char len = ea.datainBuffer();
  char data[len];
  ea.readBuffer(data);
  if (data[0] == 27) {
    if ((data[1] == 'A') && (data[2] == 1)) {
      switch (data[3]) {
        case 1 : { setMode(1); break; }
        case 2 : { setMode(2); break; }
        case 3 : { setMode(3); break; }
        case 4 : { setMode(4); break; }
        case 5 : { setMode(5); break; }
        case 6 : { setMode(6); break; }
        case 7 : { setMode(7); break; }
      }
    }
  }
}

datainBuffer() returns the number of characters which are in the output buffer, ready to be pulled. readBuffer() reads the output buffer. Smartprotocol is implemented in those too, when selected on init.

Thank you!

Does your library also work with the normal Serial library when 115200 is not needed?

Ciao
Martin

It SHOULD work. But you have to remove the FastSerial include from the library too then. However, I'd recommend FastSerial because you can define the buffer size of the read buffer up to 256 bytes and thus are less likely to miss any message from the display. I'd also recommend 115k2. The display is not much fun on slower rates :).