Addressable LEDs help

For this off-season, my team is using two LED strips on opposite sides of the robot connected together to one port. When we try to activate the LEDs, it only activates the first LED that we activate (using the following command).

public void setLEDColor(Color color, int index) {
        LEDStripConstants.LED_BUFFER.setLED(index + indexOffset, color);
        LED.setData(LEDStripConstants.LED_BUFFER);
    }

When I run this command twice with a different index, it only turns on the first LED that I tried to set, but it runs through both commands. When I use the following command, it turns on all the LEDs, but if I run it twice, it only turns on the first LEDs that I’m trying to set.

public void setLEDColors(Color color, int startIndex, int endIndex) {
        for (int i = 0; i < endIndex - startIndex; i++) {
            LEDStripConstants.LED_BUFFER.setLED(startIndex + indexOffset + i, color);
        }
        LED.setData(LEDStripConstants.LED_BUFFER);
    }
1 Like

Splitting LED strips from the same port can cause some weird issues with signal reflections, especially if the wires leading from the data port are not the same length. I would recommend turning your two strips into one strip that’s double the length. Alternatively, place 1 led super close to the rio and split the strip after the 1st LED (the WS2812B regenerates a much cleaner signal that what arduinos/rios produce).

So you’re saying it’s probably not a code problem? Additionally, can you elaborate on your second solution? I’m not 100% confident with my electronics capabilities

what happens when you do something like:

for(int i = 0; i < 10; i++){
setLEDColor(red, i);
}

Can you be more specific on that? You can’t put two leds in one port, you connect the two leds stripes in series and they would become one stripe with double the length. I know this is a bit confusing but it’s how it works.

1 Like

It would just make the first LED red

Two LED strips connected to each other in series and then into a port. We are using them in the code as two different led strips

You can definitely connect 2 data ports of ws2812 strips to the same IO pin on an Arduino/Rio and it will mirror the strips. But you can have some strange side effects.

We don’t want to mirror them though. Are there any other options? What did you mean before by connecting a single LED?

If you connect them in series, you should treat them as one LED stripe with 2x the original length. The stripe connected to your robotRIO can be controlled normally. But for the stripe connected to that stripe, you would have to map the address from i to i+n where n is the length.

Sorry, I thought you wanted to mirror. Youll have to do like Catrix said and connect the end of one strip to the beginning of the other.

For argument’s sake, if they were connected properly (I’m not sure), if it still wasn’t working do you have any idea what could be wrong?

Another thing I forgot to mention, it works fine in the sim

This is how we currently have it in the code, so I’m led to believe that it is an electronics problem

addressible led strips are usually directional, its possible you have it plugged in backwards. try looking for an indicator of direction on the strip (the leds our team uses has little arrows on them), or try lookimg at the user manual for your leds

It’s not plugged in backwards

Can you post a link to your full repo (or a full sample code project)?

I’m happy to run it on the Rio and ARGBs that I have here (or someone on CD might be able to spot the problem from the full code that isn’t visible in the snippet).

Well, I can tell you it’s almost certainly code and not electrical.

I’m still working on figuring out what it actually is, but it’s behaving very strangely (and similar to your report) on my setup here as well.

Few things that should get you unstuck:

  1. Move the setData call on line 78 out of the loop (down past the close-brace).
  2. Add a setData call to the end of staticColor (line 71-and-a-half).
  3. Change the <= to < on lines 70 and 75 (and, IMO, not on 101 but then you need to be cautious about how you compute end index).

Edit to add:
Actually, that’s still not quite enough. (It was working while I tested with the rainbow and blink, but not with the getStaticColorCommand calls.)

Hopefully, that got you to at least “it’s in the code” (because Rainbow and Blink work), but I have to do some day job now. :wink: