Go Down

Topic: Arduino mega 2560, WS2812B troubleshooting, any help welcome! (Read 1 time) previous topic - next topic

Randomkid199

Hey all!

I am trying to get a strip of ws2812B's to infinite loop a rainbow color. (End Result)

I have decided to start small and play around just to get the LED's working, after a few hours of installing drivers and getting my computer to accept the PCB, I tried the on-board LED blink code which worked as expected.

I then tried some neo-pixels & fast LED codes as well as WS2812B codes but none of them seem to be working, I'm guessing it is a hardware setup error as the on-board blink code worked, but I can for the life of me work out what the error is. I have changed the data pins around to check them, I have used an independent power supply to power the strip (I only have 5 used to test until I get it working) connected & disconnected to my PC & now 5 hours of trawling google.

Is there anything I'm missing?

Any help is greatly appreciated!

Tim

Grumpy_Mike

Quote
Is there anything I'm missing?
Yes telling us exactly what you have done. According to the post you have done everything right. So a photograph of your wiring and a schematic would help us try and spot something. Also posting your code would be good.

Randomkid199

Thanks for the reply, I think there is an issue with the Mega 2560 as I switched to my spare Teensey 3.1 & now have the LED's reacting to codes uploaded to it.

I do however now have a slight issue with the code, the LED's are reacting to changed I make in the code regarding the speed, LED amount, timing ect, but I can't seem to get them to rainbow loop across the strip fading/mixing colors rather then stepping them. here is the code:

Code: [Select]
/*  OctoWS2811 Rainbow.ino - Rainbow Shifting Test
    http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
    Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.


  Required Connections
  --------------------
    pin 2:  LED Strip #1    OctoWS2811 drives 8 LED Strips.
    pin 14: LED strip #2    All 8 are the same length.
    pin 7:  LED strip #3
    pin 8:  LED strip #4    A 100 ohm resistor should used
    pin 6:  LED strip #5    between each Teensy pin and the
    pin 20: LED strip #6    wire to the LED strip, to minimize
    pin 21: LED strip #7    high frequency ringining & noise.
    pin 5:  LED strip #8
    pin 15 & 16 - Connect together, but do not use
    pin 4 - Do not use
    pin 3 - Do not use as PWM.  Normal use is ok.
    pin 1 - Output indicating CPU usage, monitor with an oscilloscope,
            logic analyzer or even an LED (brighter = CPU busier)
*/

#include <OctoWS2811.h>

const int ledsPerStrip = 60;

DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];

const int config = WS2811_GRB | WS2811_800kHz;

OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);

int rainbowColors[180];


void setup() {
  pinMode(1, OUTPUT);
  digitalWrite(1, HIGH);
  for (int i=0; i<180; i++) {
    int hue = i * 2;
    int saturation = 100;
    int lightness = 50;
    // pre-compute the 180 rainbow colors
    rainbowColors[i] = makeColor(hue, saturation, lightness);
  }
  digitalWrite(1, LOW);
  leds.begin();
}


void loop() {
  rainbow(10, 2500);
}


// phaseShift is the shift between each row.  phaseShift=0
// causes all rows to show the same colors moving together.
// phaseShift=180 causes each row to be the opposite colors
// as the previous.
//
// cycleTime is the number of milliseconds to shift through
// the entire 360 degrees of the color wheel:
// Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red
//
void rainbow(int phaseShift, int cycleTime)
{
  int color, x, y, offset, wait;

  wait = cycleTime * 1000 / ledsPerStrip;
  for (color=0; color < 180; color++) {
    digitalWrite(1, HIGH);
    for (x=0; x < ledsPerStrip; x++) {
      for (y=0; y < 8; y++) {
        int index = (color + x + y*phaseShift/2) % 180;
        leds.setPixel(x + y*ledsPerStrip, rainbowColors[index]);
      }
    }
    leds.show();
    digitalWrite(1, LOW);
    delayMicroseconds(wait);
  }
}


I have attached the pictures of my *temporary* setup (due to breaking my soldering Iron & only having a 180 ohm resistor rather then a 100ohm.)

Any help with the code or making the rainbow effect would be great!

Thanks Again for your time & help!

Tim

Grumpy_Mike

It might be something with the libraries but I have only used the AdaFruit one and I have seen the code to cope with a Mega in that. Although I have not used one with them.

This is some code that started life as the AdaFruit demo, but I changed it so that it is implemented as a state machine so you can change the pattern any time you like, even part way through a cycle. There is a rainbow fade effect in that.

Code: [Select]

// StrandTest from AdaFruit implemented as a state machine
// pattern change by push button
// By Mike Cook Jan 2016

#define PINforControl   7 // pin connected to the small NeoPixels strip
#define NUMPIXELS1      6 // number of LEDs on second strip

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS1, PINforControl, NEO_GRB + NEO_KHZ800);

unsigned long patternInterval = 20 ; // time between steps in the pattern
unsigned long lastUpdate = 0 ; // for millis() when last update occoured
unsigned long intervals [] = { 20, 20, 50, 100 } ; // speed for each pattern
const byte button = 2; // pin to connect button switch to between pin and ground

void setup() {
  strip.begin(); // This initializes the NeoPixel library.
  wipe(); // wipes the LED buffers
  pinMode(button, INPUT_PULLUP); // change pattern button
}

void loop() {
  static int pattern = 0, lastReading;
  int reading = digitalRead(button);
  if(lastReading == HIGH && reading == LOW){
    pattern++ ; // change pattern number
    if(pattern > 3) pattern = 0; // wrap round if too big
    patternInterval = intervals[pattern]; // set speed for this pattern
    wipe(); // clear out the buffer
    delay(50); // debounce delay
  }
  lastReading = reading; // save for next time

if(millis() - lastUpdate > patternInterval) updatePattern(pattern);
}

void  updatePattern(int pat){ // call the pattern currently being created
  switch(pat) {
    case 0:
        rainbow();
        break;
    case 1:
        rainbowCycle();
        break;
    case 2:
        theaterChaseRainbow();
        break;
    case 3:
         colorWipe(strip.Color(255, 0, 0)); // red
         break;     
  } 
}

void rainbow() { // modified from Adafruit example to make it a state machine
  static uint16_t j=0;
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
     j++;
  if(j >= 256) j=0;
  lastUpdate = millis(); // time for next change to the display
 
}
void rainbowCycle() { // modified from Adafruit example to make it a state machine
  static uint16_t j=0;
    for(int i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
  j++;
  if(j >= 256*5) j=0;
  lastUpdate = millis(); // time for next change to the display
}

void theaterChaseRainbow() { // modified from Adafruit example to make it a state machine
  static int j=0, q = 0;
  static boolean on = true;
  // for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
  //  for (int q=0; q < 3; q++) {
     if(on){
            for (int i=0; i < strip.numPixels(); i=i+3) {
                strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
             }
     }
      else {
           for (int i=0; i < strip.numPixels(); i=i+3) {
               strip.setPixelColor(i+q, 0);        //turn every third pixel off
                 }
      }
     on = !on; // toggel pixelse on or off for next time
      strip.show(); // display
      q++; // update the q variable
      if(q >=3 ){ // if it overflows reset it and update the J variable
        q=0;
        j++;
        if(j >= 256) j = 0;
      }
  lastUpdate = millis(); // time for next change to the display   
}

void colorWipe(uint32_t c) { // modified from Adafruit example to make it a state machine
  static int i =0;
    strip.setPixelColor(i, c);
    strip.show();
  i++;
  if(i >= strip.numPixels()){
    i = 0;
    wipe(); // blank out strip
  }
  lastUpdate = millis(); // time for next change to the display
}


void wipe(){ // clear all LEDs
     for(int i=0;i<strip.numPixels();i++){
       strip.setPixelColor(i, strip.Color(0,0,0));
       }
}

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);
}


While not an Arduino ( although it could have been ) here are some effects I did with these LEDs and some mirrors.:-
https://vimeo.com/156278316

Randomkid199

I tested your script on my mega 2560, but it was giving errors, also the LED's I used have decided to stop working, I think somehow they have blown although they were only given 5V, I have some more on order and will test them as soon as they arrive. Here is the error I have with your script:

Code: [Select]
Arduino: 1.6.11 (Windows 7), TD: 1.30, Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\OctoWS2811\examples\Rainbow\Rainbow.ino:41:24: fatal error: OctoWS2811.h: No such file or directory

 #include <OctoWS2811.h>

                        ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Is there something I didn't copy over?

Grumpy_Mike

Quote
I tested your script on my mega 2560, but it was giving errors,
What sort of errors?
Have you installed the Adafruit_NeoPixel libiary?

As to your code:-
Quote
Is there something I didn't copy over?
It looks like it is failing to find the OctoWS2811.h file, the clue is
Quote
OctoWS2811.h: No such file or directory
This means you haven't installed the OctoWS2811 libiary correctly if at all.

Randomkid199

Quote
What sort of errors?
Have you installed the Adafruit_NeoPixel libiary?
Yes I installed the Neopixel Library.


Quote
This means you haven't installed the OctoWS2811 libiary correctly if at all.
I have installed this library, I tried copying over the .h file to the folder the error navigated to but that still didn't work.

Grumpy_Mike

Quote
I have installed this library,
Then you have not installed it correctly because the compiler can't find it.

Quote
Yes I installed the Neopixel Library.
But what sort of errors. It compiles for me for a Mega, so I don't get errors. Are you confusing errors with it not functioning as you want?

Randomkid199

The error as stated above, I'm going to try again tomorrow with a clean install of IDE & librarys to check.

Grumpy_Mike

Quote
The error as stated above,
I am confused now. Exactly what code gives what error.

Is it the code in reply #3 giving the error in reply #4?
If that is what you think then you are in error. The path of the missing file shows it is in:-

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\OctoWS2811\examples\Rainbow\Rainbow.ino

The code in reply #3 should not be in the examples folder of the OctoWS2811 libiary, and in no way does it call that libiary.

Randomkid199

I managed to fix the 'error' by reinstalling the IDE & Library's, I also have the code fully working with the LED's, I think there was a bad cable between the Digital Pin & data in for the LED's.

Thanks for all your help!
 

Go Up