Topic: Where to find Information on how to organize larger Arduino projects? (Read 2219 times)previous topic - next topic

Hello!I am new to the world of Arduino. And I like it. I have some AVR assembly done more then 10 years ago.

But I like Arduino, because I must not do all the work for all the common things like LCD and so on.I had running displays and stepper motors within minutes. My first LC-Display driver in assembler (10 years ago) took me several days until it worked.

Now I can concentrate on my programms and not all of the details, that i can do but are boring to do.

Now here comes my question:Is there somewhere a good source of how to organize larger Arduiono projects?I found a lot of tutorials for small programms but nothing about this problems. I know I could make libraries. But thiss is pure C++, and I would like to stay in the world of normal sketches.How can i organize things like: declaring hardware pins, initialize display, get all the hardware in a controlled start-state. And so on.If I divide my programm in several files. In which order are the compiled. What is with inkluding libraries that I need in different files?

If I divide my programm in several files. In which order are the compiled.

It doesn't matter. All the individual files are compiled, producing object files. Then, the linker is called to link them together. It's a multipass linker, so the order of the files presented to it is irrelevant.

Quote

What is with inkluding libraries that I need in different files?

I'm not sure that I understand the question. It's a useful technique is all I can say.

Start with a blinking led, and try other examples. You will find the answers along the way.

Arduino use C++, but also the AVR C-code can be mixed with it.

You can create new C++ files (use just a name) and also header files (name them as *.h) to your project.Use the drop-down on the right of the tab bar in the Arduino IDE.You can even copy *.c and other *.h files in the folder of your project.

To use a library, the library must be present, and the include file must be included.

You don't have to include your own include files.But sometimes you do. If the compiler uses a wrong order, you can also include your own include file in the first sketch.

You can break your code up into several .h files and #include them from the main sketch, simple buthelps keep different bits of code separate, and allows simple cut/paste reuse in other sketches.

But often you want to properly package some stuff (a driver for a particular chip), and the libraryis the natural way to do this - in particular you don't need to copy it to use in another sketch, andit is the sensible way to share code with others to use/improve/extend.

Thanks for the answers.But that was not really my question. I try again to make it clear.

I know how to blink an led.I know how to use (and write my own) library.What I talk about is a really large project (A controler for a special CNC-machine) with: - more then 10 steppers and servos. - other subsystems with serial connenction - a touchscreen with UI (menues and so on) - Lot of switches and sensors - On my Mega 2560 all IO-Pins are in use - ..........

So we talk about more than a few tousend lines of code.At startup everithing has to be initialised in the rigth order and the correct timing.

You have to think about how to split in different parts and add files to your project according to that, and give them proper names. About 20 or 30 files is no problem. But if you have 50 files, you could need a library.

I normally would make files like this: Menu, Menu_helper, Display, Keys, and so on.The 'helper' files are usefull functions. Sometime I have also files with _glue, with functions to 'glue' the different parts together.

This is just normal programming. So I still don't know why there is a problem.

You can make a "new tab" in the IDE. Those tabs can contain .cpp and .h files. You can break up your project as much as you like into separate files. You can use classes. Just make sure that the main sketch (the .ino file) has an #include for each .h file so that the compiling system knows to include them in the building process.

Please post technical questions on the forum, not by personal message. Thanks!

But to say "its normal programming, where is the problem? You will find the answers along the way. and so on ....." is not very helpfull.If I had no problem I would not ask.

I know how to programm in more than 10 languages. Not all active. Modula2 or Pascal is no longer state of the art.

But I am new to Arduino. I like it. Things in Arduino are a little bit different. So even if I know how to organize Files in C++ or Java, I asked if there is a good tutorial for Arduino how to organize projects.

If you already know OOP, it's easy: two tabs per class, one .h one .cpp. One .ino tab only, the main sketch, Just remember to include all the .h files in the .ino too, even if they're already included in some class .h file.

If you already know OOP, it's easy: two tabs per class, one .h one .cpp.

Sure, but the key is to know that you can create additional tabs. That is not all that apparent from the crappy icons on the IDE. Nor is it obvious, or well documented, what creating new tabs means.

Of course, one would think that by the time the project has grown to the size where multiple tabs are going to be helpful, one would have become confident enough to experiment with all the buttons and menu items, and become familiar with the results.