Go Down

Topic: [neopixel] Leds mismatch [solved] (Read 272 times) previous topic - next topic

pfeuh

Apr 07, 2019, 06:46 am Last Edit: Apr 09, 2019, 02:56 pm by pfeuh
Hello,

I have a working code for a strip of neopixel leds. I've just got some new strips of 8 leds from Sparkfun, they don't work as expected: Only 6 firsts of a strip shine. It seems that the second led use a byte of the first, the third one use 2 bytes of the second one and so on... As a result, the 2 last leds don't shine... Did I miss something?

<edit2>
For your information, I've tried several sketches from the web, they all have the same problem... I guess about a hardware problem or a bad reference or something like that.
<edit2>


<edit>
Code: [Select]

#include "neo8Leds.h"

#define LEDS_PIN A0
#define LED_STATE_DURATION 300

NEO8_LEDS leds = NEO8_LEDS(LEDS_PIN);

byte ledsShadow = 0;

void toggle(byte led_num)
{
    ledsShadow ^= 1 << led_num;
    if(ledsShadow & (1 << led_num))
        leds.switchOn(led_num);
    else
        leds.switchOff(led_num);
}

void setup()
{
    leds.begin();
    Serial.begin(9600);
    Serial.println(F("Type [1..8] to toggle a led"));
}

void loop()
{
    if(Serial.available())
    {
        byte incoming_char = Serial.read();
        switch(incoming_char)
        {
            case '0':
                leds.sleep();
                ledsShadow = 0;
                break;
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
                toggle(incoming_char - '1');
                break;
            default:
                break;
        }
    }
}


Code: [Select]
#ifndef neo8Leds_h
#define neo8Leds_h

#include <Adafruit_NeoPixel.h>
#include <Arduino.h>

#define NEO8_LEDS_NB_LEDS 8

class NEO8_LEDS
{
    public:
        NEO8_LEDS(int pin_num);
        void begin();
        void sequencer();
        void switchOff(byte led_num);
        void switchOn(byte led_num);
        void configColorOff(byte led_num, byte red, byte green, byte blue);
        void configColorOn(byte led_num, byte red, byte green, byte blue);
        void sleep();

    //~ private:
        int pinNum;
        byte onRed[NEO8_LEDS_NB_LEDS];
        byte onGreen[NEO8_LEDS_NB_LEDS];
        byte onBlue[NEO8_LEDS_NB_LEDS];
        byte offRed[NEO8_LEDS_NB_LEDS];
        byte offGreen[NEO8_LEDS_NB_LEDS];
        byte offBlue[NEO8_LEDS_NB_LEDS];
        byte state;
        byte previousState;
        Adafruit_NeoPixel gateway;

};

#endif


Code: [Select]

#include "neo8Leds.h"

/*******************/
/* Private methods */
/*******************/


/******************/
/* Public methods */
/******************/

NEO8_LEDS::NEO8_LEDS(int pin_num)
{
    pinNum = pin_num;
}

void NEO8_LEDS::sleep()
{
    for(byte led_num=0; led_num < NEO8_LEDS_NB_LEDS; led_num++)
        gateway.setPixelColor(led_num, 0, 0, 0);
gateway.show();
}

void NEO8_LEDS::begin()
{
    state = 0;
    previousState = 0;
    //~ pinMode(pinNum, OUTPUT);
   
    //~ memset(onRed, 64, NEO8_LEDS_NB_LEDS);
    //~ memset(onGreen, 0, NEO8_LEDS_NB_LEDS);
    //~ memset(onBlue, 0, NEO8_LEDS_NB_LEDS);
    //~ memset(offRed, 0, NEO8_LEDS_NB_LEDS);
    //~ memset(offGreen, 0, NEO8_LEDS_NB_LEDS);
    //~ memset(offBlue, 0, NEO8_LEDS_NB_LEDS);
    for(byte x=0; x < NEO8_LEDS_NB_LEDS; x++)
    {
        onRed[x] = 64;
        onGreen[x] = 0;
        onBlue[x] = 0;
        offRed[x] = 0;
        offGreen[x] = 0;
        offBlue[x] = 0;
    }
    //~ gateway = Adafruit_NeoPixel(NEO8_LEDS_NB_LEDS, pinNum, NEO_GRB + NEO_KHZ800);
    //~ gateway = Adafruit_NeoPixel(NEO8_LEDS_NB_LEDS, pinNum, NEO_RGBW + NEO_KHZ800);
    gateway = Adafruit_NeoPixel(NEO8_LEDS_NB_LEDS, pinNum, NEO_RGB + NEO_KHZ800);
gateway.begin();
gateway.show();
}

void NEO8_LEDS::sequencer()
{
}

void NEO8_LEDS::switchOff(byte led_num)
{
    gateway.setPixelColor(led_num, onRed[led_num], onGreen[led_num], onBlue[led_num]);
    //~ gateway.setPixelColor(led_num, (long)(((long)offRed[led_num]<<16)| ((long)offGreen[led_num]<<8) | (long)offBlue[led_num]));
    gateway.show();
    Serial.print(F("led "));
    Serial.print(led_num + 1);
    Serial.println(F(" off"));
}

void NEO8_LEDS::switchOn(byte led_num)
{
    gateway.setPixelColor(led_num, offRed[led_num], offGreen[led_num], offBlue[led_num]);
    //~ gateway.setPixelColor(led_num, (long)(((long)onRed[led_num]<<16)| ((long)onGreen[led_num]<<8) | (long)onBlue[led_num]));
    gateway.show();
    Serial.print(F("led "));
    Serial.print(led_num + 1);
    Serial.println(F(" on"));
}

void NEO8_LEDS::configColorOff(byte led_num, byte red, byte green, byte blue)
{
    offRed[led_num] = red;
    offGreen[led_num] = green;
    offBlue[led_num] = blue;
}

void NEO8_LEDS::configColorOn(byte led_num, byte red, byte green, byte blue)
{
    onRed[led_num] = red;
    onGreen[led_num] = green;
    onBlue[led_num] = blue;
}


</edit>

Regards,

Pfeuh

Paul__B


PaulRB

Sounds like your original strip was RGB and your new strips are RGBW.

Paul__B

Yes, how to post code.
Which is strange, as in your first post some weeks ago, you understood exactly how to post both code and images without a problem.

I think PaulRB has solved your current problem - not sure whether you eventually figured out the previous one; I can't help as I have never used MIDI.  :smiley-roll:

pfeuh

#4
Apr 08, 2019, 06:01 pm Last Edit: Apr 08, 2019, 07:52 pm by pfeuh
Hello,

Sounds like your original strip was RGB and your new strips are RGBW.
I've tried these inits:

gateway = Adafruit_NeoPixel(NEO8_LEDS_NB_LEDS, pinNum, NEO_GRB + NEO_KHZ800);
gateway = Adafruit_NeoPixel(NEO8_LEDS_NB_LEDS, pinNum, NEO_RGB + NEO_KHZ800);
gateway = Adafruit_NeoPixel(NEO8_LEDS_NB_LEDS, pinNum, NEO_RGBW + NEO_KHZ800);

Behavior is different with NEO_RGBW, specially that 2 first leds shine after gateway.show(), which is strange, but the 3 inits works with 6 leds instead of 8.

Which is strange, as in your first post some weeks ago, you understood exactly how to post both code and images without a problem.
You're right, but the main thing in my first post was a picture, not a code. By the way, if it was well posted, there was no answer. This one is not well posted, but I have answers... Life goes on.



Paul__B

Well, can't see anything obvious in the code which I can now examine.

Next questions are:
  • Have you successfully used any other NeoPixel strip?
  • What Arduino are you using?

Rather abstruse version of numLeds.

pfeuh

I have successfully used a ring of 12 leds.

I use an Arduino Uno. Tested on pins D2, D6 and A0, for the same result. Also tested 400khz, but even worse.

Here is the reference got from the order:

NeoPixel Stick 8 x WS2812 LED strip 5050 RGBW Natural - Arduino Trinket 8 x 5050 RGBW LEDs - Natural White - ~4500K

Paul__B

Well, if you knew for a start they are RGBW, there is no point in trying any initialisation that does not specify RGBW.

Beyond that I don't know.

pfeuh

#8
Apr 09, 2019, 02:52 pm Last Edit: Apr 09, 2019, 05:04 pm by pfeuh
After some investigations, it is close to work. I use this init:

Adafruit_NeoPixel(NB_LEDS, PIN_NUM, NEO_RGBW + NEO_KHZ800)

But... i've seen in several samples on the web this way of handling color:

setPixelColor(led_num, red, green, blue)

These particular strips I've got swap green an red! I have to call setPixelColor like this:

setPixelColor(led_num, green, red, blue)

By the way, you can add a fifth parameter, white, like this:

setPixelColor(led_num, green, red, blue, white)

in my opinion, class Adafruit_NeoPixel should detect this red-green swaping and manage it. Or perhap it is like this for all kinds of strip? I haven't enough experience to answer.

PaulRB

#9
Apr 09, 2019, 05:28 pm Last Edit: Apr 09, 2019, 05:32 pm by PaulRB
Did you try "NEO_GRBW"?

The is no way for the class to know if green and red are swapped, because there is no feedback from the strip. You have to tell the class what order to send colour data.

pfeuh

No, it's my mistake... Because with all the sketches I've seen, I didn't found this one, which is not often used, I presume.

I just had a look at Adafruit_NeoPixel.h, all cases are implemented! Thanks a lot, it makes my day!

Go Up