Best way to make a project with multiple files
Solution 1
I recommend sticking with libraries and library directories with examples. A library for each component to be interfaced with. This will help in many ways. Such as debugging and reuse.
C:\Users\myself\Google Drive\Arduino\libraries\componentX\componentX.h
C:\Users\myself\Google Drive\Arduino\libraries\componentX\componentX.cpp
C:\Users\myself\Google Drive\Arduino\libraries\componentY\componentY.h
C:\Users\myself\Google Drive\Arduino\libraries\componentY\componentY.cpp
etc...
This keeps it modular and compartmentalized.
Notice I have changed the Arduino's IDE preferences to Google Drive. (Cloud backup and portability)
Then rather than one BIG INO file in your sketch folder
C:\Users\myself\Google Drive\Arduino\somethingBIG\somethingBIG.ino
implement INO files in the
C:\Users\mflaga\Google Drive\Arduino\libraries\component\examples.
directories. This makes it quick to publish the components on GITHUB or Google Drive to share between systems.
Then you can have a sketch file that ties all the components together into your main project.
C:\Users\myself\Google Drive\Arduino\somethingTOPlevel\somethingTOPlevel.ino
Solution 2
You might want to take a look at the Bare Arduino Project.
For my own project Moti, I felt the need to leave the Arduino IDE and use better tools to develop my project. Having to symlink or move every libraries soon felt deeply cumbersome and I looked for another solution. At the same time I was discovering the power of Makefile
and stumbled upon Sudar's incredible project: Arduino-Makefile.
I spent time organizing my folders and thought it could be useful for others.
You can think about the Bare Arduino Project as a framework for starting your own project.
I've taken the time to write a lot of documentation. You can learn more about the framework with the README.md and the Installation Instructions.
If you like it or feels like some stuff are missing, I'd love to hear your feedbacks and improvements.
Hope it helps! :)
Ted Tedson
My experience in a few sentences: Programming with Java, C#, C/C++, PIC Assembler; Technologies and frameworks: Android SDK, Vaadin UI framework, Swing, AWT, .NET4, MPLab, Proteus, XML, UML, TortoiseGit, TortoiseSVN, GitHub; I have еxtensive interests in hardware, PIC programming, embeded systems, artificial intelligence and robotics; Own projects: TRobot: The robot is made of Microchip PIC18F452 MCU, Toshiba TB6612FNG motor driver, Tamiya 70168 double gearbox, Tamiya wheels and chasis. The first version of the software is written in assembler, the second one in C. The robot is remotely controlled by Android device. The connection is made using Microchip RN-42 bluetooth module. The protocol used for the communication between the PIC and the RN-42 is UART. The robot is able to automatically avoid obstacles using IR sensors. You can see two different versions of the robot by following these links: https://www.youtube.com/watch?v=P4Ahi8QeN24 https://www.youtube.com/watch?v=NhODgyRuuog Android file uploader: The user chooses a file for upload. The program converts the file into base64 text representation and posts the data to a web server using the HTTP POST method. On the server side a perl script gets the string, decodes it and saves it to a file. Windows file uploader: It's written in C++ and uses the same back end perl script. The program converts binary files into base64 text representation and posts the data to a web server using the HTTP POST method. On the server side a perl script gets the string, decodes it and saves it as a binary file. Tank battle game written in C++: The player must destroy all the enemy tanks. There are some obstacles on his way. CPU benchmark written in C#: The benchmark starts several threads and measures the time needed for the threads to finish their job. Mail blocking program: ABV.bg mail access blocking program written in VB.
Updated on June 26, 2022Comments
-
Ted Tedson almost 2 years
I am developing Arduino based system that will enlarge over time. At the moment it has only the humidity and temperature read functionality. But soon a door control, sound recording and gsm web client support will be added. I want all these to be included as libraries and used in the main part. I'm thinking of one ino file that includes all other modules and calls their functions. My question is what is the best and most clean way to do it?
-
Ted Tedson almost 10 yearsSo i will have only one ino file and many cpp and h files, right? Should i have setup() and loop() functions inside the ino file? I suppose it will work like main.c.
-
mpflaga almost 10 yearsThere should always only be one INO file and it should have the only instances of setup() and loop(). H files and corresponding CPP files are basically always libraries that are pulled into the INO.
-
Ted Tedson almost 10 yearsThanks, now i can start the project. From the beginning i was thinking of organizing the project that way. Thanks.