Hi,
regarding to [solved] DIP204-4 with SPI - Displays - Arduino Forum, i want to create own class for spi-access to the display...
i looked into liquidcrystal-library and saw, that it is inherited from print to get number/float conversion.
so i also inherited from print, included spi.h, but i cannot access to spi-functions and constants.
In file included from sketch_aug31a.ino:1:
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h: In member function ‘void DIP204_SPI::init()’:
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:90: error: ‘OUTPUT’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:90: error: ‘pinMode’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:93: error: ‘SPI’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:93: error: ‘LSBFIRST’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:94: error: ‘SPI_MODE3’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:95: error: ‘SPI_CLOCK_DIV64’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h: In member function ‘void DIP204_SPI::clear()’:
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:118: error: ‘delay’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h: In member function ‘void DIP204_SPI::send(uint8_t, uint8_t)’:
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:191: error: ‘LOW’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:191: error: ‘digitalWrite’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:197: error: ‘SPI’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:199: error: ‘SPI’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:200: error: ‘SPI’ was not declared in this scope
./arduino-1.0.5/libraries/DIP204_SPI/dip204_spi.h:203: error: ‘HIGH’ was not declared in this scope
dip204_spi.h is attached to first post (downloaded already by anyone, maybe you?)
there (in line 9): #include <SPI.h>
i got no error, that any include (especially spi.h) is not found.
after attaching it i only changed line 173 to "virtual size_t write(uint8_t value)" because of wrong return type.
do i need to manually include "#include <Arduino.h>"?
the "old" code (without class) is working in current Arduino-Version without errors, so i think its the class-scope, in that i can't access definitions from another library.
inheriting from both (print & spi) seems to complex for me (maybe its not working in arduino/gcc-avr).
actually i try to add debug-code, but in the moment, i initialize my class, setup and loop seems not to be called.
//DIP204_SPI lcd(53);
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
Serial.println("setup()");
}
void loop()
{
Serial.println("loop()");
delay(1000);
}
if i remove the // in first line, i see nothing more on serial-console...without init, i get 1x "setup()" and multiple "loop()" as expected.
actual sd-Library seems not to use the SPI-Library (sd/utility/sd2card.cpp):
// functions for hardware SPI
/** Send a byte to the card */
static void spiSend(uint8_t b) {
SPDR = b;
while (!(SPSR & (1 << SPIF)));
}
i did not understand that a simple assign sends data over SPI...
frank:
is this the right way to use SPI in my Library or should this been done in another way?
Adding the include in the main sketch triggers the IDE to copy SPI.h to the temporary directory where it does its compiles. Even if you don't reference SPI in the main sketch. There is no real workaround to this as far as I know.
Certainly (other than having to do that) you can use SPI (or indeed any other library) in your own library.
without the creation of the in-class-object i got no Text on Display (write and send is called right).
i've looked in SD, Ethernet and WiFi-Library...they all implement its own SPI-Code (not using the SPI-Library) and creating an Object of their SPI-Class in the main-class.
Your constructor calls init which does a lot of stuff. You cannot know what order constructors are called in, and should not do any substantial work in one. Call init yourself (not from the constructor). eg.
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
Serial.println("setup()");
lcd.init(53); // <--- initialize here
}
Well I see you are already doing that, so lose the "init" from the constructor.
Then delete your "own" instance of SPI that you added.