Command line Arduino compiling and uploading?

后端 未结 11 831
长发绾君心
长发绾君心 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 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
    }
    

提交回复
热议问题