WS2801 Adafruit Library - SPI.h error: 'byte' does not name a type

Hey guys,

there is some problem with SPI library I can't solve. I want to upload some example code to test my new WS2801 LED strand, for which I downloaded the Adafruit library. But by verifying the code, there is some huge error output:

In file included from /.../libraries/SPI/SPI.cpp:12:
/.../libraries/SPI/SPI.h:38: error: 'byte' does not name a type
/.../libraries/SPI/SPI.h:55: error: 'byte' does not name a type
/.../libraries/SPI/SPI.cpp: In static member function 'static void SPIClass::begin()':
/.../libraries/SPI/SPI.cpp:23: error: 'OUTPUT' was not declared in this scope
/.../libraries/SPI/SPI.cpp:23: error: 'pinMode' was not declared in this scope
/.../libraries/SPI/SPI.cpp:27: error: 'LOW' was not declared in this scope
/.../libraries/SPI/SPI.cpp:27: error: 'digitalWrite' was not declared in this scope
/.../libraries/SPI/SPI.cpp:29: error: 'HIGH' was not declared in this scope
/.../libraries/SPI/SPI.cpp: In static member function 'static void SPIClass::setBitOrder(uint8_t)':
/.../libraries/SPI/SPI.cpp:44: error: 'LSBFIRST' was not declared in this scope

So what's wrong?

Best regards
Dennis

What's your code?

Hey,

it’s the strandtest.pde example of the ws2801 adafruit library:

#include "Adafruit_WS2801.h"
#include "SPI.h" // Comment out this line if using Trinket or Gemma
#ifdef __AVR_ATtiny85__
 #include <avr/power.h>
#endif

/*****************************************************************************
Example sketch for driving Adafruit WS2801 pixels!


  Designed specifically to work with the Adafruit RGB Pixels!
  12mm Bullet shape ----> https://www.adafruit.com/products/322
  12mm Flat shape   ----> https://www.adafruit.com/products/738
  36mm Square shape ----> https://www.adafruit.com/products/683

  These pixels use SPI to transmit the color data, and have built in
  high speed PWM drivers for 24 bit color per pixel
  2 pins are required to interface

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution

*****************************************************************************/

// Choose which 2 pins you will use for output.
// Can be any valid output pins.
// The colors of the wires may be totally different so
// BE SURE TO CHECK YOUR PIXELS TO SEE WHICH WIRES TO USE!
uint8_t dataPin  = 2;    // Yellow wire on Adafruit Pixels
uint8_t clockPin = 3;    // Green wire on Adafruit Pixels

// Don't forget to connect the ground wire to Arduino ground,
// and the +5V wire to a +5V supply

// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin);

// Optional: leave off pin numbers to use hardware SPI
// (pinout is then specific to each board and can't be changed)
//Adafruit_WS2801 strip = Adafruit_WS2801(25);

// For 36mm LED pixels: these pixels internally represent color in a
// different format.  Either of the above constructors can accept an
// optional extra parameter: WS2801_RGB is 'conventional' RGB order
// WS2801_GRB is the GRB order required by the 36mm pixels.  Other
// than this parameter, your code does not need to do anything different;
// the library will handle the format change.  Examples:
//Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin, WS2801_GRB);
//Adafruit_WS2801 strip = Adafruit_WS2801(25, WS2801_GRB);

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif

  strip.begin();

  // Update LED contents, to start they are all 'off'
  strip.show();
}


void loop() {
  // Some example procedures showing how to display to the pixels
  
  colorWipe(Color(255, 0, 0), 50);
  colorWipe(Color(0, 255, 0), 50);
  colorWipe(Color(0, 0, 255), 50);
  rainbow(20);
  rainbowCycle(20);
}

void rainbow(uint8_t wait) {
  int i, j;
   
  for (j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 255));
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// Slightly different, this one makes the rainbow wheel equally distributed 
// along the chain
void rainbowCycle(uint8_t wait) {
  int i, j;
  
  for (j=0; j < 256 * 5; j++) {     // 5 cycles of all 25 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      // tricky math! we use each pixel as a fraction of the full 96-color wheel
      // (thats the i / strip.numPixels() part)
      // Then add in j which makes the colors go around per pixel
      // the % 96 is to make the wheel cycle around
      strip.setPixelColor(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) );
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// fill the dots one after the other with said color
// good for testing purposes
void colorWipe(uint32_t c, uint8_t wait) {
  int i;
  
  for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

/* Helper functions */

// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}

//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos)
{
  if (WheelPos < 85) {
   return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
   WheelPos -= 85;
   return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170; 
   return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Best regards
Dennis

Try putting “#include <Arduino.h>” as the first line.

No, doesn't work :confused: same output. could it be that the SPI library is broken?

laemmen:
could it be that the SPI library is broken?

I think somebody would have noticed that before now...

I suspect you're using an old version of the Arduino IDE/software.

Actually I'm using Arduino 1.0.5 for MacOS.. however, the problem is obviously referring to SPI. I downloaded the newest beta of Arduino but the problem is the same. How can I check if the SPI library is broken? It's the first time that such a problem occurs and only in connection with the Adafruit library for ws2801..

Best regards
Dennis

laemmen:
How can I check if the SPI library is broken?

By using google to check out how many other people think it's broken vs. how many people are using it happily.

fungus:

laemmen:
How can I check if the SPI library is broken?

By using google to check out how many other people think it's broken vs. how many people are using it happily.

Instead I asked my computer. computer said 'no'. So maybe there's another, let's say more useful, way to fix the problem?

best regards
Dennis

laemmen:
Instead I asked my computer. computer said 'no'. So maybe there's another, let's say more useful, way to fix the problem?

You can start by reading the error messages:

error: 'digitalWrite' was not declared in this scope
error: 'pinMode' was not declared in this scope
etc.

They're not part of the SPI library, they're standard Arduino function definitions. This is why I suggested adding "#include Arduino.h" before the Adafruit library.

In older versions of Arduino, those things were in a file called "Wprogram.h", not "Arduino.h". This is why I suspected you might have an older version installed.

If neither of those suggestions help, and nobody on the Internet is seeing the messages you're seeing, then something is messed up in your installation. I can't see your installation from here.

Okay, I read the messages but I don't understand them as you said that digitalWrite and pinMode are standard definitions. All other libraries, examples and sketches (of course including digitalWrite, analogWrite and so on) are working perfectly as they should - but as soon as there is SPI.h included nothing works. Assuming that this library is broken for whatever reason, how can I undo it when reinstalling Arduino hasn't fixed the problem?

Best regards
Dennis

laemmen:
Okay, I read the messages but I don't understand them
...
Assuming that this library is broken for whatever reason...

The reason you don't understand them is because you keep on assuming the SPI library is broken, not your installation

(...or some library you installed, or some other file in your 'libraries' folder that's in a place where it's not supposed to be).

Dennis,

Typically when you get errors like that you are using a library that
was written for pre 1.x on a 1.x IDE.

Are there any other messages than what you posted?
Often the actual problem can be early in the error/warning output.
What is most important is the first error and potentially the last warning
prior to the first error.

What might help is to turn on verbose mode so you can see if there are
any relevant warnings prior to the first error.

--- bill

bperrybap:
Dennis,

Typically when you get errors like that you are using a library that
was written for pre 1.x on a 1.x IDE.

I looked at the Adafruit library and it starts with this:

#if (ARDUINO >= 100)
 #include <Arduino.h>
#else
 #include <WProgram.h>
 #include <pins_arduino.h>
#endif

So I don’t think that’s the case. In theory it should work on both.

OTOH we don’t know if he’s using the same library I’m looking at … or if anything else has been messed up on his machine.

I posted everything that came out and it's only happening with SPI included... so what am I supposed to do now? The library I'm using is this one GitHub - adafruit/Adafruit-WS2801-Library: Arduino library for controlling strips/pixels using WS2801 driver chips

What board do you have selected in the tools menu? Anything weird?

Turn on verbose compilation and look carefully where the #include files are coming from when it compiles SPI.cpp.

My Uno is selected properly. Verbose? I'll check that

i've get something similar using the WS2801 library.
My code will not compile for an Adafruit Gemma board.
But it does when selecting an Adafruit Flora board.

This is the errors i get with the Gemma board selected:

In file included from test.ino:1:
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h: In static member function 'static byte SPIClass::transfer(byte)':
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:56: error: 'SPDR' was not declared in this scope
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:57: error: 'SPSR' was not declared in this scope
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:57: error: 'SPIF' was not declared in this scope
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h: In static member function 'static void SPIClass::attachInterrupt()':
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:63: error: 'SPCR' was not declared in this scope
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:63: error: 'SPIE' was not declared in this scope
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h: In static member function 'static void SPIClass::detachInterrupt()':
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:67: error: 'SPCR' was not declared in this scope
/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:67: error: 'SPIE' was not declared in this scope

klankschap:
i've get something similar using the WS2801 library.

Nope, that's completely different. Not the same problem at all.

In file included from test.ino:1:
error: 'SPDR' was not declared in this scope
error: 'SPSR' was not declared in this scope
error: 'SPIF' was not declared in this scope

You're trying to use it on a chip that doesn't have a hardware SPI interface, ie. a Tiny85.