Go Down

Topic: [Solved] Organising program code - Suggestions (Read 679 times) previous topic - next topic

Dyslexicbloke

Oct 25, 2012, 04:36 pm Last Edit: Oct 25, 2012, 05:54 pm by Dyslexicbloke Reason: 1
Hi folks,
I am going to say right up front that I may be talking absolute rubbish and asking about doing things that simply don't / cant work.

However I don't know and cant find any info on the subject so here go's.

I am about to start a reasonably large project.
I am used to keeping program code segregated into sections for clarity.
I am not asking about unnecessary nesting of functions, I get that with RAM at a premium that is a bad plan.
I am not asking for, nor do I want to implement, a load of library's simply to organise code, although I may put some of my utility functions into libs so that reusing is easy.

What I would like is to have multiple physical files, .ino I assume, on different tabs in Arduino 1.0.1 that compile as a single program.

I envisage putting the backbone, primary program flow if you like, into one, with other functions split into logical functional groups.
keeping setup() separate seems like a good plan, as does grouping together my display routines
The idea is to keep the development environment and the code organised, not to change the structure of the program its self.

Is this possible and if so are there any pitfalls?
Is there perhaps a better way ... I am very new to all this and happy to learn.

Thanks in advance
Al
If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

PaulS

Quote
Is this possible

Yes, it is.

Quote
are there any pitfalls?

The IDE combines all the .ino files into one .cpp file for compiling, so I don't see any.

Quote
Is there perhaps a better way

Not until you get into making libraries.

Dyslexicbloke

Thanks Paul,
I have actually built a library but was only simple, took me a silly amount of time and absolutely isn't what I am looking for here.
You are on the money there, I don't want to complicate for the sake of it

I tried adding a file spiting out some code and it seemed to break the compilation, that's why I posted the question, it looked as though it might work
is there something I need to do with 1.0.1 to make this work / enable it

Perhaps I just did it badly ... I will try again with a new file from scratch and then add to that.

If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

ckiick

Find the smallest example that doesn't work.
Post the code.
Show the error messages.
Chris J. Kiick
Robot builder and all around geek.

Dyslexicbloke

Its good, so clearly I wasn't .... Ah well
It is working for me now.

I am not sure the add file is working properly but it may be the way I am using it.

If you create a folder, mine is HMI_Main with HMI_Main.ino in it and then add additional .ino files, blanc or otherwise, they open automatically with HMI_Main.
Saving is the same, a save command saves everything.

Exactly what I wanted.
Thanks both, I would have given up on that without the assurance that I wasn't trying to do stuff that didn't make sense, again!!
If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

Dyslexicbloke

To use more than one file for a sketch It turns out that you need to do a little house keeping ....
There doesn't seem to be a way to change the order of the tabs once they are open.
They open in file name order, alphabetically.

If the compiler encounters a variable used in the first file before it has been declared in the second file you get a compilation error.
The point being that the files seem to be assembled physically with the leftmost tab ant the top.

My project is called HMI.
I have an HMI directory with HMI.ino as the main file, this contains the declarations section

also in the directory are :-
HMI_01_Functions                                       General functions, I will probably split this as the list gets bigger.
HMI_02_Setup                                            setup() code.
HMI_03_Main                                              loop() code.
HMI_04_Scratch                                          Space to play without messing up the formatting.

When the project is opened in Arduino 1.0.1 the tabs are in numerical order and code compiles and runs just fine.

I hope some of you will find this useful
If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

rockwallaby

Hi Al,

Reading how you wish to have your code segmented into structured files and organised in a way you want in the IDE is exactly how I have that same need.

Knowing how I program programs that I know will grow and contain various functionalities, such as the project you and I are both endevouring to do, I found the Arduino IDE was going to be a clunky way and most probably a very frustrating way for me to develop my project.

So, for me, spending some hours thinking about how best to do this, is exactly why I did move to using Eclipse IDE with the ARV pluging from Jantje.
I can have any project file open in any tab I wish.
I have something like 11 local files, which includes their header files, the main file with its header file, some imported library files together with Arduino library files.
So, you can see how, after a short while, the number of files grows, and with using Eclipse, I find it so much easier.
The workflow is a whole lot smoother, being able to pull up the files I am currently working on, while having others not open in a tab.
While editing, I do get to see quickly any sytax erros as I go, it prebuilds on the fly, not compile
I haven't worked with the Arduino IDE with multiple files but from what you have just mentioned, to me, it sounds horrendous to use if you can not organise your tabs in some way.

Yes, I needed a little while to throw myself into the understanding and becoming familar with this wonderful development IDE.
Like I have mentioned before, I use it to deveolp my html and javascript at the very same time, just different tabs across the top of my screen.

I guess what I am saying is that I find Eclipse with the AVR pluging totally awesome.

Below is a screen capture to help you visualise how I have it, click on the image once it is loaded to view it completely.
https://plus.google.com/photos/101798763285299013446/albums/5803380788356187681

Paul

Dyslexicbloke

#7
Oct 26, 2012, 02:22 pm Last Edit: Oct 26, 2012, 02:26 pm by Dyslexicbloke Reason: 1
I have to admit that looks good and easy to work with, the nav tree on the left with line and column numbers is probably justification for moving if there were no other benefits.

Now I have some code working and I am beginning to get a feel for things I think it is probably time I looked at a more capable IDE.
I wasn't comfortable previously because I wouldn't have known if errors / issues were down to my poor code or the IDE, I think I will be fine wit that now.

The bad new for you is when it inst working I know who to be asking :smiley-mr-green:

I have  few things to do today bur will probably have a proper go with Eclips  over the weekend.

I assume you started with Eclips for C/C++ and added the Arduino plugin to that right?
If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

rockwallaby

yep, it's pretty straight forward with the download of Eclipse and once you have that going, you simply install the plugin from within Eclipse.

With the plugin, the guy who developed it, Jantje, his web site he has much helpful info, including a video which runs through it all I believe, though I haven't watched it, I had it installed just by following instructions.

I'll help you get it sorted over the weekend if you want Al.

Have a great day then
Paul

dhenry

I have used quite a few IDEs both commercial and free. My favorite is IAR - for its simplicity and utilitarian approach.

I have used Eclipse, and found it to be quite good. However, for avrs, my favorite free IDE is Code::Blocks. It is very simple, small, and runs fast. Give it a try and you may like it.

AS5/6 are not bad but too big, especially with AS6.

You may also try Source Insight - excellent in my view but pricy. Programmer's Notepad is free and a better tradeoff between functionality and price.

As to code orgnization, I organize my code into .h and .c files and simply copy them to the projector folder, in the development phase.

rockwallaby

Hi Henry,
[Off Topic]
Yes, I too looked code::blocks initially which does look clean and sort of in line with the I do stuff in Linux (ubuntu), but I decided in the end to go with Eclipse after much perusing.
Eclipse appears to be very well supported, not saying that code::blocks isn't, just that I needed to decide and that was my decision at the end of the long day.

I am one to support open source, so no commercial software. I like to support developers of open source where and when I am able.

I don't know what IAR is, maybe you could start another thread on IDE's and provide some information and links for folks to look at.

Yes, I too organise my files as .h for the headers and use .cpp for the source.
I'm not a native C/C++ programmer, speak to me in assembler or PLC code, so Arduino has been a wonderful and fun learning arena for me thus far, and using Eclipse does just take it to the next level in my opinion.

[/Off Topic]
I guessing this thread should now be closed?

Paul

Dyslexicbloke

Closed - Yes, but a new one on IDE's is a great plan ... possibly even a sticky at some point!!
If I knew where the box was I would probably still want to think outside it!

Feel free to be blunt ... Its how I learn.

Go Up