2

I had recently got an Arduino Uno and did quite a few programs on it. Now, I had always used Visual Studio Code to do my C projects. So, is it possible to use Visual Studio Code to program an Arduino, but without the Arduino plugin available in Visual Studio Code?

This might sound a bit weird, but I wanted to learn how to build those type of plugins from scratch. Are there some resources from where I could learn to do that? I searched through Google, but I couldn't find any answers.

1
  • Install extension Arduino by Microsoft. its very simple to configure and use. for larger projects i would recommend platformio, BTW did you try new Arduino IDE2? if not give it a try, its much better than before.
    – sairfan
    Commented Aug 10, 2022 at 19:03

3 Answers 3

2

This might not be the answer you are looking for, but maybe it helps you and others. Besides, it's too long to write as a comment.

  1. Use VS Code only as editor

    Make sure that your .ino file is as small as possible, typically, just enough to call a second file (.cpp or .c file). The idea is that you do not need to change the .ino file often as you need to load the .ino file only in your Arduino IDE. All other files (including the .ino) you load in VS Code.

    Than you edit your files in VS Code as asual, but you compile/upload the file with the default Arduino IDE. The Arduino IDE doesn't see files being saved as new, so that's why you need not to change the .ino file often, as you need to synchronize it manually.

  2. MS Visual Studio

    I'm using MS Visual Studio, comparable to VS Code and written stubs or even emulations for certain Arduino classes (like Arduino, but also for other libraries I use on the Arduino, which mimic or at least print something when called).

    This way I can fully compile an Arduino project, and most important, run it so I can check the business logic and some parts of the hardware logic on a normal PC having a decent debugger etc. When working, I can use the first solution to upload it to an Arduino.

    Writing these stubs is quite some work and the simulation can depend on the project (like for a LED strip project I actually visualized the LEDs on a PC).

  3. In both above cases, I use the Arduino IDE only for compiling and uploading, not for editing. It would be also useful to skip using this Arduino IDE completely by using a command line to compile/upload using the CLI version of Arduino (see comment of theBusyBee below. In at least Microsoft Visual Studio but probably Visual Studio Code external commands can be added calling this Arduino IDE for compiling/uploading.

  4. PMF's comment below: You can use VisualMicro on top of Microsoft Visual Studio; this is a paid extension.

8
  • 1
    You might want to add that the Arduino infrastructure allows building by the command line. There are also some questions here... Commented Aug 11, 2022 at 6:47
  • @thebusybee That's indeed a good addition. Not sure which questions you refer to. Commented Aug 11, 2022 at 7:17
  • Well, my free time is heavily limited, so I don't think I can search for and choose one. Perhaps someone else can do this and add it to the answer. Commented Aug 11, 2022 at 7:41
  • 1
    Oh, I think we have a misunderstanding, perhaps. I meant that some questions here on SE/Arduino refer to CLI usage and might have good answers, worth to link to them. I did not mean that some points in this question are left open. Commented Aug 11, 2022 at 9:14
  • 1
    Because Visual Studio was mentioned: There's actually an extension called "VisualMicro" that adds all features of the Arduino IDE to Visual Studio (+ a live debugger). It's not free, but cheap enough also for private projects.
    – PMF
    Commented Aug 11, 2022 at 13:33
5

If you really looking for an alternate for Arduino IDE. Than I will recommends you to go with platformio. It has great library management.

Just install the platformio extensions on the vs code and you are ready to go.

2

You can write C++ file with the editor of your choice, include avr/io.h to manage Arduino I/O, and then compile with avr-gcc and upload with avrdude. This is what I do because I don't like working with the .ino sketch directory structure that hides away normal C++ code that you would use with any other microcontroller. (See What is the relationship of an Arduino .ino file to main.cpp?, Why does an `.ino` file have to be in a folder of the same name?)

Guide: https://create.arduino.cc/projecthub/milanistef/introduction-to-bare-metal-programming-in-arduino-uno-f3e2b4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.