Pages: [1] 2   Go Down
Author Topic: Where to find Information on how to organize larger Arduino projects?  (Read 1388 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Thanks in advance for any help
Jan
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10434
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can break your code up into several .h files and #include them from the main sketch, simple but
helps 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 library
is the natural way to do this - in particular you don't need to copy it to use in another sketch, and
it is the sensible way to share code with others to use/improve/extend.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

In other languages I would put things in classes to get it done.

How do you organize such a project with Arduino.

Thanks again
Jan
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In other languages I would put things in classes to get it done.

How do you organize such a project with Arduino.
Why are you assuming that you would do something different because it's an Arduino? You wouldn't.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have found what I searched for:
http://liudr.wordpress.com/2011/02/16/using-tabs-in-arduino-ide/

Are there more infos like this?

Jan
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Isn't that the same as what we wrote ?

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
At startup everithing has to be initialised in the rigth order and the correct timing.

Well then, make sure that, in the setup function, you initialize things in the right order.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all the answers. Some of them are helpfull.

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.

Now I have found what I have searched for.

Thanks
Jan
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31448
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Things in Arduino are a little bit different.
No not really, at the end of the day it is just C++ so do it like any C++ project.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Yes, that's a key point.
Logged

Pages: [1] 2   Go Up
Jump to: