Skip to content

Instantly share code, notes, and snippets.

@Jerrylum
Created September 14, 2022 14:53
Show Gist options
  • Save Jerrylum/e834c1128f4e60eac3f9302f942d73f7 to your computer and use it in GitHub Desktop.
Save Jerrylum/e834c1128f4e60eac3f9302f942d73f7 to your computer and use it in GitHub Desktop.
How to use Arduino CLI to program ESP32

Development

Suggested user settings, Arduino CLI is optional.

{
    "arduino.path": "C:\\Users\\jerrylum\\Documents\\Application\\arduino-cli_0.27.1_Windows_64bit",
    "arduino.useArduinoCli": true,
    "arduino.commandPath": "arduino-cli.exe"
}

To setup the development environment, run the following commands in the console.

arduino-cli config init
arduino-cli config set board_manager.additional_urls "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json"
arduino-cli config set library.enable_unsafe_install true

arduino-cli core update-index
arduino-cli core install esp32:esp32

arduino-cli lib install "ArduinoJson"
arduino-cli lib install "ArxContainer"
arduino-cli lib install "CAN"
arduino-cli lib install --git-url https://github.com/collin80/can_common
arduino-cli lib install "due_can"
arduino-cli lib install --git-url https://github.com/collin80/esp32_can
arduino-cli lib install "ESP32Servo"
arduino-cli lib install "MsgPack"
arduino-cli lib install "Packetizer"
arduino-cli lib install --git-url https://github.com/aed3/PS4-esp32
arduino-cli lib install "Task Scheduler"

The following libraries should be installed.

$ arduino-cli lib list
ArduinoJson    6.19.4    -         LIBRARY_LOCATION_USER -
ArxContainer   0.4.0     -         LIBRARY_LOCATION_USER -
CAN            0.3.1     -         LIBRARY_LOCATION_USER -
can_common     0.3.0     -         LIBRARY_LOCATION_USER -
due_can        2.0.1     -         LIBRARY_LOCATION_USER -
ESP32_CAN      0.2.5     -         LIBRARY_LOCATION_USER -
ESP32Servo     0.11.0    -         LIBRARY_LOCATION_USER -
MsgPack        0.3.19    -         LIBRARY_LOCATION_USER -
Packetizer     0.7.0     -         LIBRARY_LOCATION_USER -
PS4Controller  2.1       -         LIBRARY_LOCATION_USER -
Task Scheduler 1.4       -         LIBRARY_LOCATION_USER -

IMPORTANT: If your .ino file is called test.ino make sure it is inside a folder called test.

Create the file .vscode/arduino.json and add the following content.

{
    "sketch": "<FOLDER_NAME>.ino",
    "configuration": "PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none",
    "board": "esp32:esp32:esp32",
    "output": "build"
}

The IntelliSense configuration (.vscode/c_cpp_properties.json) should be able to automatically generated. However, it might fail to do so ([Warning] Failed to generate IntelliSense configuration.). If that happens, you can manually create the file and copy the following suggested content.

{
    "configurations": [
        {
            "name": "Arduino",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Users/jerrylum/Documents/Arduino/libraries/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment