Welcome to Laser Pointer Forums - discuss green laser pointers, blue laser pointers, and all types of lasers

LPF Donation via Stripe | LPF Donation - Other Methods

Links below open in new window

ArcticMyst Security by Avery

Need some assistance for driving LPD6803 RGB LEDs from an arduino

Joined
Jul 4, 2008
Messages
2,499
Points
113
Hello, this may sound silly, but I am right now trying out a code for driving
programmable LPD6803 LED RGB pixels. It's supposed to be straight forward but my arduino complier is spitting back errors and the latest driver
compiled but is messed up.

LED strip has 30 LED pixels in a row and can run 12Vdc-6Vdc.

I hope someone here has experience with the LED pixel in question
LPD 6803.

This is a simple strand test code.
I'll post a sample of the code below. This code spits back several compiling errors. All the libraries have been installed for this given test.

function 'void LPD6803::begin()':
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp:140: error: 'Timer1' was not declared in this scope
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp: In member function 'void LPD6803::setCPUmax(uint8_t)':
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp:156: error: 'Timer1' was not declared in this scope

#include*<TimerOne.h>
#include*"LPD6803.h"

//Example*to*control*LPD6803-based*RGB*LED*Modules*in*a*strand
//*Original*code*by*Bliptronics.com*Ben*Moyes*2009
//Use*this*as*you*wish,*but*please*give*credit,*or*at*least*buy*some*of*my*LEDs!

//*Code*cleaned*up*and*Object-ified*by*ladyada,*should*be*a*bit*easier*to*use

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



//*Choose*which*2*pins*you*will*use*for*output.
//*Can*be*any*valid*output*pins.
int dataPin = 2; // 'yellow' wire
int clockPin = 3; // 'green' wire
//*Don't*forget*to*connect*'blue'*to*ground*and*'red'*to*+5V

//*Timer*1*is*also*used*by*the*strip*to*send*pixel*clocks

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


void setup() {
**
**// The Arduino needs to clock out the data to the pixels
**// this happens in interrupt timer 1, we can change how often
**// to call the interrupt. setting CPUmax to 100 will take nearly all all the
**// time to do the pixel updates and a nicer/faster display,
**// especially with strands of over 100 dots.
**// (Note that the max is 'pessimistic', its probably 10% or 20% less in reality)
**
**strip.setCPUmax(50);**// start with 50% CPU usage. up this if the strand flickers or is slow
**
**// Start up the LED counter
**strip.begin();

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


void loop() {
**// Some example procedures showing how to display to the pixels
**
**colorWipe(Color(63,*0,*0),*50);
**colorWipe(Color(0,*63,*0),*50);
**colorWipe(Color(0,*0,*63),*50);

**rainbow(50);

**rainbowCycle(50);
}

void rainbow(uint8_t wait) {
**int i, j;
***
**for (j=0; j < 96 * 3; j++) { // 3 cycles of all 96 colors in the wheel
****for (i=0; i < strip.numPixels(); i++) {
******strip.setPixelColor(i,*Wheel( (i + j) % 96));
****}**
****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 < 96 * 5; j++) { // 5 cycles of all 96 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 * 96 / strip.numPixels()) + j) % 96) );
****}**
****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(uint16_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*15*bit*color*value*from*R,G,B
unsigned int Color(byte r, byte g, byte b)
{
**//Take the lowest 5 bits of each value and append them end to end
**return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<5 | (unsigned int)r & 0x1F);
}

//Input*a*value*0*to*127*to*get*a*color*value.
//The*colours*are*a*transition*r*-*g*-b*-*back*to*r
unsigned int Wheel(byte WheelPos)
{
**byte r,g,b;
**switch(WheelPos >> 5)
**{
****case 0:
******r=31-*WheelPos*%*32;***//Red down
******g=WheelPos*%*32;******// Green up
******b=0;******************//blue off
******break;
****case 1:
******g=31-*WheelPos*%*32;**//green down
******b=WheelPos*%*32;******//blue up
******r=0;******************//red off
******break;
****case 2:
******b=31-*WheelPos*%*32;**//blue down
******r=WheelPos*%*32;******//red up
******g=0;******************//green off
******break;
**}
**return(Color(r,g,b));
}

:confused::confused:

What's going on here
 





Joined
Sep 29, 2013
Messages
97
Points
8
Hello, this may sound silly, but I am right now trying out a code for driving
programmable LPD6803 LED RGB pixels. It's supposed to be straight forward but my arduino complier is spitting back errors and the latest driver
compiled but is messed up.

LED strip has 30 LED pixels in a row and can run 12Vdc-6Vdc.

I hope someone here has experience with the LED pixel in question
LPD 6803.

This is a simple strand test code.
I'll post a sample of the code below. This code spits back several compiling errors. All the libraries have been installed for this given test.

function 'void LPD6803::begin()':
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp:140: error: 'Timer1' was not declared in this scope
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp: In member function 'void LPD6803::setCPUmax(uint8_t)':
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp:156: error: 'Timer1' was not declared in this scope



:confused::confused:

What's going on here

I've only recently started programming with my Arduino micro....

BUT... it looks like its complaining about timer1 not being declared? have you tried fixing that first?

not sure about all that LPD6803 specific programming... I've just started small with the basics.. (single led's etc.)
 
Last edited:
Joined
Jul 4, 2008
Messages
2,499
Points
113
I've only recently started programming with my Arduino micro....

BUT... it looks like its complaining about timer1 not being declared? have you tried fixing that first?

not sure about all that LPD6803 specific programming... I've just started small with the basics.. (single led's etc.)

Yes tries out trying to declare timer1... not really working.

I think hardware issue with the LPD6803.. the original libraries for Arduino look like they are using an older code ARDINO1... and different frequency.

Strange. I think I better do some more searching. Got the LEDs to light up
but they stay red only.
:(
 
Joined
Sep 29, 2013
Messages
97
Points
8
Yes tries out trying to declare timer1... not really working.

I think hardware issue with the LPD6803.. the original libraries for Arduino look like they are using an older code ARDINO1... and different frequency.

Strange. I think I better do some more searching. Got the LEDs to light up
but they stay red only.
:(

well sounds like you're a lot deeper than I am so I probably won't be much help...

But out of curiosity/troubleshooting... have you tried declaring and using BASIC timers? without all the other code? just to make sure your using it right?
 
Joined
Jul 4, 2008
Messages
2,499
Points
113
well sounds like you're a lot deeper than I am so I probably won't be much help...

But out of curiosity/troubleshooting... have you tried declaring and using BASIC timers? without all the other code? just to make sure your using it right?

Yes. I tried the timers. They work.

I just came across a SPI code for driving this led pixel.
However, I seem to still be running into frequency issues. All the LEDs remain on and red.

it defines pin 4 as the data point. Still no luck.:confused:

#include <FastSPI_LED.h>

#define NUM_LEDS 30

// Sometimes chipsets wire in a backwards sort of way
struct CRGB { unsigned char b; unsigned char r; unsigned char g; };
// struct CRGB { unsigned char r; unsigned char g; unsigned char b; };
struct CRGB *leds;

#define PIN 4

void setup()
{
FastSPI_LED.setLeds(30);
FastSPI_LED.setChipset(CFastSPI_LED::SPI_LPD6803);
//FastSPI_LED.setChipset(CFastSPI_LED::SPI_TM1809);
//FastSPI_LED.setChipset(CFastSPI_LED::SPI_LPD6803);
//FastSPI_LED.setChipset(CFastSPI_LED::SPI_HL1606);
//FastSPI_LED.setChipset(CFastSPI_LED::SPI_595);
//FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);

FastSPI_LED.setPin(4);

FastSPI_LED.init();
FastSPI_LED.start();

leds = (struct CRGB*)FastSPI_LED.getRGBData();
}

void loop() {
// one at a time
for(int j = 0; j < 3; j++) {
for(int i = 0 ; i < NUM_LEDS; i++ ) {
memset(leds, 0, NUM_LEDS * 30);
switch(j) {
case 0: leds.r = 255; break;
case 1: leds.g = 255; break;
case 2: leds.b = 255; break;
}
FastSPI_LED.show();
delay(10);
}
}

// growing/receeding bars
for(int j = 0; j < 3; j++) {
memset(leds, 0, NUM_LEDS * 3);
for(int i = 0 ; i < NUM_LEDS; i++ ) {
switch(j) {
case 0: leds.r = 255; break;
case 1: leds.g = 255; break;
case 2: leds.b = 255; break;
}
FastSPI_LED.show();
delay(10);
}
for(int i = NUM_LEDS-1 ; i >= 0; i-- ) {
switch(j) {
case 0: leds.r = 0; break;
case 1: leds.g = 0; break;
case 2: leds.b = 0; break;
}
FastSPI_LED.show();
delay(1);
}
}

// Fade in/fade out
for(int j = 0; j < 3; j++ ) {
memset(leds, 0, NUM_LEDS * 3);
for(int k = 0; k < 256; k++) {
for(int i = 0; i < NUM_LEDS; i++ ) {
switch(j) {
case 0: leds.r = k; break;
case 1: leds.g = k; break;
case 2: leds.b = k; break;
}
}
FastSPI_LED.show();
delay(3);
}
for(int k = 255; k >= 0; k--) {
for(int i = 0; i < NUM_LEDS; i++ ) {
switch(j) {
case 0: leds.r = k; break;
case 1: leds.g = k; break;
case 2: leds.b = k; break;
}
}
FastSPI_LED.show();
delay(3);
}
}
}
 
Joined
Sep 12, 2007
Messages
9,399
Points
113
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp:140: error: 'Timer1' was not declared in this scope
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp: In member function 'void LPD6803::setCPUmax(uint8_t)':
/Users/xxx/Documents/Arduino/libraries/LPD6803RGB/LPD6803.cpp:156: error: 'Timer1' was not declared in this scope

This is telling you where the problem is. Would you mind pasting the contents of LPD6803.cpp here and highlighting lines 140 and 156 for us? Use [CODE ] [ /CODE] tags around the code so it doesn't omit your extra spaces/tabs.
 
Joined
Jul 4, 2008
Messages
2,499
Points
113
Ok here it is.
Line 140 is green
line 156 is blue

Thank you Cyparagon for pointing me in the right direction.
Keep getting errors on this build. Other sketches seem to output an incorrect frequency and cause the strip to
pulse.... all red. no other colours

Code:
#include <TimerOne.h>
#include "LPD6803.h"

/*****************************************************************************
 * Example to control LPD6803-based RGB LED Modules in a strand
 * Original code by Bliptronics.com Ben Moyes 2009
 * Use this as you wish, but please give credit, or at least buy some of my LEDs!
 *
 * Code cleaned up and Object-ified by ladyada, should be a bit easier to use
 *
 * Library Optimized for fast refresh rates 2011 by michu@neophob.com
 *****************************************************************************/

// the arrays of ints that hold each LED's 15 bit color values
static uint16_t *pixels;
static uint16_t numLEDs;

static uint8_t dataPin, clockPin;
 
enum lpd6803mode {
  START,
  HEADER,
  DATA,
  DONE
};

static lpd6803mode SendMode;   // Used in interrupt 0=start,1=header,2=data,3=data done
static byte  BitCount;   // Used in interrupt
static uint16_t  LedIndex;   // Used in interrupt - Which LED we are sending.
static byte  BlankCounter;  //Used in interrupt.

static byte lastdata = 0;
static uint16_t swapAsap = 0;   //flag to indicate that the colors need an update asap

//Interrupt routine.
//Frequency was set in setup(). Called once for every bit of data sent
//In your code, set global Sendmode to 0 to re-send the data to the pixels
//Otherwise it will just send clocks.
void LedOut() {
  // PORTB |= _BV(5);    // port 13 LED for timing debug

  switch(SendMode) {
    case DONE:            //Done..just send clocks with zero data
      if (swapAsap>0) {
        if(!BlankCounter)    //AS SOON AS CURRENT pwm IS DONE. BlankCounter 
      	{
        	BitCount = 0;
        	LedIndex = swapAsap;  //set current led
        	SendMode = HEADER;
	      	swapAsap = 0;
      	}   	
      }
      break;

    case DATA:               //Sending Data
      if ((1 << (15-BitCount)) & pixels[LedIndex]) {
		if (!lastdata) {     // digitalwrites take a long time, avoid if possible
	  		// If not the first bit then output the next bits 
	  		// (Starting with MSB bit 15 down.)
	  		digitalWrite(dataPin, 1);
	  		lastdata = 1;
		}
      } else {
		if (lastdata) {       // digitalwrites take a long time, avoid if possible
	  		digitalWrite(dataPin, 0);
	  		lastdata = 0;
		}
      }
      BitCount++;
      
      if(BitCount == 16)    //Last bit?
      {
        LedIndex++;        //Move to next LED
        if (LedIndex < numLEDs) //Still more leds to go or are we done?
        {
          BitCount=0;      //Start from the fist bit of the next LED
        } else {
	  		// no longer sending data, set the data pin low
	  		digitalWrite(dataPin, 0);
	  		lastdata = 0; // this is a lite optimization
          	SendMode = DONE;  //No more LEDs to go, we are done!
		}
      }
      break;      
    case HEADER:            //Header
      if (BitCount < 32) {
		digitalWrite(dataPin, 0);
		lastdata = 0;
		BitCount++;
		if (BitCount==32) {
	  		SendMode = DATA;      //If this was the last bit of header then move on to data.
	  		LedIndex = 0;
	  		BitCount = 0;
		}
      }
      break;
    case START:            //Start
      if (!BlankCounter)    //AS SOON AS CURRENT pwm IS DONE. BlankCounter 
      {
        BitCount = 0;
        LedIndex = 0;
        SendMode = HEADER; 
      }  
      break;   
  }

  // Clock out data (or clock LEDs)
  digitalWrite(clockPin, HIGH);
  digitalWrite(clockPin, LOW);
  
  //Keep track of where the LEDs are at in their pwm cycle. 
  BlankCounter++;

  // PORTB &= ~_BV(5);   // pin 13 digital output debug
}

//---
LPD6803::LPD6803(uint16_t n, uint8_t dpin, uint8_t cpin) {
  dataPin = dpin;
  clockPin = cpin;
  numLEDs = n;

  pixels = (uint16_t *)malloc(numLEDs);
  for (uint16_t i=0; i< numLEDs; i++) {
    setPixelColor(i, 0, 0, 0);
  }

  SendMode = START;
  BitCount = LedIndex = BlankCounter = 0;
  cpumax = 50;
}

//---
void LPD6803::begin(void) {
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);

  setCPUmax(cpumax);

[COLOR="Lime"]  Timer1.attachInterrupt(LedOut);  // attaches callback() as a timer overflow interrupt
[/COLOR]}

//---
uint16_t LPD6803::numPixels(void) {
  return numLEDs;
}

//---
void LPD6803::setCPUmax(uint8_t m) {
  cpumax = m;

  // each clock out takes 20 microseconds max
  long time = 100;
  time *= 20;   // 20 microseconds per
  time /= m;    // how long between timers
  [COLOR="Cyan"]Timer1.initialize(time);[/COLOR]
}

//---
void LPD6803::show(void) {
  SendMode = START;
}

//---
void LPD6803::doSwapBuffersAsap(uint16_t idx) {
  swapAsap = idx;
}

//---
void LPD6803::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
  uint16_t data;
	
  if (n > numLEDs) return;

  data = g & 0x1F;
  data <<= 5;
  data |= b & 0x1F;
  data <<= 5;
  data |= r & 0x1F;
  data |= 0x8000;
  
  pixels[n] = data;
}

//---
void LPD6803::setPixelColor(uint16_t n, uint16_t c) {
  if (n > numLEDs) return;

  pixels[n] = 0x8000 | c;
}
 
Last edited:




Top