Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic External Libraries not seeing Wire/SPI Arduino Libraries (Read 8040 times)
theworstbatman
Newbies
*
Offline


Posts: 8
Joined: Oct 31st, 2015
External Libraries not seeing Wire/SPI Arduino Libraries
Oct 31st, 2015 at 10:23pm
Print Post  
Hi,

I've been bumbling through my first project using VisualMicro. It's been tough coming from the magic of the Arduino IDE, having to learn where declarations and things have to go in a .cpp file versus using the .INO files. But it's part of the challenge I wanted to sign up for. 

Anyways, I"m having a problem compiling, and I'm getting some messages I'm not sure how to deal with. I'm attempting to use some libraries from Adafruit. The PWM servo library is included in my main .INO file, but unused as of yet, and the ILI9340 TFT library is in a .cpp file I created using the tools in Visual Micro. The#include is in the matching .h file. 

Here are the complier errors I am getting:
Code (C++)
Select All
Adafruit_ILI9340.cpp:27:17: fatal error: SPI.h: No such file or directory
:#include <SPI.h>
:compilation terminated
Adafruit_PWMServoDriver.cpp:19:18: fatal error: Wire.h: No such file or directory
:#include <Wire.h>
:compilation terminated 



The project is being directed to use version Arduino 1.6, and linked Arduino 1.6.5 (not 1.6.2, which I saw the FAQ note on).


  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #1 - Oct 31st, 2015 at 10:56pm
Print Post  
Hi,

Quote:
It's been tough coming from the magic of the Arduino IDE, having to learn where declarations and things have to go in a .cpp file versus using the .INO files


I'm not sure I understand. Visual Micro works the same way as the arduino ide, you can use .ino files and cpp files in both Ide's in exactly the same way. 

If you want to create cpp files then declarations need to be the same in both ide's except that when you create cpp with the visual micro commands the basix arduino declarations are inserted for you. So this means you need to know less declarations when using visual micro over the arduino ide???

It would really help to understand your perspective here because I am obviously too close to the project to see something obvious? Thanks.

Quote:
Anyways, I"m having a problem compiling, and I'm getting some messages I'm not sure how to deal with. I'm attempting to use some libraries from Adafruit. The PWM servo library is included in my main .INO file, but unused as of yet, and the ILI9340 TFT library is in a .cpp file I created using the tools in Visual Micro. The#include is in the matching .h file.
 

Did you try the same code in the arduino ide? I expect it will also fail. 

This is because some libraries rely on other libraries. This is usually documented on the library authors site or at least shown in the examples that come with the library.

The Wire (i2c) and Spi libraries are commonly used by various libraries and searching for "SPI.h: No such file or directory" on the internet would show the answers. 

You can add any additional required libraries using the library menu, you should see the wire and spi libraries list under "Core"

It's useful to keep in mind that Visual Micro is designed to work the same way as the arduino ide so that you have the safety of knowing nearly all problems will be common issues that the community will already solved or documented. The same code can be opened in either Ide.

I hope this makes sense?
« Last Edit: Oct 31st, 2015 at 10:56pm by Tim@Visual Micro »  
Back to top
IP Logged
 
theworstbatman
Newbies
*
Offline


Posts: 8
Joined: Oct 31st, 2015
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #2 - Oct 31st, 2015 at 11:53pm
Print Post  
Tim@Visual Micro wrote on Oct 31st, 2015 at 10:56pm:
Hi,

I'm not sure I understand. Visual Micro works the same way as the arduino ide, you can use .ino files and cpp files in both Ide's in exactly the same way. 



yes, that's true - that's actually part of the reason I'm using Visual Micro - I started with arduino IDE, and as part of that, I never really 'proper' C++ organization of .h or .cpp files. 

Part of my usage of visual micro is to help me transition on that, since I don't like the way .ino files are concatenated. Nothing wrong with the Visual Micro, just a point that I'm a novice to C++ and the 'right' way to do things - I could be doing something wrong. I've been trying to look at how other people's libraries are written, as well as using some books I have on C++ for reference.

Quote:
Did you try the same code in the arduino ide? I expect it will also fail.


Just tried this out, and apparently it does, although I only get the error related to the Wire library.

I am familiar with how including libraries works. However, usually I don't need to include libraries that the other library head fires are referencing. For example, If I write   

#include FastLED.h 

I don't need to usually also #include all of the libraries that FastLED.h uses, because the header file already #includes everything it needs. 

The two Adafruit libraries do this as well - I looked into them and they have #include directives to <Wire.h> and <SPI.h>. They aren't in quotes - I know that affects how the complier looks for the file... but it's still a strange result. 

I just tried your suggestion of #including the two libraries manually in the main .ino file, and it appears to work.


Ah - while write this post I went and looked in my Arduino library directory - I had some duplicate libraries installed for these functions, and that may be a part of it. 

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #3 - Nov 1st, 2015 at 12:15am
Print Post  
Ahah all is now clear thanks very much for the detailed info. 

I think FastLED.h got around the issue because the one I see on github includes fastspi.h which is included with the library
  
Back to top
IP Logged
 
theworstbatman
Newbies
*
Offline


Posts: 8
Joined: Oct 31st, 2015
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #4 - Nov 1st, 2015 at 1:26am
Print Post  
You know what, you're right. I'm looking at an older project where I used this library before, and I totally had to include SPI.h in that file, I just didn't notice. I guess it makes sense - it's like the entire project needs to be told to include that file before the library within the project can be told to include it.

But now I'm having a different problem:

I've got two real files to this program right now. The .ino is the main file where setup() and loop() happen. I'm creating .cpp files for functions involving functions of my TFT screen and servo motors. Right now, I'm just working on the TFT portion, since I've worked with TFT stuff before. 

It appears that I have to #include my Adafruit_GFX and Adafruit_ILI9340 libraries in the .ino file and in the .h file of the TFT functions. If don't include it in the .ino file, the CPP file can't find them. However, if I do include it, the complier throws this warning:

Quote:

TFT_Funcs.cpp.o:(.bss.tft+0x0): multiple definition of `tft
RoboArm.ino:(.bss.tft+0x0): first defined here
collect2.exe*:error: ld returned 1 exit status
Error creating .elf


On the other hand, if I roughly chunk all the code into a single .ino file, it works. I think I'm not understanding something here, and while I have your attention, I'd appreciate the help... so I'm going to attach the whole project and the .ino file for reference. Granted - some of the code in this is half-baked and not expected to be visually correct, but it should compile.


Here's the .ino Text:
Code
Select All
// TFT_Functions.h

#ifndef _TFT_FUNCS_h
#define _TFT_FUNCS_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#endif
#include <SPI.h>
#include <Adafruit_ILI9340.h>
#include <Adafruit_GFX.h>
#include <FastLED.h>
#include <Metro.h>
#include <FastLED.h>


//Pins
#define SCLK 13
#define MISO 12
#define MOSI 11
#define SCRN_SEL 10
#define DC 9
#define RESET	8

Adafruit_ILI9340 tft = Adafruit_ILI9340(SCRN_SEL, DC, RESET);


//Handy Screen Definitions
#define XCENTER (ILI9340_TFTWIDTH/2)
#define YCENTER (ILI9340_TFTHEIGHT/2)

// X&Y Coords for Various Screen Items
#define EXX 5
#define EXY	5
#define GRPX 10
#define GRPY 5
#define DIALRADIUS 100

//My Colors
#define BLACK 0x000
#define BROWN 0x8200
#define RED 0xF800
#define ORANGE 0xFCA0
#define YELLOW 0xFFE0
#define GREEN 0x07E0
#define BLUE 0x001F
#define VIOLET 0x9199
#define GRAY 0x7BEF
#define WHITE 0xFFFF


void	startSplash(),
      plotExtension(),
      plotGrip(),
      plotYaw(),
      drawElements();


void startSplash() {
  tft.begin();
  tft.fillScreen(ILI9340_BLACK);
  tft.setTextColor(ILI9340_WHITE);
  tft.setTextSize(8);
  tft.setCursor(10, 10);
  tft.print("Servo Arm Beta Test");
  tft.drawCircle(XCENTER, YCENTER, 30, RED);
}

void cycleSplash(bool isLoading) {


}

void drawElements() {
  tft.fillScreen(ILI9340_BLACK);

  //Draw bar for Extension Meter
  tft.fillRect(EXX, EXY, 3, 210, GRAY);

  //Draw bar for Grip Bar
  tft.fillRect(GRPX, GRPY, 310, 3, GRAY);

  //Draw Dial Area for Yaw
  tft.fillCircle(XCENTER, ILI9340_TFTHEIGHT, DIALRADIUS, GRAY);
}

void plotExtension(int extension) {
  static int pExtension;
  //First Easy Concept: Plot the extension on a vertical bar on the left hand side of the screen.
  if (pExtension != extension) {
    //erase the old lines
    int pExtPos = map(pExtension, 0, 180, 7, 208);
    tft.fillRect(EXX, pExtPos - 1, 3, 3, GRAY);
    //Draw new ones
    int extPos = map(extension, 0, 180, 7, 208);
    tft.fillRect(EXX, extPos - 1, 3, 3, ORANGE);
  }
  //store value for next loop
  pExtension = extension;
}

void plotGrip(int grip) {
  //Show the grip bar as two lines that grow from the edges of the bar to meet in the center.
  static int pGrip;
  if (grip > pGrip) {
    //uint8_t barDisplace = map(grip, 0, 180, 0, 105);







  }
  //Store that forthe next round
  pGrip = grip;
}

void plotYaw(int yaw) {
  //Harder Concept: Plot the Yaw on a half-Dial.Pythagoras!
  //TODO: Having division of 0 or 1 could be a problem.... we'll just see how that shakes out I guess.

  static int pYaw;
  static int pYawPosX;
  static int pYawPosY;

  if (pYaw != yaw) {
    //erase the old line
    tft.drawLine(XCENTER, ILI9340_TFTHEIGHT, pYawPosX, pYawPosY, GRAY);

    //First, find the X coordinate of the dial position. All servos are given as a 0-180 value.
    int yawPosX = map(yaw, 0, 180, XCENTER - DIALRADIUS, XCENTER + DIALRADIUS);

    //Calcualte Y value by making a right triangle.
    int ySquared = sq(pYawPosX / 2) - sq(DIALRADIUS);
    int yawPosY = sqrt16(ySquared);
    tft.drawLine(XCENTER, ILI9340_TFTHEIGHT, yawPosX, yawPosY, ORANGE);

    //store some of these as static variables for the next go around
    pYaw = yaw;
    pYawPosX = yawPosX;
    pYawPosY = yawPosY;
  }

}

void setup()
{
  startSplash();
  drawElements();

  /* add setup code here */

}

void loop()
{
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);


}

 

  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #5 - Nov 1st, 2015 at 2:22am
Print Post  
Quote:
It appears that I have to #include my Adafruit_GFX and Adafruit_ILI9340 libraries in the .ino file and in the .h file of the TFT functions. If don't include it in the .ino file, the CPP file can't find them


Yes that's right. Currently this is how Arduino resolves the libs that need to be compiled so Visual Micro does the same

Quote:
However, if I do include it, the complier throws this warning


Do you get the same error if you use the arduino ide?
  
Back to top
IP Logged
 
theworstbatman
Newbies
*
Offline


Posts: 8
Joined: Oct 31st, 2015
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #6 - Nov 1st, 2015 at 3:11am
Print Post  
No, if I use the .ino file text I posted, it compiles with no error. The .ino file is everything from the .h, .cpp, and .ino all together, with repetitive #includes removed.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: External Libraries not seeing Wire/SPI Arduino Libraries
Reply #7 - Nov 1st, 2015 at 3:13am
Print Post  
Okay then you can ask adafruit how to include their lib in a cpp. There must be a missing #ifdef in their .h file or something. What you are doing with the duplicate #includes in .ino and .cpp is the only way to do it.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint