Fatal error: Arduino.h: No such file or directory

Yes, platformio invokes and it leads to success

What extensions do you have installed?

Does a Ctrl+Shift+P → Rebuild IntelliSense help?

No it does not help, the problem is still there. It’s really frustrating, uninstalling and installing vs code doesnt work, uninstalling and installing platform io doesn’t work. Nothing works.

I would be very grateful if someone can help me figure this out.

If you run Build from the PROJECT TASKS, something like this should appear in the TERMINAL view:

> Executing task: platformio run <

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR (3.3.0) > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr 5.1.0 
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/nanoatmega328/src/main.cpp.o
Archiving .pio/build/nanoatmega328/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328/FrameworkArduino/CDC.cpp.o
Compiling .pio/build/nanoatmega328/FrameworkArduino/HardwareSerial.cpp.o
...
Compiling .pio/build/nanoatmega328/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/nanoatmega328/libFrameworkArduino.a
Indexing .pio/build/nanoatmega328/libFrameworkArduino.a
Linking .pio/build/nanoatmega328/firmware.elf
Checking size .pio/build/nanoatmega328/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [          ]   3.0% (used 924 bytes from 30720 bytes)
Building .pio/build/nanoatmega328/firmware.hex
================================================================================================================= [SUCCESS] Took 1.98 seconds =================================================================================================================

Terminal will be reused by tasks, press any key to close it.

It the output looks different, then you are not running PlatformIO. Ignore the PROBLEMS view and the squiggly lines in the editor for now.

If different output appears, please describe in detail what you clicked or what keyboard short-cuts you have pressed. And copy the output from the TERMINALS view.

In the plantform.io configuration, make sure you include framework = arduino

This is my case:

[platform]
description = Sample
default_envs = nanoatmega328
src_dir = .
include_dir = include
libdeps_dir = dependencies

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino

Hi,

I have the same issue, has anyone found a solution for this?
Another project I have been working on is compiling fine, but creating a new project is not. I am using a different board Espressif ESP32-C3-DevKitC-02 before was a ESP32 based TTGO.

I have created three new projects trying to solve this issue, all the same. When I try to compile the example main.cpp and get the same error. Any help would be much appreciated.

Code:

#include <Arduino.h>

// put function declarations here:
int myFunction(int, int);

void setup() {
  // put your setup code here, to run once:
  int result = myFunction(2, 3);
}

void loop() {
  // put your main code here, to run repeatedly:
}

// put function definitions here:
int myFunction(int x, int y) {
  return x + y;
}

Error:

main.cpp:1:10: fatal error: Arduino.h: No such file or directory
 #include <Arduino.h>
          ^~~~~~~~~~~
compilation terminated.

My platformio.ini file:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

Build Terminal Output:

Executing task: C:\Users\Tristan\.platformio\penv\Scripts\platformio.exe run --environment esp32dev 

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.4.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20011.230801 (2.0.11)
 - tool-esptoolpy @ 1.40501.0 (4.5.1)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   6.4% (used 21068 bytes from 327680 bytes)
Flash: [==        ]  17.7% (used 232649 bytes from 1310720 bytes)
=========================================================== [SUCCESS] Took 21.36 seconds ===========================================================
 *  Terminal will be reused by tasks, press any key to close it. 

…The project built perfectly fine with PlatformIO.

Can you show what exact button you’re pressing in VSCode to start the build process that throws this error? Note that using the build button in the top-right corner of a VSCode window is wrong.

@maxgerhardt - thank you. I just figured that out and came back to reply and saw your answer. Yes, completely forgot which button I was using last time. Must be getting old! Thank again!

I realised why, on my laptop I did not have Code Runner installed, so the top right corner had a tick icon and therefore compiled. But on my desktop, top right has Code Runner play icon now.

@asperised Hey did you end up fixing the issue? I am having the same issue. I tried all the advised methods and I still have not resolved the issue.

Please show platformio.ini, code and screenshot of VSCode with the error message visible. How did you trigger the build?