Hey everyone,
I have a couple of Sketches that share a lot of common code like functions to connect to WiFi, send MQTT messages etc. To reduce maintenance effort, I would like to put this code into a libraries folder from where it can be included into all Sketches.
The only hints I found about making libraries is to put them in a libraries folder inside the Sketch (e. g. Calling functions from another file - Programming Questions - Arduino Forum). This is not what I need.
I tried C++ style relative imports like this
#include "../../libraries/mySerial/mySerial.h"
void setup() {
Serial.begin(115200);
printToSerial(&Serial, "Hello World!");
}
void loop() {
}
but Arduino IDE throws an error:
modularization-test:1:47: fatal error: ../../libraries/ppSerial/ppSerial.h: No such file or directory
#include "../../libraries/mySerial/mySerial.h"
^
compilation terminated.
exit status 1
../../libraries/mySerial/mySerial.h: No such file or directory
The directory structure is
project_root
|- sketches
| \- sketch_1
| \- sketch_1.ino
\- libraries
\- mySerial
|- mySerial.h
\- mySerial.cpp
The relative path itself is correct (I can do "cat ../../libraries/mySerial/mySerial.h" from the sketch directory).
What am I doing wrong?
Thanks for your help!
Cheers
Fred