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?
-
So make libraries. What is your question? – spring Jun 21 '14 at 16:23
2 Answers
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

- 2,807
- 2
- 15
- 19
-
So 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. – Ted Tedson Jun 22 '14 at 08:44
-
There 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. – mpflaga Jun 22 '14 at 19:57
-
Thanks, now i can start the project. From the beginning i was thinking of organizing the project that way. Thanks. – Ted Tedson Jun 23 '14 at 15:32
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! :)

- 3,037
- 19
- 27