For a project with the SEEED Mini Lidar, I need reliable communication at 115200 bps. The application should work with an Arduino Nano and an ESP8266 too.
For the Nano I optimized the "SoftwareSerial" library a little and saved it as a new "SerialHSP" class. The structure of the new class is exactly the same as the original.
My program system (reduced, see below) consists of
- StreamTest.ino - defines the serial interface and uses classes StreamUser and SerialHSP
- Class StreamUser.cpp / .h - Receives the serial interface as "Stream *"
- Class SerialHSP.cpp / .h - is only used for the Nano
Now to my problem: When the program is compiled for the Nano, there is a cryptic error message:
Linking everything together...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Rudol\AppData\Local\Temp\arduino_build_289511/StreamTest.ino.elf" "C:\Users\Rudol\AppData\Local\Temp\arduino_build_289511\sketch\StreamTest.ino.cpp.o" "C:\Users\Rudol\AppData\Local\Temp\arduino_build_289511\libraries\SerialHSP\SerialHSP.cpp.o" "C:\Users\Rudol\AppData\Local\Temp\arduino_build_289511\libraries\StreamUser\StreamUser.cpp.o" "C:\Users\Rudol\AppData\Local\Temp\arduino_build_289511/core\core.a" "-LC:\Users\Rudol\AppData\Local\Temp\arduino_build_289511" -lm
C:\Users\Rudol\AppData\Local\Temp\ccmFUJkm.ltrans0.ltrans.o: In function global constructors keyed to 65535_0_StreamTest.ino.cpp.o.1881':* *<artificial>:(.text.startup+0xa4): undefined reference to vtable for SerialHSP'
:(.text.startup+0xa6): undefined reference to vtable for SerialHSP'* *C:\Users\Rudol\AppData\Local\Temp\ccmFUJkm.ltrans0.ltrans.o: In function __base_dtor ':
D:\Arduino\libraries\SerialHSP\src/SerialHSP.cpp:167: undefined reference to vtable for SerialHSP'* *D:\Arduino\libraries\SerialHSP\src/SerialHSP.cpp:167: undefined reference to vtable for SerialHSP'
collect2.exe: error: ld returned 1 exit status
Using library SerialHSP at version 1.0 in folder: D:\Arduino\libraries\SerialHSP
Using library StreamUser in folder: D:\Arduino\libraries\StreamUser (legacy)
exit status 1
Error compiling for board Arduino Nano.
Why the linker will not see the SerialHSP library?
The compilation for the ESP8266 (with its SoftwareSerial) works without errors. What can be the core problem for "... undefined reference to" vtable ... "?
The Sketch "StreamTest.ino":
/*===============================================================
Prüfprogramm: Seed Mini Lidar an Arduino Nano Familie
---------------------------------------------------------------
Sketch: StreamPointer.ino
Autor: Rudolf Schenke
Stand: 22.01.2021: Reduced Sketch for Stream* test
===============================================================*/
#if defined (ARDUINO_AVR_NANO)
#include <SerialHSP.h> // Special Lib für Nano Classic / UNO
SerialHSP SSerial(2,3);
// #include <SoftwareSerial.h> // Standard pendant for Nano Classic / UNO
// SoftwareSerial SSerial(2,3);
#endif
#ifdef ARDUINO_ARCH_ESP8266
#include <SoftwareSerial.h> // ESP8266 nutzt SoftwareSerial
SoftwareSerial SSerial(D1,D2);
#endif
#include <StreamUser.h> // Place holder for Lidar Library
StreamUser sensor; //---- Pseudo Lidar Object ----
///========================================================
void setup() {
delay(400);
Serial.begin(74880); // Bit rate for monitoring
while (!Serial) delay(10);
Serial.println("Testen Stream Pointer");
SSerial.begin(115200); // Bit rate for Lidar read operation
//==== The library must use the Serial given with &Serial =======
sensor.init(&SSerial); // Connect to Lidat lib -> with Serial*
}
void loop() {
}
and the Library "StreamUser"
/*===============================================================
class StreamUser as placeholder for StreamUser
---------------------------------------------------------------
Autor: Rudolf Schenke
Stand: 22.01.2021: Extrackt from original lib for tests
===============================================================*/
#ifndef StreamUser_H
#define StreamUser_H
#include <Arduino.h>
#include <Stream.h>
class StreamUser
{
public:
StreamUser() {}
~StreamUser() {}
void init(Stream* SerPtr);
private:
Stream* pSP; // Zeiger auf Serial- (Straeam-) Objekt
};
#endif
/*=====================================================================
Reduced class StreamUser: Seed Mini Lidar - Daten lesen
---------------------------------------------------------------------
Autor: Rudolf Schenke
Stand: 22.01.2021: Reduced version
=====================================================================*/
#include <StreamUser.h>
///==== Public functions ========
void StreamUser::init(Stream* SerPtr) {
pSP = SerPtr; // Serial(Stream)-Pointer speichern
}