Arduino Gets Command Line Interface Tools That Let You Skip The IDE

Arduino now has an officially supported command-line interface. The project, called arduino-cli, is the first time that the official toolchain has departed from the Java-based editor known as the Arduino IDE. You can see the official announcement video below.

Obviously this isn’t a new idea. Platform IO and other command-line driven tools exist. But official support means even if you don’t want to use the command line yourself, this should open up a path to integrate the Arduino build process to other IDEs more easily.

The code is open source, but they do mention in their official announcement that you can license it for commercial use. We assume that would mean if you wanted to build it into a product, not just provide an interface to it. This seems like something Arduino expects, because a lot of the command line tools can produce json which is a fair way to send information to another application for parsing.

The command line interface doesn’t just build a sketch. You can do things like install and manage libraries. For example, to create a new sketch:

arduino-cli sketch new HackadayPgm

You can update the installed platforms, list the connected boards, and search for board support:

arduino-cli core update-index

arduino-cli board list

arduino-cli core search mkr1000

If you don’t already have the board support, you can install it and verify that it is there:

arduino-cli core install arduino:samd

arduino-cli core list

That last step will give you the FQBN or unique name for the core. So to compile and upload you have this mouthful:

arduino-cli compile --fqbn arduino:samd:mkr1000 Arduino/HackadayPgm

arduino-cli upload -p /dev/ttyACM0 -fqbn arduino:samd:mkr1000 Arduino/HackadayPgm

Unlike, say, PlatformIO, this is clearly better for building into a tool, even if it is a makefile. We’d like to see a .build.json file or something that allows you to just issue short commands that do the right thing in a working directory. Of course, you could build that with a little shell scripting. Hmm….

It is nice to see the release of an official method and we hope this will lead to more editors being able to handle Arduino seamlessly.

49 thoughts on “Arduino Gets Command Line Interface Tools That Let You Skip The IDE

  1. I hope this would produce correct file paths. The arduino-builder script copies the sketch in the /tmp folder and compiles from there. If there is a compile error the path shown is the /tmp/… something, which confuses the IDE (Visual Studio Code).

    1. Could you be a littlebit more specific about the problem you ran into?
      Working with the EPS8266 under the arduino environment has been super easy if you ask me can’t see how loosing the GUI and having an CLI would solve your problems?

      1. Some people either prefers terminal editors or a very specific IDE.
        A official CLI IDE implementation means it’s possible to keep it all terminal, or wrap it in a plug in so you can work from your preferred IDE.

      2. I like to be able to assemble my projects by running make in the command line. As a rule, I believe that builds should be headless. Other than that, I don’t have problems with Arduino as platform. In fact, now that it has cli, it has become officially awesome.

  2. Awesome! This should make it much easier to remote update arduinos hanging off a raspberry pi or similar small linux computer (not that it’s terrible hard to use avrdude manually, but still)

    1. This CLI is more powerful than a Makefile. It handles the conversion from .ino to c++ and all the dependencies through the same steps as the Arduino IDE so it produces the best results.. including managing dependencies (using clang etc) , some of the makefiles out there do this in a simplified fashion and do not produce the same results

        1. I never really understood the philosophy behind this flavor of hating-on people. Surely however arrogant he was, you topped it in your very response! If you value your opinion so much, why don’t you also value his? You didn’t say anything more than him.

    1. Riight.

      It’s not my only language, but PHP (and some decent frameworks) helped put a second storey on our house, and Arduinos (and the Arduino port to ESP8266) are fun and very effective for many things. (and the Visual Micro plugin for Visual Studio gets you a better IDE for Arduino, when you’re ready for it)

      If that’s crappy, I’m up for more crappy. The new Arduino CLI is good news.

  3. I have been using the VisualMicro extension for Visual Studio for years. It works really well and includes intellisense and works with other extensions such as syntax highlighting, brace matching, and more. The free version does everything you would need, but I gladly registered it. Some of the best $30 I ever spent.

  4. now all i need is an extension for emacs to use it. (back in the olden days emacs had a reputation as a resource hog, but compared to more modern programs, it’s quite svelte)

    1. emacs was a resource hog before the IDEs added features. When they were just visual file browsers, and had less features than emacs, so then emacs was a resource hog. But by the time IDEs added things like telling you what variables you have available and putting them in a drop-down dialog, they were already using way way more resources.

      Emacs can do lots of things because the programming interface is generic, but a default install doesn’t do a lot of things. People talk about the “kitchen sink” merely because a directory full of user-supplied scripts is included with the distribution, without any notice paid to the fact that they’re not even loaded unless the user seeks them out. Nor is notice paid to the fact that the entire set of scripts is smaller than the “examples” folder that other software packages might include.

      That said, as an emacs user using avr-gcc I don’t bother to even use the gcc support. It is so trivially easy to switch to a different virtual desktop with a bunch of cli interfaces waiting, and just run the commands there. I would imagine emacs users who want to use the arduino libraries would do the same in most cases.

  5. …I thought the CLI for Arduino was just makefile, gcc, and a collection of avr/atmel flash tools. Maybe things have changed, but some time ago all it did was some horribly mangled way of copy-pasting all of your project code into one file (in a not-really-user-defined order), and then putting that single c file into GCC, in a very vanilla, obvious build order. And then it’d paste in #include “Arduino.h” for you on top of your big copy-pasted code file.

    In modern versions, you can include C files which will behave appropriately, but all the INO files still behave in this insane way. I don’t think there is any sane situation where you’d want to do or encourage this behavior, even (especially?) in beginners – makes you wonder if the Arduino had any idea what they were doing, especially back then. It’s things like this that have made me wish a platform a little better thought out than the Arduino were adopted by the hobby community.

    I guess with all the custom bootloaders and MCUs Arduino supports now, the CLI is possibly useful now, though I’d imagine all it’s doing is calling a bunch of manufacturer or open source tools which almost always already have CLI support.

    1. | the hobby community.

      Don’t we largely exist because of, not in spite of, what Wiring/Arduino has done? We tend to do what is effective within the scope of what we know and what we can learn without needing to be SMEs. If you give us better tools that we can adapt to without starting over, we typically do. The adoption of ESP boards over the Uno is a shining example.

      1. Nope. Hobbyists have always been and will always be. Arduino used the AVR microcontrollers because they were already popular with hobbyists and already had a toolchain they could copy and rename. :)

  6. Is this a ‘new’ cli, or just a modification of the existing one? I seem to remember being able to call ‘arduino’ (not ‘arduino-cli’) with options from the command line to get it to compile and upload (although there didn’t seem to be a way of stating the output name for the compiled binary). Was that something else?

  7. My stab into the guessing cloud: someone at Arduino realised that for rational and sensible QA a clean and stable “remote control” aka “scriptable CLI” or the like is a MUST. Now it’s here and public…
    Welcome to the pro-league! :-)

  8. anybody know if there is an option to specify the output filename of the compiled bin file? (I’d like to batch compile a series of .ino files to a series of compiled files).

  9. This is great news! An arduino cli build system is the sort of thing that the Arduino guys should’ve worked on a long time ago, instead of wasting their time and ours showcasing overpriced useless FPGA boards.

      1. Well, you wasted my time by replying to him.

        If you’re involved in a project, it is really much much much much much much much much better not respond to comments like this in stories about your project. If you value people talking about your project, and you darn well should if you’re promoting it, then you should let them talk and not complain about it.

        You’re the most biased possible commentator when you’re responding to comments voiced in the 3rd person with ones voiced in the 1st person. If you think somebody said something negative, and you can’t respond without being defensive or taking a swipe at them, or getting political, then just don’t respond. Even if a comment is 100% negative, your response should be 100% positive, or else you shouldn’t even engage it. Because they have every right to a negative opinion, and you do your project no favors by arguing with them. People might think your decisions were less good for them than other decisions you might have made, and that is normal. They’re not wrong to care about their own needs, and that should be obvious if you’re saying that you thought your choices did meet your own needs. No reason for negativity there, even in the presence of a complaint.

  10. This is great news. I just got I to the Arduino project and after seeing how basict the official IDE is I tried out platform.io which is good but I’m also a programmer and it took over my editor.

    Personally I think the folks are Arduino should fort something like Atom or Brackets and take advantage of those communities. Especially since some boards are using python or node.js

    1. There are Makefiles available.

      I always use a Rakefile too, I just use it to wrap the make commands and provide a generated menu.
      That way, the Rakefile doesn’t have to care about what tools you’re using, it is just running the cli commands for you.

      desc "run make"
      task :make do |t|
        sh "make"
      end
      

      1. Hi all ! Using arduino-cli what is the command to install a nodemcu board? I’m pretty new on arduino and have just used its IDE for basic programming, so I really need a help on this. Thanks in advance.

Leave a Reply to georgealanminorCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.