logoalt Hacker News

1718627440yesterday at 9:40 AM0 repliesview on HN

But targeting the Arduino IDE only means to have a GCC version to compile and some upload program and then set a bunch of variables in platform.txt . It doesn't actually make it any harder to not use the Arduino IDE.

> The problem with the IDE is that it doesn't offer a gradual path to more advanced usage. You're pretty much stuck with a single file main project. You can split off functionality into libraries, but the way library resolving works is way worse compared to "proper" build systems. There are projects to provide makefiles for Arduino projects, but it's a bit of a pain to set up - I use that for CI on some of my stuff, but it clearly is on the other end of difficulty scale.

It actually isn't all that hard. I recently did exactly that and it took like a week, most of which was spent on understanding what the Arduino IDE does with strace. Initially I assumed the Arduino IDE does way more stuff then it actually does. The makefile projects are too complicated, because they try to abstract over the installation and project. Instead I used Autotools which is way easier and simpler. It also breaks less, because these makefile projects tend to hardcode paths.

To save others the work: All you need to do is populate CPPFLAGS, CFLAGS, LDFLAGS, ... with the information from platform.txt and boards.txt . Then tell your build system to use the cross-compiler toolchain from your OS. Take care to only use the exact uploader program version that the Arduino IDE also uses, I have been burned by using the latest version, which bricked my board (i.e. you can't upload anything to fix it and need to use a second board to reflash the bootloader). This information is in the package_index.json file. Granted this is annoying to work with using fulltext search, you would have a much saner experience actually using the JSON format, but it still works and I am lazy.

> You're pretty much stuck with a single file main project.

You can have multiple files just fine, this is actually the reason why the Arduino IDE defaults to having this project directory. The Arduino IDE just assumes all files below that are things to compile. You need to remember to not name the other files with *.ino, but *.cpp, *.c and *.h, otherwise you end up with multiple main functions. An *.ino file is just a *.cpp file that gets preprocessed with a main function template.

> And of course the editor is horrible

You can tell the Arduino IDE to use another editor, which is what I did when I used it.