Go Down

Topic: Visual Studio Code help - main sketch file? (Read 3096 times) previous topic - next topic


I am using VSCode to write some code for my arduino and have what is probably a relatively dumb question...

How do I change the main sketch file?

As in, when you first open the program and hit the "verify" or "upload" button, it gives you a text box to select which file you want to work with. But I want to upload a different file now but am not sure how to change which one the IDE is working with.

The only way I am able to work around this without completely restarting the program is to rename the previous file to "[filename].h" or some other extension that cannot upload to an arduino board and only then it gives me the option to select the main sketch file again.

Thanks, learning a new IDE can be frustrating sometimes  >:(


That really sounds like dumb question, maybe you don't describe your problem properly?

Write your code and save it once, then try to upload it to the board of your choice???

It is like any other text editor, so use it like one.

The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"


Aug 04, 2019, 01:01 pm Last Edit: Aug 04, 2019, 01:03 pm by noehays
I'm having the same problem as the OP. Instead verifying and uploading the sketch in the active tab (like the Arduino IDE does), the VSCode Arduino extension is operating on whatever file is referred to in a line of .vscode/arduino.json constructed as "sketch": "examples/01.Basics/Blink.ino". The only way I have found to verify or upload a different sketch is to edit or delete the arduino.json file.

I'm running VSCode on Linux Mint 19 Cinnamon 64-bit, using the Microsoft Arduino extension. Here are some of the steps of how the problem happens:

1) Delete the .vscode/arduino.json file in my Arduino workspace to start fresh
2) Open VSCode
3) Open an arduino sketch (sketch A)
4) Select board and serial port
5) Click on "verify" -- a message pops up asking me to "Select the main sketch file", with an unorganized dropdown menu of every single sketch that is in any of the workspace folders.
6) I select the filename of sketch A, designating a "main sketch file", and it verifies the sketch
7) Open another sketch (sketch B)
8 ) Click on "verify"
PROBLEM: VSCode verifies sketch A, but I want it to verify sketch B.

I can't figure out how to tell VSCode that I want to verify the sketch I am editing, rather than the one I first selected. The dropdown list does not even appear a second time.

Other than editing the json file, does anyone know how to select a different sketch?



I've just spent two hours with this same problem (long-time Arduino IDE user, new VScode user).

The OP was told that it sounded like a dumb question..but what's the answer? I'm stuck too...


Oct 30, 2019, 11:03 am Last Edit: Oct 30, 2019, 11:04 am by gdot
The simplest solution I found is to save each file in a different Workspace.
Then you can switch the Workspace when you like to upload the other file.

More on VS Code Workspaces on stackoverflow.

There is no such thing as a stupid question, only stupid answers


Dec 08, 2019, 11:48 am Last Edit: Dec 08, 2019, 11:49 am by jsroques
It is no dumb question IMO... (there is no such thing as dumb question anyway ;-)

Also struggling with this. I am working on 2 sketches simultaneously for 2 arduinos communicating thru I2C. Switching from one to the other is just a pain.

I have to
  • swap the sketch (did not find any efficient way)
  • change the COM port
  • and possibly changing the board type

I often end up uploading the sketch to the wrong arduino or compile for the wrong board :-(

I'll try the multiple workspaces trick.
May be also the multi root workspace would be helpful.



That really sounds like dumb question, maybe you don't describe your problem properly?

Wow, that's a bit harsh.

In VSCode, the 'Main' or 'Workspace' .ino file that will get uploaded should be listed at the VERY bottom of the VS Code window.  As in the very thin anchor toolbar (Mine is background in blue and shows current setup board, com port, path to the sketch .ino file, plus a few other pieces of info).  Click that .ino file and you'll get that popup box that you first had in the beginning.  Paste in your new file path, and you're set.  

Also - If you right click the tab of the file you want to be the new 'Main' .ino file, there is a dropdown for 'Copy Relative Path'.  So right click and copy the relative path of the file you want, click the main sketch file in the footer, and paste into the popup box.

Go Up