Code Monkey home page Code Monkey logo

vscode-arduino's Introduction

Visual Studio Code extension for Arduino

Gitter

Welcome to the Visual Studio Code extension for Arduino preview ! The Arduino extension makes it easy to develop, build, and deploy your Arduino sketches in Visual Studio Code, with a rich set of functionalities. These include:

  • IntelliSense and syntax highlighting for Arduino sketches
  • Verify and upload your sketches in Visual Studio Code
  • Built-in board and library manager
  • Built-in example list
  • Built-in serial monitor
  • Snippets for sketches
  • Automatic Arduino project scaffolding
  • Command Palette (F1) integration of frequently used commands (e.g. Verify, Upload...)

Prerequisites

Either the legacy Arduino IDE or Arduino CLI are required. The recommended approach is to use the version of Arduino CLI that comes bundled with the extension, which works out of the box. Support for the legacy Arduino IDE will be removed in a future version of the extension.

Arduino CLI

To use the bundled version of Arduino CLI, arduino.useArduinoCli should be true, and arduino.path and arduino.commandPath should be empty or unset. arduino.useArduinoCli defaults to false while we deprecate support for the Arduino IDE, but there will be a prompt when the extension first activates to switch to the Arduino CLI.

If you want to use a custom version of Arduino CLI, it can be downloaded from the repository's release page. For custom versions, arduino.path must be set to the directory containing the Arduino CLI executable.

Legacy Arduino IDE

Use of the legacy Arduino IDE is not recommended, and support for the legacy Arduino IDE will be removed in a future version of the extension. The legacy Arduino IDE can be installed from the Arduino download page.

  • The supported legacy Arduino IDE versions are 1.6.x and up to, but not including, 2.0.0.
  • The Windows Store's version of the Arduino IDE is not supported because of the sandbox environment that the application runs in.
  • Note: Arduino IDE 1.8.7 had some breaking changes, causing board package and library installation failures. These failures were corrected in 1.8.8 and later.
  • Note: Arduino IDE 2.X.Y is not supported and there are no plans for support in the future (issue 1477).

Installation

Open VS Code and press F1 or Ctrl + Shift + P or Cmd + Shift + P to open command palette, select Install Extension and type vscode-arduino.

Or launch VS Code Quick Open (Ctrl + P or Cmd + P ), paste the following command, and press enter.

ext install vscode-arduino

You can also install directly from the Marketplace within Visual Studio Code, searching for Arduino.

Get Started

You can find code samples and tutorials each time that you connect a supported device. Alternatively you can visit our IoT Developer Blog Space or Get Started Tutorials.

Commands

This extension provides several commands in the Command Palette (F1 or Ctrl + Shift + P or Cmd + Shift + P) for working with *.ino files:

  • Arduino: Board Manager: Manage packages for boards. You can add 3rd party Arduino board by configuring Additional Board Manager URLs in the board manager.
  • Arduino: Change Board Type: Change board type or platform.
  • Arduino: Change Timestamp Format: Change format of timestamp printed before each line of Serial Monitor output.
  • Arduino: Close Serial Monitor: Stop the serial monitor and release the serial port.
  • Arduino: Examples: Show list of examples.
  • Arduino: Initialize: Scaffold a VS Code project with an Arduino sketch.
  • Arduino: Library Manager: Explore and manage libraries.
  • Arduino: Open Serial Monitor: Open the serial monitor in the integrated output window.
  • Arduino: Select Serial Port: Change the current serial port.
  • Arduino: Upload: Build sketch and upload to Arduino board.
  • Arduino: CLI Upload: Upload complied code without building sketch (CLI only).
  • Arduino: Upload Using Programmer: Upload using an external programmer.
  • Arduino: CLI Upload Using Programmer: Upload using an external programmer without building sketch (CLI only).
  • Arduino: Verify: Build sketch.
  • Arduino: Rebuild IntelliSense Configuration: Forced/manual rebuild of the IntelliSense configuration. The extension analyzes Arduino's build output and sets the IntelliSense include paths, defines, compiler arguments accordingly.

Keybindings

  • Arduino: Upload Alt + Cmd + U or Alt + Ctrl + U
  • Arduino: Verify Alt + Cmd + R or Alt + Ctrl + R
  • Arduino: Rebuild IntelliSense Configuration Alt + Cmd + I or Alt + Ctrl + I

Options

Option Description
arduino.useArduinoCli Whether to use the Arduino CLI (true) or the legacy Arduino IDE (false) -- defaults to false. If using true, either leave the arduino.path and arduino.commandPath values unset to use the bundled version of Arduino CLI, or point them at a custom version of Arduino CLI. Note that a future version of the extension will change this default to true and remove support for legacy Arduino IDE.
arduino.path Path to the Arduino installation. You can use a custom version of Arduino by modifying this setting to include the full path. Example: C:\\Program Files\\Arduino for Windows, /Applications for Mac, /home/<username>/Downloads/arduino-1.8.1 for Linux. (Requires a restart after change). The default value is automatically detected from your legacy Arduino IDE installation path. To use the Arduino CLI, use the path that contains the arduino-cli executable (e.g. /usr/local/bin), or leave it unset to use the bundled version of Arduino CLI.
arduino.commandPath Path to an executable (or script) relative to arduino.path. The default value is arduino_debug.exe for Windows, Contents/MacOS/Arduino for Mac and arduino for Linux, You also can use a custom launch script to run Arduino by modifying this setting. (Requires a restart after change) Example: run-arduino.bat for Windows, Contents/MacOS/run-arduino.sh for Mac and bin/run-arduino.sh for Linux. To use the bundled version of Arduino CLI, leave this option unset. To use a custom version of Arduino CLI, use arduino-cli.
arduino.additionalUrls Additional Boards Manager URLs for 3rd party packages as a string array. The default value is empty.
arduino.logLevel CLI output log level. Could be info or verbose. The default value is "info".
arduino.clearOutputOnBuild Clear the output logs before uploading or verifying. Default value is false.
arduino.allowPDEFiletype Allow the VSCode Arduino extension to open .pde files from pre-1.0.0 versions of Arduino. Note that this will break Processing code. Default value is false.
arduino.enableUSBDetection Enable/disable USB detection from the VSCode Arduino extension. The default value is true. When your device is plugged in to your computer, it will pop up a message "Detected board ****, Would you like to switch to this board type". After clicking the Yes button, it will automatically detect which serial port (COM) is connected a USB device. If your device does not support this feature, please provide us with the PID/VID of your device; the code format is defined in misc/usbmapping.json.To learn more about how to list the vid/pid, use the following tools: https://github.com/EmergingTechnologyAdvisors/node-serialport npm install -g serialport serialport-list -f jsonline
arduino.disableTestingOpen Enable/disable automatic sending of a test message to the serial port for checking the open status. The default value is false (a test message will be sent).
arduino.skipHeaderProvider Enable/disable the extension providing completion items for headers. This functionality is included in newer versions of the C++ extension. The default value is false.
arduino.disableIntelliSenseAutoGen When true vscode-arduino will not auto-generate an IntelliSense configuration (i.e. .vscode/c_cpp_properties.json) by analyzing Arduino's compiler output.
arduino.analyzeOnOpen When true, automatically run analysis when the project is opened. Only works when arduino.analyzeOnSettingChange is true.
arduino.analyzeOnSettingChange When true, automatically run analysis when board, configuration, or sketch settings are changed.

The following Visual Studio Code settings are available for the Arduino extension. These can be set in global user preferences Ctrl + , or Cmd + , or workspace settings (.vscode/settings.json). The latter overrides the former.

{
    "arduino.useArduinoCli": true,
    "arduino.logLevel": "info",
    "arduino.allowPDEFiletype": false,
    "arduino.enableUSBDetection": true,
    "arduino.disableTestingOpen": false,
    "arduino.skipHeaderProvider": false,
    "arduino.additionalUrls": [
        "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json",
        "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
    ],
}

The following settings are as per sketch settings of the Arduino extension. You can find them in .vscode/arduino.json under the workspace.

{
    "sketch": "example.ino",
    "port": "COM5",
    "board": "adafruit:samd:adafruit_feather_m0",
    "output": "../build",
    "prebuild": "./prebuild.sh",
    "postbuild": "./postbuild.sh",
    "intelliSenseGen": "global"
}
  • sketch - The main sketch file name of Arduino.
  • port - Name of the serial port connected to the device. Can be set by the Arduino: Select Serial Port command. For Mac users could be "/dev/cu.wchusbserial1420".
  • board - Currently selected Arduino board alias. Can be set by the Arduino: Change Board Type command. Also, you can find the board list there.
  • output - Arduino build output path. If not set, Arduino will create a new temporary output folder each time, which means it cannot reuse the intermediate result of the previous build leading to long verify/upload time, so it is recommended to set the field. Arduino requires that the output path should not be the workspace itself or in a subfolder of the workspace, otherwise, it may not work correctly. By default, this option is not set. It's worth noting that the contents of this file could be deleted during the build process, so pick (or create) a directory that will not store files you want to keep.
  • prebuild - External command which will be invoked before any sketch build (verify, upload, ...). For details see the Pre- and Post-Build Commands section.
  • postbuild - External command to be run after the sketch has been built successfully. See the afore mentioned section for more details.
  • intelliSenseGen - Override the global setting for auto-generation of the IntelliSense configuration (i.e. .vscode/c_cpp_properties.json). Three options are available:
    • "global": Use the global settings (default)
    • "disable": Disable the auto-generation even if globally enabled
    • "enable": Enable the auto-generation even if globally disabled
  • buildPreferences - Set Arduino preferences which then are used during any build (verify, upload, ...). This allows for extra defines, compiler options or includes. The preference key-value pairs must be set as follows:
    "buildPreferences": [
        ["build.extra_flags", "-DMY_DEFINE=666 -DANOTHER_DEFINE=3.14 -Wall"],
        ["compiler.cpp.extra_flags", "-DYET_ANOTER=\"hello\""]
    ]
}

Known limitations/restrictions

  • Header files to include in a .ino sketch have to be in a sub-directory (e.g. put a header into foo/foo.h and then use #include foo/foo.h). Without this subdirectory (e.g. foo.h directly next to the .ino file using #include "foo.h"), the compile step will fail. (issue 1389

Pre- and Post-Build Commands

On Windows the commands run within a cmd-, on Linux and OSX within a bash-instance. Therefore your command can be anything what you can run within those shells. Instead of running a command you can invoke a script. This makes writing more complex pre-/post-build mechanisms much easier and opens up the possibility to run python or other scripting languages. The commands run within the workspace root directory and vscode-arduino sets the following environment variables: VSCA_BUILD_MODE The current build mode, one of Verifying, Uploading, Uploading (programmer) or Analyzing. This allows you to run your script on certain build modes only. VSCA_SKETCH The sketch file relative to your workspace root directory. VSCA_BOARD Your board and configuration, e.g. arduino:avr:nano:cpu=atmega328. VSCA_WORKSPACE_DIR The absolute path of your workspace root directory. VSCA_LOG_LEVEL The current log level. This allows you to control the verbosity of your scripts. VSCA_SERIAL The serial port used for uploading. Not set if you haven't set one in your arduino.json. VSCA_BUILD_DIR The build directory. Not set if you haven't set one in your arduino.json.

For example under Windows the following arduino.json setup

{
    "board": "arduino:avr:nano",
    "sketch": "test.ino",
    "configuration": "cpu=atmega328",
    "prebuild": "IF \"%VSCA_BUILD_MODE%\"==\"Verifying\" (echo VSCA_BUILD_MODE=%VSCA_BUILD_MODE% && echo VSCA_BOARD=%VSCA_BOARD%)"
}

will produce

[Starting] Verifying sketch 'test.ino'
Running pre-build command: "IF "%VSCA_BUILD_MODE%"=="Verifying" (echo VSCA_BUILD_MODE=%VSCA_BUILD_MODE% && echo VSCA_BOARD=%VSCA_BOARD%)"
VSCA_BUILD_MODE=Verifying
VSCA_BOARD=arduino:avr:nano:cpu=atmega328
Loading configuration...
<...>

when verifying.

IntelliSense

vscode-arduino auto-configures IntelliSense by default. vscode-arduino analyzes Arduino's compiler output by running a separate build and generates the corresponding configuration file at .vscode/c_cpp_properties.json. vscode-arduino tries as hard as possible to keep things up to date, e.g. it runs the analysis when switching the board or the sketch.

It doesn't makes sense though to run the analysis repeatedly. Therefore if the workspace reports problems ("squiggles") - for instance after adding new includes from a new library - run the analysis manually:

Manual rebuild: Arduino: Rebuild IntelliSense Configuration, Keybindings: Alt + Cmd + I or Alt + Ctrl + I

When the analysis is invoked manually it ignores any global and project specific disable.

IntelliSense Configurations

vscode-arduino's analysis stores the result as a dedicated IntelliSense-configuration named Arduino. You have to select it from the far right of the status bar when you're in one of your source files as shown here:

74001156-cfce8280-496a-11ea-9b9d-7d30c83765c1

This system allows you to setup and use own IntelliSense configurations in parallel to the automatically generated configurations provided through vscode-arduino. Just add your configuration to c_cpp_properties.json and name it differently from the default configuration (Arduino), e.g. My awesome configuration and select it from the status bar or via the command palette command C/C++: Select a Configuration...

Change Log

See the Change log for details about the changes in each version.

Supported Operating Systems

Currently this extension supports the following operating systems:

  • Windows 7 and later (32-bit and 64-bit)
  • macOS 10.10 and later
  • Ubuntu 16.04
    • The extension might work on other Linux distributions, as reported by other users, but without guarantee.

Support

You can find the full list of issues on the Issue Tracker. You can submit a bug or feature suggestion, and participate in community driven discussions.

Development

Installation prerequisites:

To run and develop, do the following:

  • git clone https://github.com/microsoft/vscode-arduino
  • cd vscode-arduino
  • Run npm i
  • Run npm i -g gulp
  • Open in Visual Studio Code (code .)
  • Press F5 to debug.

To test, press F5 in VS Code with the "Launch Tests" debug configuration.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information please see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Privacy Statement

The Microsoft Enterprise and Developer Privacy Statement describes the privacy statement of this software.

License

This extension is licensed under the MIT License. Please see the Third Party Notice file for additional copyright notices and terms.

Contact Us

If you would like to help build the best Arduino experience with VS Code, you can reach us directly at gitter chat room.

vscode-arduino's People

Contributors

adiazulay avatar akaroml avatar andxu avatar aster94 avatar belked avatar benmcmorran avatar blackchoey avatar codeworm96 avatar czgtest avatar davidcooper1 avatar dependabot[bot] avatar deqingsun avatar dilin-ms avatar dooriya avatar eduherminio avatar elektronikworkshop avatar fearthecowboy avatar gcampbell-msft avatar hellyzh avatar hlovdal avatar jogo- avatar kopp avatar maddogjt avatar rferrese avatar robotdad avatar sffamily avatar sneezry avatar testforstephen avatar two-pack avatar yaohaizh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-arduino's Issues

UI Integration - Sprint 1

This is the checklist for all the UI tasks in Spring 1

  • COM port for serial monitoring - Status bar
  • Band rate for serial monitoring -Status bar
  • Serial monitoring - Integrated output window
  • Arduino output - Integrated output window
  • Built-in samples - Tree explorer
  • [ ] F5 integration with build and deploy

Arduino integration - Output UI integration

The users should have installed Arduino IDE before they try this extension. The extension will provide an integrated output window - Arduino. The behavior of this output window should be the same as the output in Arduino IDE, i.e., all the output from Arduino executable command.

  • Windows
  • macOS

Syntax highlighting for *.ino files

The expected behavior of *.ino Syntax highlighting is,

  • Syntax highlighting support for all C/C++keywords
  • Syntax highlighting support for Arduino keywords (e.g. Serial...)

We don't cover *.pde sketch file in this sprint.
We don't cover in-line assembly code in this sprint either.

Boards Manager in HTML preview

Use the previewHTML to show the Boards manager. The UI in previewHTML should be almost the same as what we see in Arduino IDE.

There should be a new task resisted in VSCode command palette - Boards Manager. When start the Boards Manager, there will be a Board Manager window showing in previewHTML side by side with the editor area (vscode.ViewColumn.Two). There are more things in this previewHTML, from top to bottom.

  • [P2] Drop-down Filter and search form
  • [P1] Platform package name. format: {package name} by {Company Name} [version] [INSTALLED]
  • [P1] Boards included in this package
  • [P2] Online help link
  • [P2] More info link
  • [P1] Version selector
  • [P1] Install/Update/Remove

The info shows in this previewHTML should come from #19

Need UX input.

Boards Manager fundamental utilities

There are two kinds of boards in Arduino IDE.

  • Official boards
  • 3rd party boards

Given that we haven't decided the config file schema, in this sprint, we only support the official Arduino boards.

The board manager fundamental utilities should include:

  • Parse the board json file from http://downloads.arduino.cc/packages/package_index.json
  • Verify the json file from the signature http://downloads.arduino.cc/packages/package_index.json.sig
  • Generate the local cache for each toolchain
  • Compare with downloaded toolchain. (Installed? New version?)
  • Download the toolchain of specified board and version.
  • Unzip it and put it to the platform folder of Arduino IDE.

[ArduinoDebug]Integrate gdb into vscode.

Features:

  1. Start/Stop Debug, (F5, shift+F5)
  2. Insert/Remove/Disable BreakPoint(BP).
  3. Hit on BP, with locals, threads, watch support
  4. Step/Step in/Step out/Run to cursor
  5. Termination of process detect
  6. Configuration for debug feature.

Arduino integration - Upload

The users should have installed Arduino IDE before they try this extension. The extension will provide a F1 task - upload. Basically it will run a local excitable command like below.

  • Windows: arduino.exe --upload [sketch path] -v --board [board name] --port [port]

We don't support Linux distros and macOS in this sprint.

Boards Manager in Tree Explorer

Boards manager UI integration in VSCode Insiders - Tree Explorer

The list should come from the #19 .
Context Menu (showQuickPick): Still need discussion.

Example list - Built-in example

The users should have installed Arduino IDE before they try this extension. The extension will provide a tree view on the left side in VS Code Insiders. There are three types of examples. The list below shows the file locations on Windows.

  • Build-in examples
    • File location: {Installation Path}\Arduino\examples
  • Examples for any board
    • File location for default libs: {Installation Path}\libraries\{lib name}\examples
    • File location for imported libs: {User documents path}\Arduino\libraries\{lib name}\examples
  • Example for specified board
    • File location: {UserAppdata}\Local\Arduino15\packages\arduino\hardware\{hw name}\{version}\libraries\{lib name}\examples
    • {UserAppdata}\Local\Arduino15\packages\arduino\hardware\samd\1.6.9\libraries\USBHost\examples

This sprint, we only cover the built-in examples.

Press F5 to build .ino file and deploy to device

Currently pressing F5 while an INO file is opened triggers nothing. The expected behavior is:

  1. User press F5
  2. Start the build process and show the output window for user to see the build result
  3. After build succeeded, upload the binaries to current device

Read sketch configuration from Arduino IDE

At the end of the day, we will build the VS Code extension without installing Arudino IDE. We should think about the project file structure in that extension.

But at current stage, we believe the right approach is to read the config file from Arduino IDE. To leverage as much config as we can. The limitation in this approach is that users have to config everything correctly in Arduino IDE first before they turn to VS Code to do code editing.

The expected behavior is

  1. Configure everything correctly in Arduino IDE, including board type, COM port and so on.
  2. Go to VS Code to open the *.ino file and start coding.
  3. Use VS Code to verify and upload.

Language Mode - Associate *.ino with Arduino

We'd like to have a language identifier for *.ino files in the VS Code. This would be great if someday the VS Code can automatically suggest the user to install our Arduino extension when he/she open a *.ino file in VS Code.

The mock-up is showing below.
image

Arduino integration - Verify/Compile

The users should have installed Arduino IDE before they try this extension. The extension will provide a F1 task - Verify. Basically it will run a local excitable command like below.

  • Windows: arduino.exe --verify [sketch path] -v

We don't support Linux distros and macOS in this sprint.

Serial Monitoring

Provide a integrated window in VSCode to support serial monitoring for sending and receiving the serial messages. The expected behavior should be the same as the serial monitoring tool in Arduino IDE. Due to the UI limitation in VSCode, we could use a F1 task to send messages. Also, the COM port and band rate should be configurable.

  • Serial listening from the integrated window
  • F1 task: send a message
  • Configurable COM port and band rate

The library for serial stuffs need to be built in different platforms.

  • Windows
  • macOS

In this sprint, we don't support Linux distros.

IntelliSense - code completions for *.ino codes

Provide context-aware code completion for *.ino files. The expected behavior is showing the pop-up list when the user type a letter in the editor. The pop-up list should automatically lists all the available member functions and all the available member attributes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.