How to fix PlatformIO ESP8266/ESP32 fatal error: SPI.h: No such file or directory
Problem:
You are trying to compile your PlatformIO application for the ESP8266 or ESP32 but you’re seeing an error message like
error.txt
In file included from .pio/libdeps/d1_mini/TFT_eSPI/TFT_eSPI.cpp:17:0:
.pio/libdeps/d1_mini/TFT_eSPI/TFT_eSPI.h:32:17: fatal error: SPI.h: No such file or directory
*************************************************************
* Looking for SPI.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:SPI.h"
* Web > https://platformio.org/lib/search?query=header:SPI.h
*
*************************************************************
#include <SPI.h>This problem is common using the TFT_eSPI library.
Solution
First, ensure that your platformio.ini has
platformio.ini
framework = arduinoIf you’re using a different framework, SPI.h won’t be available since it’s a part of the Arduino framework !
Secondly, add this line to your platformio.ini:
platformio_ldf.ini
lib_ldf_mode = deep+and recompile your source code. This will reconfigure the library dependency finder (ldf) to find dependencies of dependency libraries:
dependency_graph.txt
Dependency Graph
|-- <TFT_eSPI> 2.3.52
| |-- <SPI> 1.0Check out similar posts by category:
ESP8266/ESP32, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow