Including SPI Lib in a Class

I have been trying to create my own class and i wanted to implement the SPI transfer commands. I have a few Serial.print commands to help debug, which work fine. However, whenever there is an SPI.transfer(some byte here) command there is an error that says "SPI was not declared within the scope". I included the SPI.h in my cpp file.

Why not use the SPI code directly? SPDR = (some byte here); and whatever the other code is that watches to see that it's done.

I just started using the arduino recently and I'm not exactly sure what that is so I can look into that, but shouldnt the class I was writing not give that error if I included the SPI.h file anyway?

Its to do with the Arduino IDEs library handling. You can't include one library in another unless you include it in you .ino file as well. Even then it doesn't always work.

Thanks a lot

Just include it eg
#include <SPI.h>

and it does work in classes.

@tom First time I’ve heard of any problems at all with using lib from within classes or other libs. Got any examples?

this is the first few line of Adafruit’s ST7735 lib which is both a class and a lib.

#include "Adafruit_ST7735.h"
#include <avr/pgmspace.h>
#include <limits.h>
#include "pins_arduino.h"
#include "wiring_private.h"
#include <SPI.h>

Mark

jwhsiehum:
whenever there is an SPI.transfer(some byte here) command there is an error that says “SPI was not declared within the scope”. I included the SPI.h in my cpp file.

I think it’s time to post some code demonstrating the problem - preferably a complete example i.e. a test sketch using the library as well as the library itself.