PlatformIO Community

Including the arduino library

Hello. I built a baremetal project and now want to use an arduino stepper motor library so need to include arduino.h

I get squiggles in my header file when I try to do this:
image

and obviously, squiggles don’t compile:

Compiling .pio\build\ATmega4809\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\WInterrupts.cpp.o
In file included from C:\Users\Paul\.platformio\packages\framework-arduino-megaavr\cores\arduino\Arduino.h:140:0,
                 from C:\Users\Paul\.platformio\packages\framework-arduino-megaavr\cores\arduino\wiring_private.h:31,
                 from C:\Users\Paul\.platformio\packages\framework-arduino-megaavr\cores\arduino\WInterrupts.cpp:33:
C:\Users\Paul\.platformio\packages\framework-arduino-megaavr\cores\arduino\UART.h:28:10: fatal error: pins_arduino.h: No such file or directory

**********************************************************************
* Looking for pins_arduino.h dependency? Check our library registry!

My arduino IDE works fine, have I missed a path perhaps?

It depends on the selected variant & the existance of that variant folder in the core for that to work.

Assuming you are using board = ATmega4809, it has

And the core matchingly has the 48pin-standard folder. PlatformIO has the MegaCoreX package as C:\Users\<user>\.platformio\packages\framework-arduino-megaavr-megacorex

However, as we can see from your log, the error comes from

Which is not the MegaCoreX but the original Arduino core https://github.com/arduino/ArduinoCore-megaavr/tree/master/variants, which does not have that variant folder.

So It’s using the wrong Arduino core package for you.

Please post your full platformio.ini. Did you do any modifications to C:\Users\<user>\.platformio\platforms\atmelmegaavr\boards\ATmega4809.json?

thanks for all the info. I have got it to compile now with the PIO.ini shown below.

However and I’m not sure it’s a problem, the squiggles on the line #include <arduino.h> remain. A hover over the line shows:
image

PIO.ini as folows:


[env:ATmega4809]

board = ATmega4809
platform = atmelmegaavr
framework = arduino

board_build.variant = 40pin-standard  


monitor_flags = 
  --echo
upload_protocol = custom
upload_flags =
    -C
    $PROJECT_PACKAGES_DIR/tool-avrdude-megaavr/avrdude.conf
    -p
    $BOARD_MCU
    -c
    xplainedmini_updi
    -Pusb
    -b115200
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
debug_tool = custom
; no debug server
debug_server =
debug_port = 127.0.0.1:12555
build_type = debug
debug_load_mode = manual
debug_init_cmds =
  target extended-remote $DEBUG_PORT
  $INIT_BREAK
debug_init_break = tbreak loop

To answer the query

Did you do any modifications to C:\Users\<user>\.platformio\platforms\atmelmegaavr\boards\ATmega4809.json?

No I made no mods.

I have just noticed also that although the code compiles, in my main.cpp the the include line for my header file

#include “encoder.h” also has squiggles.

thanks.

When I use your above exact platformio.ini and a minimal code

#include <Arduino.h>
void setup(){}
void loop(){}

it compiles for me.

>pio run
Processing ATmega4809 (board: ATmega4809; platform: atmelmegaavr; framework: arduino)
------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATmega4809.html
PLATFORM: Atmel megaAVR (1.5.0) > ATmega4809
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 48KB Flash
PACKAGES:
 - framework-arduino-megaavr-megacorex 1.0.9
 - toolchain-atmelavr 2.70300.201015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\ATmega4809\src\main.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\CDC.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\UART.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\UART0.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\UART1.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\UART2.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\UART3.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\UNO_compat.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\ATmega4809\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\abi.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\Common.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\IPAddress.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\PluggableUSB.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\Print.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\RingBuffer.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\Stream.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\api\String.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\hooks.c.o
Compiling .pio\build\ATmega4809\FrameworkArduino\main.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\new.cpp.o
Compiling .pio\build\ATmega4809\FrameworkArduino\wiring.c.o
Compiling .pio\build\ATmega4809\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\ATmega4809\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\ATmega4809\FrameworkArduino\wiring_pulse.S.o
Compiling .pio\build\ATmega4809\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\ATmega4809\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\ATmega4809\libFrameworkArduino.a
Indexing .pio\build\ATmega4809\libFrameworkArduino.a
Linking .pio\build\ATmega4809\firmware.elf
Checking size .pio\build\ATmega4809\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.1% (used 4 bytes from 6144 bytes)
Flash: [          ]   1.2% (used 602 bytes from 49152 bytes)
Building .pio\build\ATmega4809\firmware.hex
============================================= [SUCCESS] Took 2.03 seconds =============================================

So you likely have corrupted files.

Remove the folder C:\Users\<user>\.platformio\packages\framework-arduino-megaavr-megacorex first and then rebuild the project.

You should also rather write #include <Arduino.h> in the correct uppercasing so that your code can compile on non-Windows machine which require you to use the correct spelling.

yep, that worked, thanks for help.