I'd like to find out:
- how big can an Arduino project get, is there some limit?
- are there examples of large open source code bases? I did some research but find only example projects with single .ino file. Are there projects with multiple files e.g. functions, constants in separate files say to avoid a 10K+ .ino file?
-
2check the source code for some of the librariesjsotola– jsotola2020年04月02日 17:26:34 +00:00Commented Apr 2, 2020 at 17:26
-
here github.com/jandrassy/RegulatorJuraj– Juraj ♦2020年04月03日 05:49:59 +00:00Commented Apr 3, 2020 at 5:49
-
and a new one github.com/jandrassy/IsgModbusTcpSGJuraj– Juraj ♦2020年04月04日 05:51:31 +00:00Commented Apr 4, 2020 at 5:51
-
Yes, there are limits--as with any programming environment. 3d printer apps tend to be super-tight wrt space.Dave Newton– Dave Newton2021年12月02日 18:04:46 +00:00Commented Dec 2, 2021 at 18:04
4 Answers 4
Big projects are likely not developed with Arduino IDE. Arduino IDE was make for designers/inventors, not for programmers.
Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping, aimed at students without a background in electronics and programming.
Programmers will use a fully-fledged IDE which has many features a programmer needs on a daily basis, such as:
- handling multiple files efficiently
- allowing to create libraries instead of just
setup()
andloop()
- code completion (suggestions as you type)
- debugging (inspection and changing of variables at runtime)
- refactoring (modifying the structure of your code without changing the behavior)
- integrated version control (like Git / Github)
Such an IDE could be Eclipse with an Arduino Plugin or Atmel Studio and perhaps Visual Studio.
So, what do you need to look for? Don't look for .ino
files. Instead, look for .h
and .cpp
code, just like other non-Arduino C++ code.
Some examples:
- SPI: 297 lines
- Wire: 453 lines
- SoftwareSerial: 486 lines
- I2S: 533 lines
- USBHost: several files, up to 1600 lines
Again im late to the party...
If you are planning on making a larger project and splitting things up you can take advantage of libraries. This will work even if you are married to the arduino ide for some reason. if your not married to the arudino ide platformio doesn't suck too bad, and makes libraries a bit less messy when your doing the grunt work of setting them up the first time.
The idea should be to break your problem into smaller testable pieces of code into smaller testable libraries. If your code doesn't depend on arduino features you may be able to use test your library fully on a bigger machine to make sure there are no bugs (for example abuse clangs static analysis tool to see if you made any dumb pointer errors https://clang-analyzer.llvm.org/)
I kinda set an example of this (https://gitlab.com/mikealger/ExampleArduinoProjectStructure) up for students a while back but i still think its handy for anyone looking to build /manage the lifecycle of a project, I still use the basic ideas when i'm doing one off small projects based on others work to keep my notes straight i.e. https://gitlab.com/mikealger/celstronhomebrewgps
yea its probably shameless promotion but i haven't logged in for like 2 years...
Each sketch uses Flash memory, you can see this when you compile your project. You also can see how much percentually you have used.
And as jsotola explains, libraries are examples how multiple files can be used.
However, next to you .ino scene (in the same folder) you can put .h, .c and .cpp files which are automatically compiled (when used by the .ino file). However, if you use too many files, because tabs are placed horizontally in the Arduino IDE, it's better to use a decent editor. And while doing that, you use the Arduino IDE to compile (only).
Thats an example how to organize by function groups.
Other good complex examples can be found when searching for
Arduino esp8266 webserver site:github.com
The limit is basically your IDE -If you use ArduinoIDE the limit is (without already tested and working lib files) around 20 files, more is a pain in the a** to handle.
I keep the length of my files between 500 - max 1000 lines. For documentation and keeping relationship diagrams (valuable for debug) I use doxygen with the graph extension.
When using an IDE like eclipse you can use more files, you have a good overview over your classes, but time to spend (and learn) configuring a project is initially much higher and there are sometimes (release dependent) breaking changes in the tool chain.