Code to long -> error after adding tabs

Hi,

I'am working on an IOT project with Blynk.
The code quickly became to long! So I added tabs, and now the code gives an error.
It is the same code, but the functions changed form place.

I really have no choice but to use tabs, 500 lines is just to long in my eyes.

The code is on GitHub, click here. (The original working should also be somewhere on there!)
The error message is in attachments, as wel as on GitHub, in the issue section (here), (its to long for on the forum).

I have no idea why it would do this...
I hope someone has a solution!

Isaak

Error message.txt (11.9 KB)

- char auth[] = "NEO79_k3Zzy1PqnLkNUOMZiIXJmIo3kz";
+ char auth[] = "token";

It looks like maybe you forgot my advice to add secrets.ino to your .gitignore file. If that's private information then you'll want to revoke the token ASAP.

It turns out that the Arduino-recommended method of multiple .ino files is not the best way to manage and modularize a large, multi-file project. The IDE's method of smashing all the .ino files together and compiling them as one can trip you up with global variable scope and problems with auto-prototype generation. You also don't get file-level scope control and true modularity.

I'd recommend managing the project the same way programmers have been managing large C+/C++ projects for about 50 years …. with separate source (.cpp) and header (.h) files. Function implementations go in the former while the interfaces that tell functions in other files how to use them go in the latter.

gfvalvo:
I'd recommend managing the project the same way programmers have been managing large C+/C++ projects for about 50 years …. with separate source (.cpp) and header (.h) files. Function implementations go in the former while the interfaces that tell functions in other files how to use them go in the latter.

I disagree. The multiple .ino files approach is fine for this application. There is a much more gentle learning curve associated with this approach than going straigh to .h and .cpp files. Once you understand how the .ino files are combined, it's a very gentle transition.

The same can't be said for a novice switching from a single file sketch to .h and .cpp files. Sure, that's how it's been done for 50, but Arduino is all about doing things in a way that makes this technology accessible to everyone. If you only want to keep on with the same old paradigms, then what's the point of even bothering with Arduino?

gfvalvo:
problems with auto-prototype generation

Pure FUD. The prototype generation system is applied after the files are concatenated. Any prototype generation issue would have occured just the same with a single file sketch.

idv7:
The code quickly became to long! So I added tabs, and now the code gives an error.

What you need to understand about having multiple .ino files in a sketch is that they are simply concatenated together into a single file before compiling. The order of concatenation is the same as the order the IDE shows the tabs in. This means all the same requirements apply as though you still had all the code in a single file.

I think if you take a close look at your code with this in mind you'll be able to spot the cause of the errors.

For example, you are using the timer2 object in the first file AMS_V2_1_Main.ino but you declare that object later in AMS_V2_6_Other.ino.

Git can be tremendously useful for this sort of thing, but only if you are disciplined in your commits:

Every commit should be atomic. That means it does only one specific thing, and does that thing completely. Information on that here:

Commit messages should be meaningful. You'll be very grateful for this information later when you're trying to figure out why you made a specific decision in the development. Information on that here:

I recommend against versioning with file names. Git has a tag capability that allows you to mark specific points in history. You can always recover the project at the state it was at that tag. GitHub has an enhancement on tags called releases:

These can easily be created via the GitHub web interface. It's likely that GitHub Desktop has some such capability as well (I haven't used it in years so I don't know).

pert:
If you only want to keep on with the same old paradigms, then what's the point of even bothering with Arduino?

Well, I stick with the 50 year old paradigm because it provides the advantages I mentioned previously … modularity, exact interface definition, scope control … plus testability and maintainability. If that wasn't the case, coders would not still be developing large projects in this manner. Compiling a single, giant file (after smashing the tabs together) doesn't provide these things.

As for "bothering with Arduino", the answer is that the Arduino ecosystem provides access to sophisticated hardware (processors, sensors, etc, etc), that I don't have to build myself, at low cost. I can buy assembled and tested modules from Arduino, Adafruit, PJRC, etc cheaper than I could make them thanks to the volume Arduino generates. I don't need to deal with surface mounting 0204-sized passives, BGAs, QFPs, etc. I can just fab simple PCBs that just interconnect these modules.

You could take a look at my tutorial on How to Write Your Own Arduino Libraries which goes through step by step breaking your large .ino file down into smaller files and then your own library.

Tasmota, which I have compiled on my Arduino IDE, has over 230 tabs.

If all of your tabs are a function, or a small group of functions, then it should compile just fine. You can't put declarations in the tabbed functions, you're just asking for problems.

I put all of my declarations and globals in the main tab, the leftmost tab on the IDE, and tht usually keeps me sane.

Thank for the many answers!
I will try to use the .ccp and .h methode. If it might be to difficult i wil with to the ino methode.

drmpf, wow thats a good tutorial! will use it.

Isaak

So I followed drmpf's tutorial, but there are still many errors... I probably did many thing wrong.
I hope someone finds the error...

Github sketch
Github issue with error message (its really long)

Thx a lot!
Isaak

Edit: My friend tried the links and they didn't work... I tested it in incognito and it worked fine, let me know if you have issues opening it!

Looks like I need to update the tutorial to make this clearer
You need to add the #include "...h" to the top of the associated .cpp file AS WELL AS to the .ino file.

Did that, almost same error...
GitHub error code

Isaak

As suggested above adding

#include "AMS_V3_4_Input.h" to the top of AMS_V3_4_Input.cpp fixed those compile errors

// file AMS_V3_4_Input.cpp
#include "AMS_V3_4_Input.h"
//BUTTONS
void buttons_setup() {
  pinMode(buttenPinEncoder, INPUT_PULLUP);
  pinMode(buttenPinBlackbutton, INPUT_PULLUP);
}
. . .

You have a lot of files.
Remove them all and add them back in one pair of .cpp / .h at a time and get each one of those working from the main sketch.
Standard error debugging. Keep taking code out until it works and then put the last line back in and see what that breaks.

Sorry but that isn't possible, many functions are used in different cpp files...
So I might be calling a function form a cpp file that i just took out.

Then you comment out all such calls. The goal is to get it to compile, not "work".

Once a subset of the project compiles, you add in the next .cpp / .h pair, uncomment calls to its functions, and fix any compiler errors.

Lather, rinse, repeat.

But almost all the code is used in other functions so there isn't really a point in doing that.

Edit: I might just try the .ino methode that Pert recommended, since it won't generate all these errors (hopefully).
If anyone is willing to try getting some of those errors out of my sketch I would really appreciate that.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.