How to Upload an Arduino Sketch from Linux Terminal

Video is ready, Click Here to View ×

In this tutorial I show you how to upload an Arduino sketch without the use of the Arduino IDE. If you’re interested in using a different program to write your Arduino code, you need a way to upload it. The command line / terminal of a Linux or Mac computer allows you to do this easily. Or if your computer connected to the Arduino is remote (say a Raspberry Pi) you may not want to run a full fledged VNC server and instead want the ease of terminal access. Either way, this tutorial shows you…


  1. Alex do you have any tutorial for modbus implementation between arduino and pi? I was able to implement pi as master and arduino as slave but facing problem with the vice versa. Can you assist in any way possible?

  2. I got error message:mkdir -p build-mega
    make reset
    make[1]: Entering directory '/home/tsuu/sketchbook'
    /usr/bin/ard-reset-arduino /dev/ttyACM0
    Traceback (most recent call last):
    File "/usr/bin/ard-reset-arduino", line 4, in <module>
    import serial
    ImportError: No module named 'serial'
    /usr/share/arduino/ recipe for target 'reset' failed
    make[1]: * [reset] Error 1
    make[1]: Leaving directory '/home/tsuu/sketchbook'
    /usr/share/arduino/ recipe for target 'upload' failed
    make: * [upload] Error 2

  3. ARDUINO_DIR = /usr/share/arduino
    ARDUINO_PORT = /dev/ttyACM*
    USER_LIB_PATH = /home/pi/sketchbook/libraries
    include /usr/share/arduino/

    my Makefile , I have change BOARD_TAG to due, arduino_due.

    this is my testing sketch which has no error in PC arduino IDE and functional after upload.
    but I have the following error undex rasp pi , the sketchbook is pi pi ( owner and group).

    error while compiled under rasp pi – [USER] ARDUINO_DIR = /usr/share/arduino
    – [DEFAULT] ARDUINO_SKETCHBOOK = /home/pi/sketchbook
    – [BUNDLED] AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr (in Arduino dist ribution)
    – [COMPUTED] ARDUINO_LIB_PATH = /usr/share/arduino/libraries (from ARDUINO_DIR)
    – [DEFAULT] ARDUINO_CORE_PATH = /usr/share/arduino/hardware/arduino/cores/arduino
    – [COMPUTED] ARDUINO_VAR_PATH = /usr/share/arduino/hardware/arduino/variants (from ARDUINO_DIR)
    – [COMPUTED] BOARDS_TXT = /usr/share/arduino/hardware/arduino/boards.txt (from ARDU INO_DIR)
    – [USER] USER_LIB_PATH = /home/pi/sketchbook/libraries
    – [USER] BOARD_TAG = Arduino_due
    – [COMPUTED] OBJDIR = build-Arduino_due (from BOARD_TAG)
    – [DETECTED] MONITOR_BAUDRATE = 9600 (in sketch)
    – [DEFAULT] MCU_FLAG_NAME = mmcu
    – [DEFAULT] CFLAGS_STD = -std=gnu99
    – [AUTODETECTED] Size utility: AVR-aware for enhanced output
    – [COMPUTED] BOOTLOADER_PARENT = /usr/share/arduino/hardware/arduino/bootloaders (f rom ARDUINO_DIR)
    mkdir -p build-Arduino_due
    /usr/share/arduino/hardware/tools/avr/bin/avr-g++ -x c++ -include Arduino.h -MMD -c -mmcu= -D F_CPU= -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -I. -I/usr/share/arduino/hardware/arduino/cores/ arduino -I/usr/share/arduino/hardware/arduino/variants/ -Wall -ffunction-sections -fdata-se ctions -Os -fno-exceptions DUE_potentiometer.ino -o build-Arduino_due/DUE_potentiometer.o
    avr-g++: error: missing argument to ‘-mmcu=’
    /usr/share/arduino/ recipe for target 'build-Arduino_due/DUE_potentiometer.o' failed
    make: * [build-Arduino_due/DUE_potentiometer.o] Error 1


    /* Learn how to use a potentiometer to fade an LED with Arduino – Tutorial
    More info and circuit schematic:
    Dev: Michalis Vasilakis / Date: 25/10/2014 */

    //29 May 2017
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x3F,20,4);
    //GND -black
    //grey-middle arm of 50 K potentiometer
    //Orange- 3.3V
    const int ledPin = 9; //pin 9 has PWM funtion
    const int potPin = A1; //pin A0 to read analog input
    char abc[]="abcdefghijklmnopqrstuvwxyz";
    int value; //save analog value

    void setup(){
    //Input or output?
    pinMode(ledPin, OUTPUT);
    pinMode(potPin, INPUT); //Optional
    lcd.begin(20, 4);
    lcd.init(); //in I2C this statement must be used before the lcd can display characters 17 May 2017
    // lcd.Display();
    display_1("Potentiometer p54",0);

    void loop(){

    value = analogRead(potPin); //Read and save analog value from potentiometer
    value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
    if ( value != 0){

    lcd.print(" ");
    analogWrite(ledPin, value); //Send PWM value to led
    delay(500); //Small delay

    void display_1(const char* stmt2,int display_row) //original name :char_pressed is test1
    // digitalWrite(LCD_LIGHT_PIN, HIGH);
    // Print some text to the LCD.
    // lcd.clear();
    if (display_row == 0) {
    lcd.setCursor(0, 0);
    //char stmt3 = stmt2.substring(1,2);
    if (display_row == 1) {
    lcd.setCursor(0, 1);
    //char stmt3 = stmt2.substring(1,2);

    // lcd.setCursor(col, row)
    if (display_row == 2 ){
    lcd.setCursor(0, 2);
    if (display_row == 3){
    lcd.setCursor(0, 3);

    wait(1); // (2+1) x 50 milliseconds

    // lcd.noDisplay();
    // digitalWrite(LCD_LIGHT_PIN, LOW);
    void wait(int n)
    for (int i= 0;i < n; i++) {
    } //end of wait routine

  4. but you can use raspi pi itself to do all of the procedures with a suitable size lcd n a keyboard. The method from above is also good for remote reprogramming a arduino in a long distance.

  5. Whouah ! Awesome ! I see that you use avr dude indirectly (with the "make" script). I suppose that the next episode will be "programming Uno with cpp11" (which is possible – few people know that). Thank's for all.

  6. A big thumbs up for this video. You have saved me a ton of trouble while I learned many new things. Your video was to the point and with perfect narration. Informative and enjoyable at the same time. Keep up the good work. Thanks.

Leave a Reply

Your email address will not be published.