0

What's the order of files being compiled/used?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

What's the order of files being compiled/used?

by jeffrey on Mon Dec 31, 2018 12:43 pm

I am used to top/down programming in Microsoft Access, and I have dabbled with the Arduino. My Arduino programs have been pretty simple, but now I am branching out and it didn't take long for me to get confused.

1. The IDE lets you include files in the editor with your sketch. Do I have to use the #include statement with them being one of the tabs in the IDE?

2. I am using the Fona library where I have to make changes to take into account the pins for the shield since the library assumes you are not using the shield. However, I may want to use the breakout for another project. If I make changes to the .h file in the libraries directory, that would affect all projects that use that file. Can I copy that file to the subdirectory where my sketch is, include it in the IDE as a tab, and make the required changes there? If so, do I have to add/change anything in the .h file to make it see the #includes in the file? And will it "bump heads" with the .h file in the libraries subdirectory?

jeffrey
 
Posts: 31
Joined: Sat May 12, 2012 8:04 pm

Re: What's the order of files being compiled/used?

by adafruit_support_bill on Mon Dec 31, 2018 1:46 pm

There is an article on the subject here: http://arduino.land/FAQ/content/7/43/en ... files.html

Editing the source of the library files is best avoided if possible. It is possible to override #defines in the library by simply re-defining them after the #include.

adafruit_support_bill
 
Posts: 70973
Joined: Sat Feb 07, 2009 10:11 am

Re: What's the order of files being compiled/used?

by jim_lee on Mon Dec 31, 2018 4:05 pm

Arduino IDE has some odd behaviors. There are three places it stashes source code. First is your sketch folder. This has your .ino file and your .h & .cpp files that pertain only to your .ino file. Then there is the "library" folder in with your sketch folders. This is where you can store your "general purpose" source code. This is a common place for add-on drivers and things like the FONA stuff. Then there is a third place, hidden on Macs, in with the Arduino application. This also has library files. Mostly these are from venders like Adafruit. Sometimes you will end up with multiple versions of the same library. For example : I have one version for the .mp3 player in the Arduino hidden folder from Adafruit, and a second version, also in this hidden folder, from the people that make the Teensy processor that I like to use. Then there is a third version I have in my library folder with my sketches that is my personal version.

I think that by trying to hide stuff to make things "look" simpler, its just made things into a more complex mess.

Then things get odder.. The IDE will open .ino files, but .h & .cpp files can only be opened if they're in your sketch folder. I will not open .h & .cpp files anywhere else. And, if you have too many source files in with your sketch, you get more tabs than can fit on your screen and there is no way to scroll them.

So, you want to customize your library files to fit your situation. This is typically a bad idea. There could actually be multiple copies, did you hack the correct one? Also, there is a really good chance that what you need is already there, it just needs a little more education to figure out how it was designed to work. , Adafruit is typically pretty good about making sure their library files work with all their products. I would be very suspect if it looked like one of their libraries didn't work with one of their products without hacking the library code.

But yes, I do have a custom version of their mp3 player code with my "modifications" in it. So I break my own rules now and again.

To edit .h & .cpp files outside of your sketch folder (libraries) you are going to need to get an app that can edit them. There's a lot of editors out there, its just about getting one you like to use.

Good luck, hope this helps.

-jim lee

jim_lee
 
Posts: 436
Joined: Thu May 24, 2012 8:24 pm

Re: What's the order of files being compiled/used?

by adafruit_support_bill on Mon Dec 31, 2018 4:59 pm

Then things get odder.. The IDE will open .ino files, but .h & .cpp files can only be opened if they're in your sketch folder. I will not open .h & .cpp files anywhere else. And, if you have too many source files in with your sketch, you get more tabs than can fit on your screen and there is no way to scroll them.

And, if that is not odd enough, the .cpp files in those tabs will be processed in alphabetical order. They will be concatenated into one fie before being submitted to the compiler.

adafruit_support_bill
 
Posts: 70973
Joined: Sat Feb 07, 2009 10:11 am

Re: What's the order of files being compiled/used?

by jeffrey on Tue Jan 01, 2019 2:24 pm

Thanks for the assist! Not being a programmer by trade and only getting to tinker with this stuff in spurts, I invariably find myself in a hole.

As for Adafruit's libraries, they have to take into account the different variations of their products. The Fona, for example, can be wired to any set of pins, meaning you either wire it to match their library or you change their library. Oddly enough, they didn't set the library up to work with their shield, which is hardwired by design. The library was written for the Fona breakout, and I guess it came before the shield. Their assumption that I will find what needs to be changed can be woefully short sighted!

jeffrey
 
Posts: 31
Joined: Sat May 12, 2012 8:04 pm

Re: What's the order of files being compiled/used?

by adafruit_support_bill on Tue Jan 01, 2019 3:49 pm

The Fona, for example, can be wired to any set of pins, meaning you either wire it to match their library or you change their library. Oddly enough, they didn't set the library up to work with their shield, which is hardwired by design.


Not sure what you mean. There is no need to change anything at all in the library. The library does not reference any pins - much less define them. The library only assumes a serial interface.

Whether you are using a breakout or the shield, you need to pass an instance of a serial interface to the 'begin()' function. The example code in the library shows how to do this.

The FONAtest.ino example in the library defines the pins as they are on the shield: https://github.com/adafruit/Adafruit_FO ... NAtest.ino
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4


And constructs the SoftwareSerial instance with those pins.
Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;


which is passed to 'fona.begin()' in setup().
Code: Select all | TOGGLE FULL SIZE
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }

adafruit_support_bill
 
Posts: 70973
Joined: Sat Feb 07, 2009 10:11 am

Re: What's the order of files being compiled/used?

by jeffrey on Wed Jan 02, 2019 6:20 pm

I had a brain fart. The changes were in the config.h file, not the library files.

jeffrey
 
Posts: 31
Joined: Sat May 12, 2012 8:04 pm

Please be positive and constructive with your questions and comments.