Newbie question

Hello

I am just starting out with a Pro Mini. Learning slowly.

I have a small code for an I2C screen. Works fine on my laptop in the living room. Pretty basic text and graphics.

When I move it to my other laptop in my shed, it throws up this error:

C:\Users\Ian\Documents\Arduino\libraries\Adafruit_SSD1306/Adafruit_SSD1306.h:48:17: fatal error: SPI.h: No such file or directory
#include <SPI.h>

This has to be a library issue right? But, I just cannot see any difference between the two laptops.
I have re-installed all the libraries. Code compiles on one, and not the other.

I have checked the Adafruit_SSD1306.h file and the are both configured the same for the display (128x64).

I have a side question....
Within this Adafruit_SSD1306.h text file, it calls: '#include <SPI.h>' and
'#include <Adafruit_GFX.h>'.

Does this mean they are loaded when these files run (and therefore automatically included), and therefore do not need to be declared again at the beginning of my written code?

I ask this, as my fully working laptop code I wrote does not call the function '#include <SPI.h>' at all.

The only three items I call in my code are:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

And the screen works fine.

So, I can only assume '#include <SPI.h>' is called directly by the SSD1306.h library as needed. Does that make sense?

I might be talking rubbish here!

SPI.h is a file from the SPI library, which is supposed to come with the IDE. Maybe you should try re-install the Arduino IDE on the shed laptop.

Which version of the Arduino IDE are you using on the shed laptop?

IanStMartin:
Does this mean they are loaded when these files run (and therefore automatically included), and therefore do not need to be declared again at the beginning of my written code?

It depends on the IDE version. Older versions required that #include directives be added to the sketch for all library dependencies. The preprocessing system was later improved so this was no longer necessary. For this reason, sketches that compile on newer IDE versions may fail with "No such file or directory" errors for #include directives in libraries when compiled on older IDE versions.

Both laptops have version 1.6.5.
I have gone through all the version numbers of libraries, the IDE etc. Can't see any differences.
Obviously something somewhere is outta wack

But oddly... I have other demo codes that compile fine on the shed laptop and they request #include <SPI.h>

So the SPI.h file must be there. Very odd.

I have also ensured that the paths are identical to all files on both laptops.
Looks like my living room laptop will be moving to the shed until further notice!

No more Netflicks wife

IanStMartin:
Both laptops have version 1.6.5.

If you have a sketch like this:

#include <Adafruit_SSD1306.h>
void setup() {}
void loop() {}

and you compile it on Arduino IDE 1.6.5, it will fail with this error:

C:\Users\Ian\Documents\Arduino\libraries\Adafruit_SSD1306/Adafruit_SSD1306.h:48:17: fatal error: SPI.h: No such file or directory
 #include <SPI.h>

If you compile that with Arduino IDE 1.8.8, it will have no error.

If you want that sketch to compile on Arduino IDE 1.6.5, you need to add this line to the sketch:

#include <SPI.h>

Thanks Pert..

Err... but it doesn't. I tried adding #include <SPI.h> to the code and it still failed.

Something is amiss here....

My IDE shows version 1.6.5 at the top of the screen.
So I downloaded version 1.8.8 and went to install that.

It flagged up that I was already using 1.8.3? Eh?

Clean install time I think

IanStMartin:
Err... but it doesn't. I tried adding #include <SPI.h> to the code and it still failed.

With the exact same error message as before?

Do you see SPI listed under the Sketch > Include library menu?

OK. Deleted all on the shed laptop and full re-install with 1.8.8. Seems to have fixed it.
No idea what happened there, some kind of corrupted install.

Even though it does not matter now - yes, SPI was listed under the Include Library Pert.

On a side note...

The shed laptop does compile now, but I do get an error that states:

warning: extra tokens at end of #endif directive [-Wendif-labels]

What does that mean? Google here I come

Sorry, I see it's a warning, not an error. Please do this:

  • Click on the black console window at the bottom of the Arduino IDE window
  • Press "Ctrl+A". This will select all the text in the window.
  • Press "Ctrl+C". This will copy the text to the clipboard.
  • Open this forum thread in your browser.
  • Click on the "</>" button in the "Quick Reply" toolbar. This will add code tags, that prevent any part of the warning output from being interpreted as markup by the forum software.
  • Press "Ctrl+V". This will paste the warning output inside the code tags.
  • Click "Post".

... And add your code, I don't think you've shown it yet. You may only post the fe first lines where the #if #endif should be located

Thanks for everyone's advice. This was a re-install of the IDE and it all appears to work.
Only thing that throws up is the 'xtra tokens at end of #endif directive' line, and I believe that is just a warning.
Program complies and runs fine

In the future, better titles for your posts would be nice.

I'm glad to hear it's working.

I'm still interested in seeing the full content of the "extra token" warning. The reason is that if it's in a library I'd like to try to get that fixed to prevent it from causing confusion for anyone else in the future.