Go Down

Topic: ws2812b only working on strand test not as a pixel stick  (Read 527 times) previous topic - next topic

buckrussel

I got a pixel stick which just got upgraded from 30 to 61 LEDs which worked fine till I change the lights over but the strange bit is the code I used for strand test on the new leds to test the line is the same as the one used to test the old one then when I put the new code in which still doesn't change since the old leds the LEDs are ws2812b and so were the old ones, I get nothing from the led the wiring all good I made sure of that even shorten the length of pow and gnd that still didn't work so I keep coming back to the code please help me figure what's going on
here's the code I used i hope the problem there

or could the problem be that i have to use a 470ohm restior on the data line when using this code instead of the strand test i will put both code in
Code: [Select]

#include <Adafruit_NeoPixel.h>

// Neopixel data pin
#define PIN 6
// SD card CS pin
#define SDPin 4


// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

// * SD card attached as follows:
// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

#include <SPI.h>
#include <SD.h>

// Neopixel data pin
#define PIN 6
// SD card CS pin
#define SDPin 4

int buttonPin = 2;
bool playAnimation = true;
int buttonState = 0;
int file_position = 0;
int m_NumberOfFiles = 0;
bool runAnimation = true;
String m_FileNames[10];
File root;
File dataFile;
String m_CurrentFilename = "";

int number_of_leds = 60;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(number_of_leds, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
 Serial.begin(115200);
 pinMode(buttonPin, INPUT);
 pinMode(13, OUTPUT);
 pinMode(5, OUTPUT);
 digitalWrite(5,HIGH);
 strip.begin();
 strip.show();
 setupSDcard();
 delay(100);
}

void loop() {
  if (digitalRead(buttonPin) == HIGH) {
     digitalWrite(13,HIGH);
     file_position++;
     Serial.println(file_position);
     delay(100);
     digitalWrite(13,LOW);
   }
  delay(500);
   Serial.print("Sending file");
   if ( file_position >= m_NumberOfFiles) {
    file_position = 0;
   }
   SendFile(m_FileNames[file_position]);
   ClearStrip();

}


void setupSDcard() {
 pinMode(SDPin, OUTPUT);

 while (!SD.begin(SDPin)) {
   Serial.println("SD init failed!");
   delay(500);
 }
 Serial.println("SD init done");
 delay(1000);
 root = SD.open("/");
 Serial.println("Scanning files");
 delay(500);
 GetFileNamesFromSD(root);
}

// This function lists files inside the SD card
void GetFileNamesFromSD(File dir) {
 int fileCount = 0;
 String CurrentFilename = "";
 while(1) {
   File entry =  dir.openNextFile();
   if (! entry) {
     // no more files
     m_NumberOfFiles = fileCount;
     Serial.println("total files");
     Serial.println(fileCount);
   entry.close();
     break;
   }
   else {
       CurrentFilename = entry.name();
       if (CurrentFilename.endsWith(".TXT")) { //only txt files
         if(CurrentFilename.startsWith("_")){      // mac sidecar files start with _ and should not be included, may be on card if written from Mac
         }else{
           m_FileNames[fileCount] = entry.name();
           fileCount++;
         }
       }
   }
   entry.close();
 }
}

// This function blinks the top led twice and starts the animation
void SendFile(String Filename) {
 char temp[14];
 runAnimation = true;
 Filename.toCharArray(temp,14);
 Serial.println(Filename);
 dataFile = SD.open(temp);
 // if the file is available send it to the LED's
 if (dataFile) {
   int i = 0;
   int red, green, blue;
   strip.setPixelColor(1,255,255,255);
   strip.show();
   delay(500);
   strip.setPixelColor(1,0,0,0);
   strip.show();
   delay(500);
   strip.setPixelColor(1,255,255,255);
   strip.show();
   delay(500);
   strip.setPixelColor(1,0,0,0);
   strip.show();
   delay(2000);
   while(dataFile.available() && runAnimation){

     if (digitalRead(buttonPin) == HIGH) {
       runAnimation = false;
       break;
       delay(100);
     }
     if (i == (number_of_leds)) {
       i=0;
       strip.show();
       delay(120);
       }
     red = dataFile.parseInt();
     green = dataFile.parseInt();
     blue = dataFile.parseInt();
     strip.setPixelColor(i, red, green, blue);
     i++;
   }
   Serial.print("closing file");
   dataFile.close();
 } else {
   Serial.print("  Error reading ");
   setupSDcard();
   return;
   }
 }

// Turn all LED off on the pixelstick
void ClearStrip() {
 int x;
 for(x=0;x<number_of_leds;x++) {
   strip.setPixelColor(x, 0);
 }
 strip.show();
}



buckrussel

and the strand test code sorry it in a new post

Code: [Select]
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code


  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

// 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) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Grumpy_Mike

Quote
could the problem be that i have to use a 470ohm restior on the data line when using this code instead of the strand test i will put both code in
No.

What is a pixel stick?

buckrussel

a pixel stick reads a image from micro sd card coverts into colour to diplay on the leds strip then you use a camera to capture the image been displayed in led pixels best way i can explain apart from look a youtube and google to understand it more

Paul__B


Grumpy_Mike

Like this?

https://vimeo.com/46172052
Like I first did in 1989?

Well the WS2812b is a poor LED to use for this because the PWM rate is so slow that you don't get very good results. The dot star ones are better because they have a faster PWM rate.

So the explanation is rather hard to follow. This might be because of the lack of sentences in the explanation.

A bit like the "yer but, no but" character Vicky Pollard in Little Brittan. https://www.youtube.com/watch?v=zExc6SK4kpA

So you might want to try again, or wait for some one to come along that can read technical stuff without breathing.

buckrussel

yeah pretty much like that amazing job on it BTW and are the dot star ones RGB addressable i might look into them and i think i got the code to work now look like some parts weren't declared properly also change the driver used and set the number on leds

changed this part from false to true

Code: [Select]
#include <SPI.h>
#include <SD.h>

// Neopixel data pin
#define PIN 6
// SD card CS pin
#define SDPin 4

int buttonPin = 2;
bool playAnimation = true;
int buttonState = 0;
int file_position = 0;
int m_NumberOfFiles = 0;
bool runAnimation = true;
String m_FileNames[10];
File root;
File dataFile;
String m_CurrentFilename = "";

int number_of_leds = 60;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60,6, NEO_RGB + NEO_KHZ800);




// This function blinks the top led twice and starts the animation
Code: [Select]
void SendFile(String Filename) {
 char temp[14];
 runAnimation = true;
 Filename.toCharArray(temp,14);
 Serial.println(Filename);
 dataFile = SD.open(temp);
 // if the file is available send it to the LED's
 if (dataFile) {
   int i = 0;
   int red, green, blue;
   strip.setPixelColor(1,255,255,255);
   strip.show();
   delay(500);
   strip.setPixelColor(1,0,0,0);
   strip.show();
   delay(500);
   strip.setPixelColor(1,255,255,255);
   strip.show();
   delay(500);
   strip.setPixelColor(1,0,0,0);
   strip.show();
   delay(2000);
   while(dataFile.available() && runAnimation){

     if (digitalRead(buttonPin) == HIGH) {
       runAnimation = true;
       break;
       delay(100);
     }
     if (i == (60)) {
       i=0;
       strip.show();
       delay(120);
       }
     red = dataFile.parseInt();
     green = dataFile.parseInt();
     blue = dataFile.parseInt();
     strip.setPixelColor(i, red, green, blue);
     i++;
   }
   Serial.print("closing file");
   dataFile.close();
 } else {
   Serial.print("  Error reading ");
   setupSDcard();
   return;
   }
 }

// Turn all LED off on the pixelstick
void ClearStrip() {
 int x;
 for(x=0;x<number_of_leds;x++) {
   strip.setPixelColor(x, 0);
 }
 strip.show();
}

Go Up