Hi Ken
This is my source tree, based on what your download provided:
.
├── include
│ ├── Adafruit_LiquidCrystal.h
│ └── utility
│ └── Adafruit_MCP23008.h
├── lib
│ ├── Adafruit_LiquidCrystal-1.1.0
│ │ ├── Adafruit_LiquidCrystal.cpp
│ │ ├── Adafruit_LiquidCrystal.h
│ │ └── utility
│ │ ├── Adafruit_MCP23008.cpp
│ │ └── Adafruit_MCP23008.h
│ └── Wire
│ ├── Wire.cpp
│ └── Wire.h.xxx
├── platformio.ini
└── src
└── main.cpp
Points to note:
- To get a compilation, I had to move various header files into
include
. I could have added the path’s to the directories to the build_flags
with a -I
option, I suppose. I had to do that for the Arduino headers anyway.
-
lib/Wire/Wire.h
is only renamed to determine where it’s being picked up from by the compiler.
- Nothing touches the Adafruit library in the compilation process.
- If
lib
is present, the compiler option -I lib/Wire
is passed allowing for lib/Wire/Wire.h
to be found. However, -I lib/Adafruit_LiquidCrystal-1.1.0 -I lib/Adafruit_LiquidCrystal-1.1.0/utility
is never passed to the compiler. (Regardless of the lib_ldf_mode
and lib_compatible_mode
options used.
- Renaming
lib/Adafruit_LiquidCrystal-1.1.0
folder to lib/fred
makes zero difference.
This is what I ended up with in my platformio.ini
:
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
build_flags =
-I/home/norman/.platformio/packages/framework-arduino-avr/cores/arduino
-I/home/norman/.platformio/packages/framework-arduino-avr/variants/standard
-I/home/norman/.platformio/packages/framework-arduino-avr/libraries/Wire/src/
Ok, if I comment out the last one, relating to Wire, then Wire.h
is loaded from lib/Wire
but fails to compile as other headers are required from the Arduino packages. If I rename that Wire.h
it obviously isn’t found, and if I add back the include path I commented out, it’s found in there as opposed to in lib
– plus, all the other dependencies are also found.
Summary:
- The code needs far too much from the Arduino packages to be considered Arduino free.
- The Adafruit library is never mentioned or compiled.
- The Adafruit headers are only found if I copy them to
include
.
- If I manage to get a clean compile, the linker barfs because the
core.a
Arduino static library hasn’t been created, so the linker cannot find the Print
class stuff it is requiring from within the Adafruit library.
That’s how it should work, yes. Normally the Arduino “stuff” is compiled into a core.a
library and linked – but obviously only when you use the Arduino framework.
Not that Adafruit one! I cannot get a proper download. Unless, of course, the library dependency finder is looking at the project’s framework. If I change it to use the Arduino framework, it does download.
I often write code that has no Arduino stuff in it – basically to replace the Arduino stuff! I don;t appear to have had many major problems yet.
Ahem, libraries? 
Your own libraries go in lib
with each separate library having its own folder, named after the library but that’s not essential. At first build time, or after any code changes to the library files, they are compiled into a library, libXXXX.a
where ‘XXXX’ is the library folder name, then linked at the end of the build.
I use the lib
folder for all my own AVE C++ stuff. I’m writing another book so I have quite a few of my own build libraries which are usable from Arduino and plain AVR C++ as the code doesn’t need or use any Arduino Language.
Here’s a plain AVR C++ project of mine. It is used to replicate the millis()
and micros()
functions in the Arduino framework, but without needing to use the Arduino framework:
.
├── include
│ └── README
├── lib
│ ├── AVRmillis
│ │ ├── AVRmillis.cpp
│ │ ├── AVRmillis.h
│ │ └── defines.h
│ └── README
├── platformio.ini
├── src
│ └── main.cpp
└── test
└── README
Platformio.ini
:
[env:uno]
platform = atmelavr
board = uno
src/main.cpp
:
// Test sketch for the AVRmillis class. This one
// does the usual "flash the built in LED" every 1000
// milliseconds.
//
// Norman Dunbar.
// 4 January 2021.
#include "avr/interrupt.h"
#include "util/delay.h"
#include "AVRmillis.h"
// Toggle the LED every flashPeriod milliseconds.
const uint16_t flashPeriod = 1000;
int main() {
// Interrupts on! (I always forget!)
sei();
// Pseudo Globals.
uint32_t timeToggled = 0;
//--------------------------------------------------------
// SETUP:
//--------------------------------------------------------
// D13/PB5 = OUTPUT.
DDRB |= (1 << DDB5);
//--------------------------------------------------------
// LOOP:
//--------------------------------------------------------
while (1) {
// Grab current millis time.
uint32_t timeNow = AVRmillis.millis();
// Has the flashPeriod expired? If so,
// toggle the LED and save when we toggled.
if ((timeNow - timeToggled) >= flashPeriod) {
PINB |= (1 << PINB5);
timeToggled = timeNow;
}
}
return 0;
}
Compilation:
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (3.1.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <AVRmillis>
Building in release mode
Compiling .pio/build/uno/src/main.o
Compiling .pio/build/uno/lib66f/AVRmillis/AVRmillis.o
Archiving .pio/build/uno/lib66f/libAVRmillis.a
Indexing .pio/build/uno/lib66f/libAVRmillis.a
Linking .pio/build/uno/firmware.elf
Checking size .pio/build/uno/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 0.4% (used 9 bytes from 2048 bytes)
Flash: [ ] 1.4% (used 442 bytes from 32256 bytes)
Building .pio/build/uno/firmware.hex
You can see from the above that libAVRmillis.a
was successfully created. It was then linked (there are no linker errors) and after an upload, I have the obligatory flashing LED on my Uno.
Admittedly, this isn’t a massive project like your’s is, but I think the main problems here is:
- You are trying to not use Arduino stuff;
- You are, however, using a library that itself uses Arduino stuff;
- I suspect that the LDF doesn’t download libraries that are flagged as “arduino” when you are not using that framework. (To be confirmed.)
If you want to see the rest of the code for the AVRmillis
stuff, it’s aonline in my GitHub repository at GitHub - NormanDunbar/AVRmillis: PlatformIO example code to replace the Arduino `micros` and `millis` functions. Harnesses the Timer/counter 0 overflow interrupt in exactly the same manner as the Arduino does..
HTH
Cheers,
Norm.