Upload Sketch via Terminal

Hello,

I want to write a bash script that uploads code to an Arduino UNO R3, but I can't find a way to upload the Arduino code via Mac OS terminal. I wrote the Arduino sketch using the Arduino IDE and saved it to my desktop. I tried to send the .ino file to the UNO with the command 'cp uno_fan_control_off.ino ../../../dev/cu.usbmodem2101' (which is the port I was able to get from the Arduino Editor). When I run the command the orange led on the Arduino blinks once but the code doesn't run the same way it does when I upload it via Arduino IDE. Can anyone help me out with this?

Hi @ericwinter. Arduino provides a command line tool named "Arduino CLI" for this purpose. The installation and usage instructions are available here:

https://arduino.github.io/arduino-cli/

For example, to compile and upload the sketch, you can run this command from the terminal:

arduino-cli compile --fqbn arduino:avr:uno --port /dev/cu.usbmodem2101 --upload <sketch path>

(where <sketch path> is the path to the Arduino sketch you want to upload)

Thank you!

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per