Which version of the Arduino are you using?
I'm currently using IDE v0021, on Ubuntu Linux.
[quote author=Nick Gammon link=topic=54345.msg389569#msg389569 date=1299366288]
For some obscure reason (to do with the pre-processing of your source) you also need to include SPI.h in your main sketch. I came across this and was baffled for a while.
I've also now confirmed this. Very strange, but at least now I've got the answer as to why this wasn't working!
Should this be reported as a bug, or is this the way this is intended to work? I read a little traffic on the developer mailing list from after the change for how the Ethernet library handles the SPI library, and I get the impression that this is the intended behavior...
Unfortunately, even though my simplistic example now compiles, my real code still won't work. Whenever I compile it, I no longer get the errors about the missing library, but I am still having other issues (ones I originally thought would be resolved by fixing the missing lib issue... sorry for not mentioning earlier).
Whenever I try to compile, i get this error:
In file included from EncoderInterface.c:23:
/home/andrew/arduino-0022/libraries/SPI/SPI.h:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘SPIClass’
/home/andrew/arduino-0022/libraries/SPI/SPI.h:53: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘SPI’
/home/andrew/arduino-0022/libraries/SPI/SPI.h:55: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
/home/andrew/arduino-0022/libraries/SPI/SPI.h:62: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
/home/andrew/arduino-0022/libraries/SPI/SPI.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
EncoderInterface.c: In function ‘Test_encoder_SPI_link’:
EncoderInterface.c:63: error: ‘SPI’ undeclared (first use in this function)
EncoderInterface.c:63: error: (Each undeclared identifier is reported only once
EncoderInterface.c:63: error: for each function it appears in.)
EncoderInterface.c: In function ‘Flush_encoder_cache’:
EncoderInterface.c:131: error: ‘SPI’ undeclared (first use in this function)
EncoderInterface.c: In function ‘Encoder_read_angle’:
EncoderInterface.c:183: error: ‘SPI’ undeclared (first use in this function)
EncoderInterface.c: In function ‘Encoder_setup’:
EncoderInterface.c:263: error: ‘SPI’ undeclared (first use in this function)
It still looks like it's getting mad about something in the SPI library, but I don't understand why. I tried upgrading to Arduino 0022 to see if it would help, but it won't run on my system, and I also tried reinstalling 0021, but that didn't help either.
Im including links my full sketch and source... the forum wouldnt let me upload them for some reason. Can anybody see what in the world is wrong here?
http://pastebin.com/YdfKkhLm -- MegaEncoder.pde
http://pastebin.com/z0ngcECh -- EncoderInterface.h
http://pastebin.com/M39J491z -- EncoderInterface.c