Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Arduino CLI Setup tutorial.

NotificationsYou must be signed in to change notification settings

B45i/arduino-cli-how-to

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

One software that I use very often but absolutely hate is the Arduino IDE.

The UI is simple and non-intimidating, even a beginner can use it very easily without any trouble.But I will say Arduino IDE is bit underwhelming as an IDE, At least by today's standard.

  • It doesn't have proper intellisense.
  • It doesn't have "goto definition" / "goto declaration" feature.
  • No variable renaming.
  • Even though it supports tabs, You can only open files from the same project.
  • No git integration.
  • No custom font support.
  • Indentation is using 2 spaces only and no way to control it.
  • Most of all, NO DARK THEME. (I know we can tweak the theme little bit but it always looked imperfect).

I can go on about the reasons to hate Arduino IDE.

Over time the Arduino team has added some nice features to the IDE but the development experience is same. You can feel that its a software from the 2000s.

There were some attempts like Arduino extension for VS Code and plarformIOPlatformIO has a different code structure so if you share your project online, Beginners will have a hard time recreating your project.For the Arduino extension to work, You need to have the Arduino IDE already installed in your system. I felt it like a "hacky" setup.

About a year ago, Arduino launched arduino-cli, their CLI tool written in google's go programing language is powering Arduino Create Web Editor.

Advantage of the arduin-cli is that you can write code in your favourite text editor and compile and upload the code to the specified board using the CLI tool.

CLI is very small in size (about 7MB). but packs all the major feature of the IDE.

Install the CLI

On windows

  1. Download the cli tool fromhere

  2. Extract thearduino-cli.exe file to a folder which is indexed inPATH.

  • Either you can move thearduino-cli.exe toC:\Windows\System32

    or

  • add thearduino-cli.exe path to system variable.

  • I crated a folder:C:\Program Files\arduino-cli, and added it into my path variable.

  • followthis link if need help in adding folder to system variable.path variable

Check the installation

  • Check if thearduino-cli is accessible from terminal by typing:arduino-cli.

  • You should get an output similar to this:cli-test

  • If everything is working, update the local cache of available platforms and libraries by running:arduino-cli core update-index

Create a new sketch

New sketch can be created in current folder by the command:arduino-cli sketch new MyFirstSketch

eg:

$ arduino-cli sketch new cli-blinkSketch created in: C:\projects\cli-blink

A folder with.ino file will be create for you.

You can open this file in you favorite IDE or text editor.

See the connected board

  • Connect the board to your PC and run the command to see the list of board attached to it.

arduino-cli board list

$ arduino-cli board listPort Type Board Name FQBN Core/dev/ttyACM1 Serial Port (USB) Arduino/Genuino MKR1000 arduino:samd:mkr1000 arduino:samd

Compile and upload the sketch

Once you open the code in your favorite Editor, Add you code to the.ino file

voidsetup() {pinMode(LED_BUILTIN, OUTPUT);}voidloop() {digitalWrite(LED_BUILTIN, HIGH);delay(1000);digitalWrite(LED_BUILTIN, LOW);delay(1000);}

Compile the sketch

Run the following command to compile the sketch

arduino-cli compile --fqbn YourBoardFQBN YourSketchName

  • Here theFQBN stands forFully Qualified board name, which is used to denote a particular board.

  • for examplearduino:avr:nano is thefqbn forArduino Nano,and arduino:avr:uno forUno boards

  • To compile sketch calledcli-blink forArduino Nano run the following command.

arduino-cli compile --fqbn arduino:avr:nano cli-blink

and you will get output like

$ arduino-cli compile --fqbn arduino:avr:nano cli-blinkSketch uses 924 bytes (3%) of program storage space. Maximum is 30720 bytes.Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytesforlocal variables. Maximum is 2048 bytes.
  • If you get any error like

    Error during build: platform not installed

    Then run the command:arduino-cli core install arduino:avr, which will install missing platform.

  • To list all the supported boards and its FQBN in you machine use command:

arduino-cli board listall

Upload the sketch

  • Use the command:arduino-cli upload -p YourBoardPort --fqbn YourBoardFQBN YourSketchName

  • To compile sketch calledcli-blink forArduino Nano connected in PortCOM3 run the following command:

arduino-cli upload -p COM3 --fqbn arduino:avr:nano cli-blink

Install 3rd party cores

  • You can usearduino-cli to compile and upload code to non AVR boards as well such asESP8266 andESP32.

  • For this, we need to add the additional package indexes in the Arduino CLI configuration file.

  • Create a configuration file if it doesn't exist by the command:arduino-cli config init

$ arduino-cli config initConfig file written to: C:\Users\B45i\AppData\Local\Arduino15\arduino-cli.yaml
  • Open the configuration file in any editor and add new board manger url toboard_manager > additional_urls.

  • To add ESP8266 with URL:https://arduino.esp8266.com/stable/package_esp8266com_index.json,Edit theyaml file like this:

board_manager:additional_urls:[https://arduino.esp8266.com/stable/package_esp8266com_index.json]
  • now update the core by command:arduino-cli core update-index
$ arduino-cli core update-indexUpdating index: package_index.json downloadedUpdating index: package_esp8266com_index.json downloaded
  • If you doarduino-cli core search esp8266 you can see esp8266 listed.

  • Compile code for nodeMCU:

arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 cli-blink

  • Upload to nodeMCU connected onCOM4:

arduino-cli upload -p COM4 --fqbn esp8266:esp8266:nodemcuv2 cli-blink

Install libraries

  • You can search for additional libraries by:arduino-cli lib search LibraryName
$ arduino-cli lib search wifimanagerName:"WiFiManager"  Author: tzapu  Maintainer: tzapu  Sentence: ESP8266 WiFi Connection manager with fallback web configuration portal  Paragraph: Libraryfor configuring ESP8266 modules WiFi credentials at runtime.  Website: https://github.com/tzapu/WiFiManager.git  Category: Communication  Architecture: esp8266  Types: Contributed  Versions: [0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.15.0-beta, 0.15.0]
  • Install the library by:

arduino-cli lib install WiFiManager

$ arduino-cli lib install WiFiManagerWiFiManager depends on WiFiManager@0.15.0Downloading WiFiManager@0.15.0...WiFiManager@0.15.0 downloadedInstalling WiFiManager@0.15.0...Installed WiFiManager@0.15.0

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp