Eureka! No red line under Arduino.h

I guess I shouldn't have been trying to do this on a Mac though admittedly I only bought a Windows machine recently.

Trying to get Arduino library development on VS Code setup properly has been a bloody nightmare. I thought I had it sorted on my Mac but after a year or so gap between library developments, it doesn't work all of a sudden (the bane of every programmers life I guess).

So I switched to the Windows machine that I have bought in the last year and managed to get it working fairly quickly (I think! Only using a super simple test library generated by ChatGPT so far).

The issue was always that I couldn't get Arduino.h recognised and 'squiggles' working properly.

Adding C:\Users\xxxxx\AppData\Local\Arduino15** helped a lot with the former.
The project settings.json file then added "C_Cpp.errorSquiggles": "enabled" for me

Looks like this is solved. Only took me about 10 years

Well I spoke too soon. I'm getting:

fatal error: avr/pgmspace.h: No such file or directory
28 | #include <avr/pgmspace.h>

Tried to add the libraries folder as a -I argument in tasks.json but still doesn't work

Which board are you compiling for?

At the moment I'm just trying to setup the most basic scenario with the most basic library. I can't even do that!

I can get the source files recognised and intellisense all working but will it compile....? No!

Lets say UNO first and then adding in Nano 33 IoT later.

OK, that should be OK. As you might guess from the avr part of the path, this header is specific to the AVR architecture. However, due to being used in a lot of Arduino code, an avr/pgmspace.h header file has been added to the core of some boards platforms of non-AVR architectures as well for the sake of compatibility. The platform of the Nano 33 IoT is one of those.


When compiling for the Uno, the file is at a path like this:

C:\Users\xxxxx\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h

(the 7.3.0-atmel3.6.1-arduino7 part of the path might be different if you are using an older version of the "Arduino AVR Boards" platform, but you can extrapolate the correct path in that case)


When compiling for the Nano 33 IoT, the file is at a path like this:

"C:\Users\xxxxx\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino\api\deprecated-avr-comp\avr\pgmspace.h"

(the 1.8.13 part of the path is dependent on which version of the "Arduino SAMD Boards (32-bits ARM Cortex-M0+)" boards platform you have installed)

Thanks - lets forget about the samd boards for now. The real question is this:

Has anybody at all written an Arduino library with VS Code and if so, how have they done it? Writing the library is of no consequence or difficulty. It is the setting up of th C++ environment in VS Code such that intellisense works perfectly AND the library code builds.

Sorry if I wasn't clear before.

Pete....

For now I'm just writing sketches. That will do for now. I spent a whole day trying every which way of include paths and VS Code setttings to no avail. I'm sure there is an answer - I just don't have it. I find it hard to believe I cannot find a simple project template in VS Code to write an Arduino library. All the templates are just straightforward library development, but using the Arduino IDE for this is ridiculous and painful. The VS Code templates/examples are for setting up sketch development which is useful for the library examples but not the library itself.

Anyway, here's hoping someone has done it and it is even possible

Many thanks

Pete...

Am I the first person in the World to do this? Surely not? I'll see if Microsoft can help as I'm guessing some of their engineers will be using VS Code to build Arduino libraries.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.