Arduino Mega, 60LED/m WS2812B with Pololu Library

Hello,

I am very new to addressable LEDs & Arduino’s and really need some assistance. Let me apologize in advance for my ignorance and also say thank you for any help provided. Here is my “dilemma”.

I have an Arduino Mega2560 running ver1.0.6 and the 60pixel/m WS2812B LED strip. I have managed to find various sketches online, like a simple strip test & Night Rider sketch, and have easily made them work with very few mods (pin_num, led_count, etc). I decided to give the Pololu library a try so I downloaded the “Arduino library for addressable RGB LED strips from Pololu”. I followed the instructions in the “Getting Started” section but all I get is tons of errors when trying to upload. I have tried all 4 of the included examples to no avail but the particular file I am referencing here is the LedStripGradient.

Here is the list of errors. I “think” I understand what they mean but don’t know what I am missing that would cause this. If this is supposed to be a working sketch, why would these variables not already be declared?

Arduino: 1.0.6 (Windows 7), Board: “Arduino Mega 2560 or Mega ADK”

LedStripGradient:13: error: expected constructor, destructor, or type conversion before '<' token
LedStripGradient:17: error: 'rgb_color' does not name a type
LedStripGradient.ino: In function 'void loop()':
LedStripGradient:30: error: 'colors' was not declared in this scope
LedStripGradient:30: error: 'rgb_color' was not declared in this scope
LedStripGradient:30: error: expected `;' before '{' token
LedStripGradient:34: error: 'ledStrip' was not declared in this scope
LedStripGradient:34: error: 'colors' was not declared in this scope

Here is the code for LedStripGradient:

/* LedStripGradient: Example Arduino sketch that shows
 * how to control an Addressable RGB LED Strip from Pololu.
 *
 * To use this, you will need to plug an Addressable RGB LED
 * strip from Pololu into pin 12.  After uploading the sketch,
 * you should see a pattern on the LED strip that fades from
 * green to pink and also moves along the strip.
 */
 
#include <PololuLedStrip.h>

// Create an ledStrip object and specify the pin it will use.
PololuLedStrip<12> ledStrip;

// Create a buffer for holding the colors (3 bytes per color).
#define LED_COUNT 60
rgb_color colors[LED_COUNT];

void setup()
{
}

void loop()
{
  // Update the colors.
  byte time = millis() >> 2;
  for(uint16_t i = 0; i < LED_COUNT; i++)
  {
    byte x = time - 8*i;
    colors[i] = (rgb_color){ x, 255 - x, x };
  }
  
  // Write the colors to the LED strip.
  ledStrip.write(colors, LED_COUNT);  
  
  delay(10);
}

Hello.

I am sorry you are having trouble with our LED strip library. I suspect the library is not installed correctly. Could you post the full paths to both PololuLedStrip.h and PololuLedStrip.cpp so I can check how you installed the library? Maybe the compiler could not find PololuLedStrip.h; could you post the full output from the Arduino build so I can see if there is a warning about that header file? Do you see the library listed in the File -> Examples menu? Have you tried restarting the Arduino IDE?

–David

Hi David,

Thanks for taking the time to help. I do appreciate it!

As for the paths, here is what I have.

PololuLedStrip.cpp & PololuLedStrip.h both reside here- C:\Users\Chris\Documents\Arduino\libraries\PololuLedStrip\pololu-led-strip-arduino-master\PololuLedStrip
This was there default location.

Error Output -

Arduino: 1.0.6 (Windows 7), Board: "Arduino Mega 2560 or Mega ADK"
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Users\Chris\Documents\Arduino\hardware\arduino\cores\arduino -IC:\Users\Chris\Documents\Arduino\hardware\arduino\variants\mega C:\Users\Chris\AppData\Local\Temp\build6829947281873216589.tmp\LedStripGradient.cpp -o C:\Users\Chris\AppData\Local\Temp\build6829947281873216589.tmp\LedStripGradient.cpp.o

LedStripGradient.ino:10:28: warning: PololuLedStrip.h: No such file or directory
LedStripGradient:13: error: expected constructor, destructor, or type conversion before ‘<’ token
LedStripGradient:17: error: ‘rgb_color’ does not name a type
LedStripGradient.ino: In function ‘void loop()’:
LedStripGradient:30: error: ‘colors’ was not declared in this scope
LedStripGradient:30: error: ‘rgb_color’ was not declared in this scope
LedStripGradient:30: error: expected `;’ before ‘{’ token
LedStripGradient.ino:29: warning: unused variable 'x’
LedStripGradient:34: error: ‘ledStrip’ was not declared in this scope
LedStripGradient:34: error: ‘colors’ was not declared in this scope

Just as you mentioned, I see that the first warning is - PololuLedStrip.h: No such file or directory
I do have a “bit” of knowledge as to how #includes work and source file interaction but the things I tried (moving/copying cpp & h files to different dirs, including root) did not help.

The contents of the File -> Examples menu does contain PololuLedStrip.

Yes, I have restarted the Arduino IDE. I have terminated power to all components and rebooted the PC a time or two… no luck!

Thanks again for your help.

-Chris

Hey David,

I actually just got the strip to work. After changing the preferences to include verbose output during comp & upload (thanks to you!) and attempting another “fix” or two, I saw a few errors that indicated where my problem was. During testing I had left a copy of PololuLedStrip.cpp and PololuLedStrip.h in the actual \examples\LedStripGradient folder and obviously that was a no no. Removed them and whalla… the LEDs fired up.

Something else to mention…

I also had a copy of .cpp & .h in \libraries\PololuLedStrip\pololu-led-strip-arduino-master\PololuLedStrip (default location) and in \libraries\PololuLedStrip, where I had also moved a copy to. I now see that I needed the two files in the \libraries\PololuLedStrip only. It seems like they would have been placed there by default instead of having to move them there. And just to make sure I had not moved the two files myself and just forgot, I unzipped a freshly downloaded copy of “pololu-led-strip-arduino-master.zip” and moved the extracted files back to the \libraries dir and once again it did not work. I then moved the .cpp & .h files to \libraries\PololuLedStrip and it worked flawlessly. Why would they not be in the proper dir by default? Am I missing something?

Just want to make it easier for the next newbie to figure out!

Thanks David

-Chris

I am not sure what you mean by “default”. When you are installing the library you need to copy the correct folder to the correct location, and the instructions we give do not provide any automated way to do that. It sounds like you made a new a folder called PololuLedStrip and then you copied the pololu-led-strip-arduino-master folder generated by github into that new folder. You should not do that; instead you should just copy the PololuLedStrip folder that comes with the download and put it into the libraries folder. The full path to PololuLedStrip.cpp should be something like C:\arduino-1.0.6\libraries\PololuLedStrip\PololuLedStrip.cpp (if you install it in the IDE) or C:\Users\Chris\Documents\Arduino\libraries\PololuLedStrip\PololuLedStrip.cpp (if you install it in your personal libraries directory).

–David

One downside it seems to hosting files on github, for beginners, is that the arduino IDE wants to see
"LibraryName" folder with “LibraryName.cpp” & “LibraryName.h” [actually I might have the extensions wrong] but the github download will have the folder “libraryName-master-zip” or something like that. It’s not a big deal and there are some ways around it, but probably by the time people get to hosting libraries on github they forget that such a tiny thing might confuse beginners.

Maybe it should be more common to include a readme.txt in the files explaining this - not sure.