Command line Arduino compiling and uploading?

后端 未结 11 828
长发绾君心
长发绾君心 2020-12-13 17:37

How do I compile and upload Arduino sketches from the command line on Mac and Linux? I\'ve installed the Arduino programming environment. Are there some sample makefiles an

相关标签:
11条回答
  • 2020-12-13 17:57

    I have a makefile for Arduino which can be used to compile and upload Arduino (or plain AVR C) programs to Arduino.

    Following are some of the important features of this makefile

    • Supports upload via Arduino as ISP or any programmer
    • Supports compiling plain AVR C programs
    • Supports user as well as system libraries.
    • Generate assembly and symbol files
    • Program using alternate Arduino core (like ATtiny or Arduino alternate cores)
    0 讨论(0)
  • 2020-12-13 17:58

    If you do not insist on make there is also scons/sconstruct scons/sconstruct. Since this in basically written in Python it is much simpler to tweak than make. In addition it can be debugged with any Python debugger.

    0 讨论(0)
  • 2020-12-13 18:03

    There is a command-line Arduino toolkit named Ino. It just does that.

    0 讨论(0)
  • 2020-12-13 18:05

    You can actually use the arduino GUI to compile and upload, and set the editor to external in the preferences. That way, you can edit the C++ (PDE) files from xcode, and have arduino generate the actual CPP and build the whole shebang.

    You can also use XCode to write plain C++/C for the arduino, using the avr-gcc compiler.

    Have a look at: https://stackoverflow.com/a/8192762/153835

    You can then use the plain avrdude upload tool to program the arduino. Have a look at: http://www.ladyada.net/library/arduino/bootloader.html

    It used to be that the protocol spoken by Arduino was a modification of the STK500 protocol, and that only the avrdude bundled with arduino could speak it. I don't know if the mainstream avrdude was upgraded, or if you still have to resort to the avrdude inside the Arduino folder.

    0 讨论(0)
  • 2020-12-13 18:05

    I use platformio, quite like it. It also has extensions into Visual Studio Code, so you can do everything from there. It has library manager and uploader built-in.

    My setup is a NFS drive where I have the code, mounted on my linux laptop, and also mounted on my Raspberry Pi that sits next to my Arduino's.

    When it's time to compile, I do so on my laptop, and as the RPi is next to the Arduino, I upload from there..

    After installing and configuring, the basics are simple; 'platformio run' will compile your code. 'platformio run -t upload' will compile & upload.

    I also have a bash function to upload without compiling;

    function th(){
        if [ "${1}" = "upload" ];then
        if [ ! -f platformio.ini ]; then
            echo platformio.ini not found
        else 
            UPLOAD_PORT=`cat platformio.ini | grep upload_port | awk '{print $3}'`
            if [ "${UPLOAD_PORT}" = "" ]; then
                echo no upload port
            else
                if [ "${2}" != "" ]; then
                    FIRMWARE=${2}
                else
    #the firmware location seems to have moved
    #               FIRMWARE='.pioenvs/megaatmega2560/firmware.hex'
                    FIRMWARE='.pio/build/megaatmega2560/firmware.hex'
                fi
                if [ -f "${FIRMWARE}" ]; then
                    avrdude -v -p atmega2560 -C /home/stevenk/.platformio/packages/tool-avrdude/avrdude.conf -c wiring -b 115200 -D -P "${UPLOAD_PORT}" -U flash:w:$FIRMWARE:i
                else
                    echo ${FIRMWARE} not found
                fi
            fi
        fi
        else 
                wget --timeout 8 -qO- http://192.168.178.212/$1
        fi
    }
    
    0 讨论(0)
  • 2020-12-13 18:12

    If you can use cmake then there are some links in the same web (this and this for example). GNU makefile is a little bit different from cmake but nothing complicated. Just Google a little bit and you can find a lot of Makefile examples how to compile AVR code.

    0 讨论(0)
提交回复
热议问题