Unable to upload code to arduino from RPi from Terminal

Hello,

I have a very simple code as follows:

void setup() {
	Serial.begin(9600);
}

void loop(){
	Serial.println("test2--");
}

It is only for simplifying the problem scenario.

The thing is that I can perfectly upload that code to Arduino using the Arduino IDE running on the Raspberry with GUI.

The problem is that when I try to upload the code to Arduino nano using the terminal commands over ssh it is unable to upload the code.

I've noticed that the command for uploading the code to Arduino differs between the IDE and the Terminal.

The command run in the IDE is:

/opt/arduino-1.8.9/hardware/tools/avr/bin/avrdude -C/opt/arduino-1.8.9/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:/tmp/arduino_build_825460/testMenu.ino.hex:i 

and the output is as follows:

Problema subiendo a la placa. Visita http://www.arduino.cc/en/Guide/Troubleshooting#upload para sugerencias.
/opt/arduino-1.8.9/hardware/tools/avr/bin/avrdude -C/opt/arduino-1.8.9/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:/tmp/arduino_build_825460/testMenu.ino.hex:i 

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/opt/arduino-1.8.9/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/pi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "/tmp/arduino_build_825460/testMenu.ino.hex"
avrdude: writing flash (1486 bytes):

Writing | ################################################## | 100% 0.27s

avrdude: 1486 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_825460/testMenu.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_825460/testMenu.ino.hex:
avrdude: input file /tmp/arduino_build_825460/testMenu.ino.hex contains 1486 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.22s

avrdude: verifying ...
avrdude: 1486 bytes of flash verified

avrdude done.  Thank you.

However, in the Terminal the result is the following:

make do_upload
make[1]: se entra en el directorio '/home/pi/ASTB_stress_test_V3/testMenu'
/usr/share/arduino/hardware/tools/avr/../avrdude -q -V -p atmega328p -C /usr/share/arduino/hardware/tools/avr/../avrdude.conf -D -c arduino -b 57600 -P /dev/ttyUSB0 \
		-U flash:w:build-nano328/testMenu.hex:i
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe0

avrdude done.  Thank you.

make[1]: *** [/usr/share/arduino/Arduino.mk:1462: do_upload] Error 1
make[1]: se sale del directorio '/home/pi/ASTB_stress_test_V3/testMenu'
make: *** [/usr/share/arduino/Arduino.mk:1455: upload] Error 2

First I tought it could be due to a Serial interface chip drivers, but I can connect to the Serial port on the RPi and read the Serial.println message perfectly. Also, I can do it over the Arduino IDE. So it seems something with the command parameters and maybe the data speed when programming over the port.

Any ideas what is the difference between IDE and Terminal and how to make the code upload work over Terminal?

I've also tried with other arduino clones and it seems to work well the terminal upload on those boards.

I've done some tests with two different arduino nano boards programming them via Terminal and IDE with the following results.

The one that can be programmed via the Terminal uses the Processor ATmega328P(Old bootloader), as I have to choose it on the IDE. So it seems that over the Terminal it uses this config as default.

The other board on the IDE uses the Processor ATmega328P. And it cannot be programed over the Terminal.

So I guess it must be some configuration in the Makefile to specify the proper processor type for the ATmega328P. How can I do it?

I managed to solve the issue.

For some reason the new Arduino NANO boards need BOARD_TAG = uno when uploading code to them.

The information is in this thread:

Solution for this specific issue

Nothing specific to the terminal. It is simply a matter of the way someone wrote that Makefile. You would get the same no matter how you ran the command.

@in0 Yes I know it is not a Terminal issue. I mean that it is clear that the executed code, or the environment used, is different when using the IDE than when using the Terminal.

The library path is different, the #include statement needs to be adapted to ech situation. And then also In the IDE I can specify the NANO board as NANO, but in the Terminal I need to specify the BOARD_TAG to UNO, in some new nano boards.

So there is deffinitely some differences between both environments.

If you will provide a link to where you obtained the Makefile I will provide a detailed explanation of the different behavior.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.