[SOLVED] get confused while adding libraries

Post here first, or if you can't find a relevant section!
Post Reply
dev
Posts: 78
Joined: Sun Feb 19, 2017 8:41 am

[SOLVED] get confused while adding libraries

Post by dev » Wed Jan 24, 2018 3:29 pm

Hi
I have code file .ino but it requires some other libraries which i have downloaded. But i don't know how to add these libraries as include folder to the main code.

So, that my main.ino code can search .h files in that folder

stevestrong
Posts: 2057
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: get confused while adding libraries

Post by stevestrong » Wed Jan 24, 2018 3:34 pm

You can add header files to the directory where your INO file is located.
Or you can use complete libraries, the source files must be placed under /user/Documents/Arduino/libraries/<library_name>.

This is valid only if you use Arduino IDE to build your project.

User avatar
mrburnette
Posts: 2198
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: get confused while adding libraries

Post by mrburnette » Wed Jan 24, 2018 3:57 pm


User avatar
mrburnette
Posts: 2198
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: get confused while adding libraries

Post by mrburnette » Wed Jan 24, 2018 5:02 pm

Added thoughts:

I publish some projects. Libraries are a big positive for the Arduino world, even if I am capable of writing my own, why? I'm a f_eeking hacker, I take what I want from libraries, muck with the code, etc. It's in my DNA.

However, by moving the library code into my sketch folder, I can create a multi-tab ArduinoIDE project and offer myself some protection from future library issues; that is, if Adafruit screwed-up the graphics library, my code is insulated from that because when I update from the library manager, my sources in my Arduino/sketch directory are not affected.

One needs to be judicious how that implement this power, but when I ZIP an Arduino Sketch folder, I am also grabbing libraries that I used that are not normally included with the Arduino stock libraries. Therefore, when I post my project and upload the ZIP, the end-user does not have to be concerned about acquiring libraries from all over the world and maybe having issues with getting the sketch to compile. I really am a "bad" author, because when I publish something, I wash my hands of it and move on... I do not want to support the project for the rest of my life. And if I modify a library, I do not want to have to take a full page and explain why I did thus and so.

As one grows in their comfort of using the ArduinoIDE, you may wish to try multi-tab projects. I encourage you to do so.
MultiTab.png
MultiTab.png (14.18 KiB) Viewed 166 times

Ray

Added:
Please note that there is a tab titled notes.h
This entire tab is marked /* on the first line and */ on the last line; that is, everything in the file is a comment!
This is just my way of having a place to stick notes, ASCII pinouts, and so forth. I find this very helpful when
I come back months later to review my code. For example, with a display like the Barometer sketch, I used
the notes section to define character positioning, etc.

Code: Select all

/* 
    http://forum.arduino.cc/index.php?topic=265904.msg2077121#msg2077121
    Forum user: madias, Vienna, AUSTRIA:  "I if modified the Adafruit Ili9341 library, for all 
    people, who didn't apply the SPI patch on thread number #1361. But I'll strongly recommend to 
    apply timschuerewegen modifications. Must have bugfixes! There was no #define for  
    digitalPinToBitMask/digitalPinToPort...  so I copied them from UTFT at the begin of Adafruit_ili9341.cpp.
    (are those digitalPin**** now included in the newest STM32 release?) Then I got a mismatch in the *.h file 
    because of volatile uint32 * VS volatile uint32_t *. I corrected this."
    Using library: adafruit ili9341, hardware SPI
Pin connections:
    #define TFT_DC 12
    #define TFT_CS 13
    #define TFT_RST 14
    the rest of the pins (MISO,MOSI,SCK) are the standard SPI pins of your mini.



  ILI9341 TFT GLCD display connections for hardware SPI:
  Signal           Maple Mini           Leonardo      LCD Display    UNO pins
  ===============  ===========          ========      ===========    ========
  #define _sclk         6         //         15       J2 pin 7          13
  #define _miso         5 NC      //         14          pin 9          12
  #define _mosi         4         //         16          pin 6          11
  #define TFT_CS       13         //         10          pin 3          10
  #define TFT_DC       12         //          9          pin 5           9
  #define TFT_RST      14         //          8          pin 4           8


 Color definitions for TFT SPI 2.2" Display
    ILI9341_BLACK   0x0000
    ILI9341_BLUE    0x001F
    ILI9341_RED     0xF800
    ILI9341_GREEN   0x07E0
    ILI9341_CYAN    0x07FF
    ILI9341_MAGENTA 0xF81F
    ILI9341_YELLOW  0xFFE0  
    ILI9341_WHITE   0xFFFF


**************************** ILI9341 320x240 DISPLAY LAYOUT ****************************
0,0
----------------------------------------------------------------------------> 319
| nnnT                                                                 DOW
|              lcd.fillRect( 0,  0, 319, 59, 0);     // blank top
|
|
|<- 059 
|
|              lcd.fillRect( 0, 60, 319, 114, 0);     // blank middle
|                              HH:MM:SS A
|
|
|
|<- 174
|              lcd.fillRect( 0, 175, 319, 64, 0);     // blank lower
|
| MON DD YYYY
|
|<- 239
*/

User avatar
mrburnette
Posts: 2198
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: get confused while adding libraries

Post by mrburnette » Wed Jan 24, 2018 5:07 pm

stevestrong wrote:
Wed Jan 24, 2018 3:34 pm
<...>
This is valid only if you use Arduino IDE to build your project.
Yes as you and I know. For the new users of Arduino, a little about the process:

This is because ArduinoIDE gathers all of the *.INO files in the project folder and concatenates them as input to the compiler. The Arduino system also manages the function prototyping - but, sometimes if fails and the programmer will have to add a forward declaration.
https://github.com/arduino/Arduino/wiki/Build-Process
The Arduino environment performs a few transformations to your sketch before passing it to the avr-gcc compiler:
  • All .ino files in the sketch folder (shown in the IDE as tabs with no extension) are concatenated together and the .cpp extension is added to the filename.
  • #include <Arduino.h> is added to the sketch. This header file (found in the core folder for the currently selected board) includes all the definitions needed for the standard Arduino core.
  • Prototypes are generated for all function definitions in .ino files that don't already have prototypes. In some rare cases prototype generation may fail for some functions. To work around this, you can provide your own prototypes for these functions.
  • #line directives are added to make warning or error messages reflect the original sketch layout.
No pre-processing is done to files in a sketch with any extension other than .ino. Additionally, .h files in the sketch are not automatically #included from the main sketch file. Further, if you want to call functions defined in a .c file from a .cpp file (like one generated from your sketch), you'll need to wrap its declarations in an 'extern "C" {}' block that is defined only inside of C++ files.

Ray

dev
Posts: 78
Joined: Sun Feb 19, 2017 8:41 am

Re: get confused while adding libraries

Post by dev » Thu Jan 25, 2018 3:14 am

Thanks.
I got one more method. We can directly include .zip as library and it worked too..

User avatar
mrburnette
Posts: 2198
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: get confused while adding libraries

Post by mrburnette » Thu Jan 25, 2018 1:29 pm

dev wrote:
Thu Jan 25, 2018 3:14 am
Thanks.
I got one more method. We can directly include .zip as library and it worked too..
And you can just manually unZIP into the /Arduino/library folder and bounce the IDE (shut down, restart.) The JAVA IDE reads the library folder once and caches the names. If you use IDE tools, the cache gets updated, but if you extract an archive directly with the IDE open, then the IDE has to be bounced.

Ray

Post Reply