How do I properly include Arduino libraries in ESP-IDF

I’m using the ESP-IDF framework and have set up Arduino as a component, which is working.

While I’ve managed to get one Arduino library to work, my second library just cannot be found, so I must be including it improperly. Here is the error

src/main.cpp:10:10: fatal error: TMCStepper.h: No such file or directory

********************************************************************
* Looking for TMCStepper.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:TMCStepper.h"
* Web  > https://platformio.org/lib/search?query=header:TMCStepper.h
*
********************************************************************

 #include "TMCStepper.h"
          ^~~~~~~~~~~~~~
compilation terminated.

I have placed the Arduino library “TMCStepper” into the components folder as well as lib folder,and installed it in the libdeps folder.

This is my main.cpp code

#include "Arduino.h"

#define ARDUINO_ARCH_ESP32 

#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif

#include "FastAccelStepper.h"
#include "TMCStepper.h"


extern "C" void app_main()
{
    initArduino();
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);

}

And here is the platformio.ini code

[platformio]
src_dir = src
lib_dir = components

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
build_flags = 
  -I components
  -I include
lib_ldf_mode = chain+
lib_deps = 
  gin66/FastAccelStepper @ ^0.23.5
  teemuatlut/TMCStepper @ ^0.7.3

Any idea why it can’t find the TMCStepper.h file?

Try setting lib_compat_mode = off in the platformio.ini to disable framework checks for == Arduino? (docs).

1 Like

That worked. Thank you!