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 SAThe 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.
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
CMD and PowerShell
Creating temporary directory
D:\Arduino\PROJECTS\0001 My First Project>CompileAndUpload.bat Button.inoFrom the file name, it will extract the sketch name and create a temporary directory with this sketch name.
Copying
Locating communication ports
Compiling
Uploading
Removing
Limitations and Known Issues
ANSI Color code not handled correctly
Only Tested on Arduino Uno and Nano
Serial Terminals block access to COM ports
COM port entry in command line history
Examples
File not found
Compile Errors
Successful Compile and Upload
Multiple COM port detection
Prerequisites
Windows 10
Arduino IDE
Arduino CLI
Fritzing IDE
Installation
Install Arduino GUI
Install Arduino CLI
Download the Batch File
CompileAndUpload.bat [ino filename]Provide the path to the .ino file. E.g.:
CompileAndUpload.bat Button.inoYou can use mapped drives, files and directories with spaces. E.g.:
CompileAndUpload.bat "\\NAS\Arduino\PROJECTS\0001 LED and Button\MultiFunctionButton.ino"
Background Story
.\Button\Button.ino
\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