How to fix PlatformIO SPI.h: No Such File or Directory

Problem:

When compiling your PlatformIO firmware, you see an error message like

example-3.txt
                 from .pio/libdeps/esp32dev/Adafruit INA219/Adafruit_INA219.h:21,
                 from .pio/libdeps/esp32dev/Adafruit INA219/Adafruit_INA219.cpp:31:
.pio/libdeps/esp32dev/Adafruit BusIO/Adafruit_SPIDevice.h:6: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
*
*************************************************************

Solution

Add SPI to the lib_deps in platformio.ini, for example, before:

example-2.ini
    adafruit/Adafruit INA219 @ ^1.1.1

After:

example-1.ini
    adafruit/Adafruit INA219 @ ^1.1.1
    SPI

and then recompile.


Check out similar posts by category: Arduino, Electronics, PlatformIO