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

Nope the problem is still there.

These are the two errors I am getting.

When you press the build button, is PlatformIO invokes and the build leads to “success”?

1 Like

That might be the case. But what is shown on the Terminal tab after pressing Build?

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?

Hello there,

This is my fist day moving out from ArduinoIDE to VC PIO. Already got a ton of errors.
The first one was the missing Arduino.h . I found two ways of fixing:

ONE

Open a brand new pio project project in default location, no desktop, no documents, just the default location.

TWO

Add manually Arduino.h path to C++ extension.

You will need to find Arduino.h location where it was downloaded, in my case it was: C:\Users[username].platformio\packages\framework-arduinoespressif32\cores\esp32

Just add the path in the Include Path box

I have found several other bugs and problems when trying to use ArduinoCloudIoT libraries and WiFi , i have been trying to solve one by one. It seems that since the new arduino ide was released many compatibility issues where created and developers are working on that but meanwhile you need to tackle them as they show up.

regards

Yes my problem was that i was not puting platform = arduino.
Thanks

hi im not sure whats wrong with my code it keeps saying “DCMDriverL293D.h no such file and directory”

Here is my code:

void setup() {
  // put your setup code here, to run once:

}// Include Libraries
#include "Arduino.h"
#include "DCMDriverL293D.h":


// Pin Definitions
#define DCMOTORDRIVERA_PIN_ENABLE1	5
#define DCMOTORDRIVERA_PIN_IN1	2
#define DCMOTORDRIVERA_PIN_IN2	3
#define DCMOTORDRIVERA_PIN_ENABLE2	6
#define DCMOTORDRIVERA_PIN_IN3	4
#define DCMOTORDRIVERA_PIN_IN4	7



// Global variables and defines

// object initialization
DCMDriverL293D dcMotorDriverA(DCMOTORDRIVERA_PIN_ENABLE1,DCMOTORDRIVERA_PIN_IN1,DCMOTORDRIVERA_PIN_IN2,DCMOTORDRIVERA_PIN_ENABLE2,DCMOTORDRIVERA_PIN_IN3,DCMOTORDRIVERA_PIN_IN4);


// define vars for testing menu
const int timeout = 10000;       //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup() 
{
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");
    
    
    menuOption = menu();
    
}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
    
    
    if(menuOption == '1') {
    // L293D Motor Driver with Dual Hobby DC Motors - Test Code
    //Start both motors. note that rotation direction is determined by the motors connection to the driver.
    //You can change the speed by setting a value between 0-255, and set the direction by changing between 1 and 0.
    dcMotorDriverA.setMotorA(200,1);
    dcMotorDriverA.setMotorB(200,0);
    delay(2000);
    //Stop both motors
    dcMotorDriverA.stopMotors();
    delay(2000);

    }
    
    if (millis() - time0 > timeout)
    {
        menuOption = menu();
    }
    
}



// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

    Serial.println(F("\nWhich component would you like to test?"));
    Serial.println(F("(1) L293D Motor Driver with Dual Hobby DC Motors"));
    Serial.println(F("(menu) send anything else or press on board reset button\n"));
    while (!Serial.available());

    // Read data from serial monitor if received
    while (Serial.available()) 
    {
        char c = Serial.read();
        if (isAlphaNumeric(c)) 
        {   
            
            if(c == '1') 
    			Serial.println(F("Now Testing L293D Motor Driver with Dual Hobby DC Motors"));
            else
            {
                Serial.println(F("illegal input!"));
                return 0;
            }
            time0 = millis();
            return c;
        }
    }
}


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

}int motorPin = 9;

void setup() {
   pinMode(motorPin, OUTPUT);
   Serial.begin(9600);
   while (! Serial);
   Serial.println("Speed 0 to 255");
}

void loop() {
   if (Serial.available()) {
      int speed = Serial.parseInt();
      if (speed >= 0 && speed <= 255) {
         analogWrite(motorPin, speed);
      }
   }
}

Edit by sivar2311: Used pre-formatted text to make the code easier to read.
Please use pre-formatted code when posting code or log files. Thanks in advance!

Is this your first Arduino project?

This code looks like wildly copied parts and makes no sense.

yeah it’s my first im trying to get the l293d motor driver arduino uno with a bread board trying to power a TT motor 20191205. my teacher just told me to copy and paste the codes no idea what’s happening

This is the forum for PlatformIO.
I recommend you start with the ArduinoIDE.

Start with something simple like making an LED blink.