Arduino.h, avr-gcc

I am a VSCode veteran, brand new to PlatformIO. I’ve been struggling with some really basic things. After attempting without success to import an existing and working Arduino sketch (created in Arduino IDE), I decided to start from scratch.

I created a new project for Arduino Uno Wifi rev.2 board. Immediately I got errors in the first line of main.cpp: #include <Arduino.h> , which said to update my includePath. In addition, I got the message:
cannot open source file “inttypes.h” (dependency of “Arduino.h”)C/C++(1696)

I don’t how to update the includePath, and I cannot find where to source the Arduino.h file. Googled for quite awhile before posting this…

In addition I am getting error:
Unable to resolve configuration with compilerPath: “avr-gcc”
in the output window. Same story, lots of Googling, no joy.

Can you help me get past these fails?

Thanks!

In case it isn’t clear, I haven’t written any code yet, these errors are happening with the template code that PlatformIO creates.

Also, I uninstalled and reinstalled just to see if that made any difference, didn’t.

It sounds to me as you there might be two overlapping errors. First, make sure that you do not have conflicting VSCode extensions installed, especially “C/C++ by austin” or Arduino.

Then, make sure to build the project once regardless of IntelliSense errors. PlatformIO is the build system here, not the IntelliSense extension; it can be wrong while still building. If you’ve never built any project before then PlatformIO will only at build time download the toolchain and framework files, only after which the IntelliSense will be able to pick them up. So this initial error is one-time expected.

If you have made modifications to your include path or the .vscode/c_cpp_properties.json file, you must re-initialize the project to restore it to a good state. Use the project task “Default → Miscelleneous → Rebuild IntelliSense”.

OK - re-installed from scratch and created a blank new project with main.cpp as follows:
image ;

Build using the PlatformIO build:

> Executing task in folder Datalogger_Ethernet_New: C:\Users\StephenRogers\.platformio\penv\Scripts\pio.exe run --environment uno_wifi_rev2 <

Processing uno_wifi_rev2 (platform: atmelmegaavr; board: uno_wifi_rev2; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/uno_wifi_rev2.html
PLATFORM: Atmel megaAVR (1.3.0) > Arduino Uno WiFi Rev2
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 47.50KB Flash
PACKAGES:
 - framework-arduino-megaavr 1.8.6
 - 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\uno_wifi_rev2\FrameworkArduinoVariant\variant.c.o
'avr-gcc' is not recognized as an internal or external command,
operable program or batch file.
Compiling .pio\build\uno_wifi_rev2\src\main.cpp.o
'avr-g++' is not recognized as an internal or external command,
operable program or batch file.
Compiling .pio\build\uno_wifi_rev2\FrameworkArduino\CDC.cpp.o
'avr-g++' is not recognized as an internal or external command,
operable program or batch file.
Compiling .pio\build\uno_wifi_rev2\FrameworkArduino\NANO_compat.cpp.o
'avr-g++' is not recognized as an internal or external command,
operable program or batch file.
Compiling .pio\build\uno_wifi_rev2\FrameworkArduino\Tone.cpp.o
'avr-g++' is not recognized as an internal or external command,
operable program or batch file.
Compiling .pio\build\uno_wifi_rev2\FrameworkArduino\UART.cpp.o
'avr-g++' is not recognized as an internal or external command,
operable program or batch file.
Compiling .pio\build\uno_wifi_rev2\FrameworkArduino\UART0.cpp.o
'avr-g++' is not recognized as an internal or external command,
Compiling .pio\build\uno_wifi_rev2\FrameworkArduino\UART1.cpp.o
operable program or batch file.
*** [.pio\build\uno_wifi_rev2\FrameworkArduinoVariant\variant.c.o] Error 1
*** [.pio\build\uno_wifi_rev2\src\main.cpp.o] Error 1
*** [.pio\build\uno_wifi_rev2\FrameworkArduino\CDC.cpp.o] Error 1
*** [.pio\build\uno_wifi_rev2\FrameworkArduino\NANO_compat.cpp.o] Error 1
*** [.pio\build\uno_wifi_rev2\FrameworkArduino\Tone.cpp.o] Error 1
*** [.pio\build\uno_wifi_rev2\FrameworkArduino\UART.cpp.o] Error 1
*** [.pio\build\uno_wifi_rev2\FrameworkArduino\UART0.cpp.o] Error 1
'avr-g++' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\uno_wifi_rev2\FrameworkArduino\UART1.cpp.o] Error 1
============================================================================ [FAILED] Took 0.91 seconds ============================================================================
The terminal process "C:\Users\StephenRogers\.platformio\penv\Scripts\pio.exe 'run', '--environment', 'uno_wifi_rev2'" terminated with exit code: 1.

I have also checked that those conflicting VSCode Extensions are not there. C/C++ is required by PlatformIO it says but that is the only extension other than PlatformIO IDE itself that would seem to conflict.

I also reinitialized the project to rebuild intellisense.

These sure seem like unexpected errors. I have also watched some tutorials for PlatformIO and these types of results are not in them.

Here is the error in the #include:

Looks like the compiler failed to be downloaded properly. Please remove the folder C:\Users\StephenRogers\.platformio\packages\toolchain-atmelavr completely and press “Build” again.

1 Like

Wow that seemed to work!

Hope is in the air… Thanks!

Unfortunately, when I add in some code that works fine in Arduino IDE, I compile it and get a ton of errors, beyond capacity to capture or put in here.

Here most of them are, all seem to do with lib dependencies relating to the Arduino Uno Wifi Ver.2 that I selected from the Libraries Menu in PlatformIO. I imagine you will see what’s wrong with a glance. I already tried removing the folder for toolchain-atmelavr. That didn’t make any difference this time.

The following are just a few of the hundreds of errors I’m getting.

In file included from .pio\libdeps\uno_wifi_rev2\SD\utility\Sd2Card.h:26:0,
                 from .pio\libdeps\uno_wifi_rev2\SD\utility\Sd2Card.cpp:26:
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:300:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
In file included from .pio\libdeps\uno_wifi_rev2\SD/utility/Sd2Card.h:26:0,
                 from .pio\libdeps\uno_wifi_rev2\SD/utility/SdFat.h:29,
                 from .pio\libdeps\uno_wifi_rev2\SD/SD.h:25,
                 from .pio\libdeps\uno_wifi_rev2\SD\File.cpp:15:
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:300:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:311:5: error: 'DDRB' was not declared in this scope
   {&DDRB, &PINB, &PORTB, 3},  // B3 11
     ^~~~
In file included from .pio\libdeps\uno_wifi_rev2\SD/utility/Sd2Card.h:26:0,
                 from .pio\libdeps\uno_wifi_rev2\SD/utility/SdFat.h:29,
                 from .pio\libdeps\uno_wifi_rev2\SD\SD.h:25,
                 from .pio\libdeps\uno_wifi_rev2\SD\SD.cpp:53:
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:300:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:302:5: note: suggested alternative: 'VDD'
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
     ^~~~
     VDD
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:311:5: note: suggested alternative: 'DD0'
   {&DDRB, &PINB, &PORTB, 3},  // B3 11
     ^~~~
     DD0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:311:12: error: 'PINB' was not declared in this scope
   {&DDRB, &PINB, &PORTB, 3},  // B3 11
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:300:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:302:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:301:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 1},  // D1  1
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:311:12: note: suggested alternative: 'PIN0'
   {&DDRB, &PINB, &PORTB, 3},  // B3 11
            ^~~~
Compiling .pio\build\uno_wifi_rev2\libc51\Ethernet\EthernetServer.cpp.o
            PIN0
Compiling .pio\build\uno_wifi_rev2\libc51\Ethernet\EthernetUdp.cpp.o
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:300:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:312:5: error: 'DDRB' was not declared in this scope
   {&DDRB, &PINB, &PORTB, 4},  // B4 12
     ^~~~
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:301:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 1},  // D1  1
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:301:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 1},  // D1  1
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:302:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:300:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:301:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 1},  // D1  1
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:312:5: note: suggested alternative: 'DD0'
   {&DDRB, &PINB, &PORTB, 4},  // B4 12
     ^~~~
     DD0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:312:12: error: 'PINB' was not declared in this scope
   {&DDRB, &PINB, &PORTB, 4},  // B4 12
            ^~~~
In file included from .pio\libdeps\uno_wifi_rev2\SD/utility/Sd2Card.h:26:0,
                 from .pio\libdeps\uno_wifi_rev2\SD/utility/SdFat.h:29,
                 from .pio\libdeps\uno_wifi_rev2\SD/SD.h:25,
                 from src\main.cpp:34:
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:300:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:301:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 1},  // D1  1
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:302:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:302:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:302:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:303:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 3},  // D3  3
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:303:5: error: 'DDRD' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 3},  // D3  3
     ^~~~
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:301:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 1},  // D1  1
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:302:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:312:12: note: suggested alternative: 'PIN0'
   {&DDRB, &PINB, &PORTB, 4},  // B4 12
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:313:5: error: 'DDRB' was not declared in this scope
   {&DDRB, &PINB, &PORTB, 5},  // B5 13
     ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:303:5: note: suggested alternative: 'VDD'
   {&DDRD, &PIND, &PORTD, 3},  // D3  3
     ^~~~
     VDD
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:303:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 3},  // D3  3
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:302:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:303:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 3},  // D3  3
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:303:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 3},  // D3  3
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD\utility\Sd2PinMap.h:304:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 4},  // D4  4
            ^~~~
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:300:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 0},  // D0  0
            ^~~~
            PIN0
Compiling .pio\build\uno_wifi_rev2\libc51\Ethernet\socket.cpp.o
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:302:12: note: suggested alternative: 'PIN0'
   {&DDRD, &PIND, &PORTD, 2},  // D2  2
            ^~~~
            PIN0
.pio\libdeps\uno_wifi_rev2\SD/utility/Sd2PinMap.h:301:12: error: 'PIND' was not declared in this scope
   {&DDRD, &PIND, &PORTD, 1},  // D1  1

It is trying to use the SD library targeting older Arduino-AVR chips (ATMega328P).

But as you can see from

PACKAGES:

  • framework-arduino-megaavr 1.8.6
  • toolchain-atmelavr 1.70300.191015 (7.3.0)

and the contents of the framework package in C:\Users\<user>\.platformio\framework-arduino-avr-megacore\libraries

The framework has its built-in SD card library that must be used, not a library from the library registry.

The library has a declared name of

grafik

So we just use a platformio.ini of

[env:uno_wifi_rev2]
platform = atmelmegaavr
board = uno_wifi_rev2
framework = arduino 
lib_deps = 
    SPI
    SD (MegaCore)

and the standard test code (in that regards it’s the same as for other libraries) from SD/examples/CardInfo/CardInfo.ino at master · adafruit/SD · GitHub, as src\main.cpp, with an added #include <Arduino.h> at the top.

That should compile.

(Note: Due to a maybe weird setup of my PlatformIO installation I’m running into issue Using built-in library fails with KeyError: 'framework-stm32cube' · Issue #3777 · platformio/platformio-core · GitHub and had to manually specify the path of the SD (MegaCore) library. using the platformio.ini with the path specific to my computer.

[env:uno_wifi_rev2]
platform = atmelmegaavr
board = uno_wifi_rev2
framework = arduino 
lib_deps = 
    SPI
    SD (MegaCore)=file://C:\Users\Max\.platformio\packages\framework-arduino-avr-megacore\libraries\SD

Only then

Building .pio\build\uno_wifi_rev2\firmware.hex
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  13.9% (used 852 bytes from 6144 bytes)
Flash: [==        ]  24.7% (used 12003 bytes from 48640 bytes)
=================== [SUCCESS] Took 2.61 seconds ===================

).

Possible gotchas with SD cards and that board also seem to be noted at http://homepage.usys.ethz.ch/eugsterw/knowhow/arduino-wifi-micro-sd/.

Sadly, I have been unable to move past these library issues. For now I have to give up and just use Arduino IDE.

The good news is that a collaborator has purchased a MKR board and I’m hoping that PlatformIO will work for that. Very motivated to use it if I can get the board configuration to work. I understand the Arduino Uno Wifi Rev.2 is very old and PlatformIO is pretty new.

Thank you so much for your help.
Stephen

Does the above not work? What’s the exact error message here?

Experiencing the same issue, real pity that I cannot get it going either.

Compiling .pio\build\dueUSB\lib90f\ezButton\Button.cpp.o
Compiling .pio\build\dueUSB\lib90f\ezButton\ezButton.cpp.o
Compiling .pio\build\dueUSB\FrameworkArduinoVariant\variant.cpp.o
src\OPTICALencodV2_tests.cpp: In function ‘void PCINT2_vect()’:
src\OPTICALencodV2_tests.cpp:130:28: error: ‘PIND’ was not declared in this scope
portDvalShoulderEncExt = PIND & 0b00001100; // PIND4 PIND3 PIND2 = physical pins digital 2 & 3 & 4
^~~~
src\OPTICALencodV2_tests.cpp:130:28: note: suggested alternative: ‘PIOD’
portDvalShoulderEncExt = PIND & 0b00001100; // PIND4 PIND3 PIND2 = physical pins digital 2 & 3 & 4
^~~~
PIOD
src\OPTICALencodV2_tests.cpp: In function ‘void PCINT0_vect()’:
src\OPTICALencodV2_tests.cpp:161:3: error: ‘cli’ was not declared in this scope
cli();
^~~
src\OPTICALencodV2_tests.cpp:161:3: note: suggested alternative: ‘clz’
cli();
^~~

A Arduino Due is not an AVR, it’s an ARM chip. It has no PIND register like an AVR. Where do you have that project from?

Mate, you just solved my problem … HA HA what a fool i am!