Setting to CRGB::Black is giving random colors

I'm new to all of this, so "is it plugged in" style questions are absolutely welcome, though I do have everything plugged in.

What I'm attempting to accomplish is getting a MIDI input to affect an LED strip output by using an Arduino Uno, but at the moment I'm having problems with just the LED portion.

What I have is a WS2811 Pixel strip that has 3 LEDs per segment. The +/- wires are connected to this plug I had for a set of rope lights, rated for 12V, 700mA. Each set of 3 lights appears to be linked such that they are always all the same color/brightness/etc.

Code can be seen here: Arduino-Testing/MIDI.ino at main · Batophobia/Arduino-Testing · GitHub

Hopefully my poor MS Paint skills can convey it, but the board setup looks like this:
image

I attempted to put the color bands on the resistors to match the way they are plugged in. The 1N914 diode has the black bar facing towards the higher numbers. The 6N138 Optocoupler has the little dot by the f30 slot. MIDI setup stuff was done following this.

Currently, the expected output is for the lights to turn on, all the same color, then half a second later turn off, then half a second later repeat. What is happening is rarely the strand is entirely off, instead often being partially lit, and most of the time it's multiple random colors and not the same each loop.

Any advice on how to at least get it to be the same color each time? I've also tried CRGB instead of CHSV, which didn't work, as well as FastLED.delay, which resulted in rapid flashing of random colors.

OK, how about posting the code here?

If you are not sure how, then read the instructions!

Always a good start. :sunglasses:

If you would have removed the breadboard and used straight lines instead of freehand things would be easier to see

So that does not deal with the midi at all so for now we can not even bother about the circuit for that part either.

I use slightly different values for the midi part (470R & 1K) but that probably works just fine.

Fastled.delay() just calls show() repeatedly until the time has expired. I find it best to avoid it, since it disables interrupts for extended period of time.

From your code

void colorLEDs(int clr){
    for(int i = 0; i < NUM_LEDS; i++) {
      leds[i] = CHSV(clr,255,255);
      FastLED.show();
   }
}

show() should be outside of the loop();

#define COLOR_ORDER RGB

That color order is not very common, most common is GRB or RBG, but of course this not your issue.
The program, although not ideal, should work as expected, so that leaves the ledstrip connections, which you have not shown us details of.
The strip and the arduino should share common GND !

1 Like

Yea, my original draft had more images, but I was limited to 1. This is how the strip connects:

The black wire on the left goes to the wall outlet (12V, 700mA). From the LED, red is 12V, green is data, white is ground.

Sorry, was hoping to make less of a text wall by using a link to GitHub instead. Here's the code: I'm currently using.

//#include <MIDI.h>
#include <FastLED.h>

#define DATA_PIN    11
#define NUM_LEDS    9
#define BRIGHTNESS  255
#define LED_TYPE    WS2811
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];

//MIDI_CREATE_DEFAULT_INSTANCE();

void handleNoteOn(byte channel, byte pitch, byte velocity) {
  //leds[velocity] = CRGB::Red;
  //FastLED.show();
  //FastLED.delay(100);
}

void handleNoteOff(byte channel, byte pitch, byte velocity) {
  //leds[channel] = CRGB::Black;
  //FastLED.show();
  //FastLED.delay(100);
}

void resetLEDS() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(0, 0, 0);
  }
  FastLED.show();
}

void colorLEDs(int clr) {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(clr, 255, 255);
  }
  FastLED.show();
}

void setup() {
  delay( 3000 ); // power-up safety delay
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);

  //MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function
  //MIDI.setHandleNoteOff(handleNoteOff);
  //MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop() {
  //MIDI.read();
  colorLEDs(255);
  delay(500);
  resetLEDS();
  delay(500);
}

For reference, here is a close-up of the LEDs:

So you have no Ground connection between the Arduino & the Ledstrip. That is your issue. Like that the data wire has no reference to GND at the receiving end.
So connect GND to GND and report back (add an actual wire between the strip & the arduino, don't go the long way around ! )

1 Like

That was it, thanks. I've got GND from LED and negative of 12V line going directly into GND slots on the Uno, with the last GND slot going to the board. It seems to be working. Found out coloring goes BRG, and it is working as expected so far. Onto messing with MIDI stuff :smiley:

Midi controlled ledstrip Huh ? Lights to fit the music.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.