fotografeer.nl

fotografeer.nl

  • Overzicht
  • Fotografeer tips
  • Blog
  • Albums
  • Categorieën
  • Sets
  • Aanvraag
Home / Categories / Blog / Essays / Compile and Upload .ino file to Aruduino board via arduino-cli
Share
2022/12/09

Compile and Upload .ino file to Aruduino board via arduino-cli

This blog post describes how you can use a Windows 10 batch file to compile and upload Arduino .ino files to an Arduino board. And it provides background on why it was created in the first place.

Update 2022-12-19: Many of the concerns mentioned in this blog are no longer valid for version 2.0.3 of the Arduino GUI. Just downloaded and installed this version:

Version: 2.0.3
Date: 2022-12-05T09:30:25.331Z
CLI Version: 0.29.0 [76251df9]
Copyright © 2022 Arduino SA
The editor now features line numbers and you can now set font size and dark theme. The need to match directory name and sketch name seems to no longer exist. Need to investigate if the need for this batch file still exists.

The .ino files are compiled and uploaded to Arduino boards, like the Uno. There it can read input from sensors and push buttons and control output devices, like the LED show here.

Example of an electronic prototype with an Uno and breadboard. Image created with Fritzing.

Disclaimer

THIS HOWTO AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THIS HOWTO OR SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS HOWTO OR SOFTWARE.

Features

This section describes the features that the batch file brings.

CMD and PowerShell

Works in both CMD and PowerShell. See the examples section below.

Creating temporary directory

The file location for the .ino file is provided as input on the command line.
D:\Arduino\PROJECTS\0001 My First Project>CompileAndUpload.bat Button.ino
From the file name, it will extract the sketch name and create a temporary directory with this sketch name.

Copying

The original .ino file is copied to the temporary directory.

Locating communication ports

The communication port that the Arduino board is connected to is automatically detected.
With multiple boards, you can choose where to upload.

Compiling

The .ino file in the temporary directory is compiled.

Uploading

If compiling succeeds, the created byte code is uploaded to the Arduino board.

Removing

The temporary directory and all its content is removed.

Limitations and Known Issues

ANSI Color code not handled correctly

After compiling with the arduino-cli, the ANSI color codes are not displayed correctly. Instead of enabling and disabling the color for the terminal text, it shows ←[96m and ←[0m. Example:
This seems to be caused by the arduino-cli, because if I comment that out, the colors are shown correctly. Have not found a real cause or workaround for it.

Only Tested on Arduino Uno and Nano

So far, this batch file has only been tested with Arduino Uno and Nano boards. The Nano upload phase has the 'cpu=atmega328old' option set. Nothing is known on how it behaves with other boards.

Serial Terminals block access to COM ports

If you opened a serial terminal in the Arduino IDE or Fritzing IDE, upload will fail. The serial terminals deny the batch file access to the COM ports. (Toegang geweigerd = Access denied)

COM port entry in command line history

If you used multiple ports and manual enter a choice, the COM port name will be in the command line history and will show up if you use arrow up to go to previous commands.

Examples

File not found

Compile Errors

Successful Compile and Upload

Multiple COM port detection

Prerequisites

Windows 10
Arduino IDE
Arduino CLI
Fritzing IDE

Windows 10

The target system for the batch file is Windows 10 on which it has been tested.

Arduino IDE

An IDE helps you to develop software source code in an organized way in a user-friendly GUI. You need to download and install the Arduino IDE, before you can use the Arduino CLI.

Arduino CLI

The Arduino CLI allows users to type commands to compile and upload the software.

Fritzing IDE

Optionally, you can download and install the Fritzing IDE.

Installation

Before you can use the batch file, you need to prepare the following.

Install Arduino GUI

The newer version 2 of the GUI can be downloaded and installed from the Arduino Software page. Look for the DOWNLOAD OPTION section on the right and select "Win 10 and newer, 64 bits". Follow the download instructions and install the GUI.

Install Arduino CLI

The Arduino CLI 64 bits MSI installation file can be downloaded and executed to install the CLI through a setup wizard.
Follow the instructions to install the CLI.

Download the Batch File

Here is the code for the Windows batch file. Copy/Paste the text into a file called CompileAndUpload.bat on your local computer. Put it in a suitable location. E.g:
Add the location to your enviroment path.
To run it, open a cmd or PowerShell window. After the prompt, type:
CompileAndUpload.bat [ino filename]
Provide the path to the .ino file. E.g.:
CompileAndUpload.bat Button.ino
You can use mapped drives, files and directories with spaces. E.g.:
CompileAndUpload.bat "\\NAS\Arduino\PROJECTS\0001 LED and Button\MultiFunctionButton.ino"

Background Story

A while ago a good friend, who is a model-train enthusiast, asked me to create some software to control LEDs for emulating a running light, a welding light and randomly switching on/off lights in the model houses. The software needed to run on an Arduino Uno board to which these LEDs are connected. This introduced me to Arduino ecosystem.

To start developing the code for the requested functionality, I downloaded the Arduino IDE. It works great and has a Verify and Upload button. And easy to learn how to use. The only quirky thing is that a .ino file must always be in a sketch directory with the same name. E.g.
.\Button\Button.ino
I'd like to use multiple .ino files, without having any restrictions on the directory name. E.g.
\Arduino\PROJECTS\0001 LED and Button\Button.ino
\Arduino\PROJECTS\0001 LED and Button\MultiFunctionButton.ino
\Arduino\PROJECTS\0001 LED and Button\Other Code Here.ino
An alternative might be the Fritzing IDE. This supports multiple .ino files per project. It has an upload button, but there doesn't seem to be a Verify button to only compile the .ino files, like the Arduino GUI has. Therefore Fritzing doesn't seem to have a way to show the compile error messages if you make a mistake in your source code. If you have invalid code, the upload will fail without any error message to indicate what is going wrong.
The only way to work around these issues was to create a batch file that can compile, show the compile error messages and upload when compile succeeds, as described above.

Read more in Blog

arduino

Programming ATtiny85 from Arduino Nano - T… WordPress in Docker on ReadyNAS OS VM
View all essays by month
View all essays by category
  1. 14

    Blog

  2. 13

    Fotografeer tips

  3. 6

    Portret

  4. 6

    Elfia

View all essays by tag
  1. 9

    arduino

Links
  • Fotografeer tips
  • Tips - Introductie
  • Tips - Beelduitsnede
  • Tips - Scherpstellen
  • Tips - Compositie
  • Tips - Perspectief
  • Tips - Objectief categoriën
  • Tips - Objectief eigenschappen
  • Tips - Objectief beeldhoeken
  • Blog
  • Twitter
  • Facebook
Tweet
  • Overzicht
  • Fotografeer tips
  • Blog
  • Essays
  • Albums
  • Inhoud
  • Twitter
  • Facebook
© 1979-2025 Peter van Loon - fotografeer.nl - since 2003 | Built with Koken