MIDI react LED using Arduino. (but im really stuck)

Grumpy_Mike:
So nice if you to let us know at the start, it only makes previous answers useless.

Also mixing addressable LED strips of this type with the WS2812 controller, will not work reliably because when the LEDs are being fed their data the interrupts are turned off which means you could miss incoming MIDI bytes making the whole thing not work.

The only soloution I see is to use the sort of addressable LED strip that needs two outputs, data and clock and then write your own library that does not disable the interrupts when sending the data. The data write process for this types is interruptible. These LEDs are sometimes called dot star.

yes i need two outputs. i understand you now. Can I convert data pin to "data pin and clock pin"?

ozguney:
yes i need two outputs. i understand you now. Can I convert data pin to "data pin and clock pin"?

No, you need a different kind of LED strip.

PieterP:
No, you need a different kind of LED strip.

pffff, im researching about it. i found a multiplex. does it fix my problem?

Again, we cannot read your mind. Multiplexing is a very broad term.

MIDI signals are not coming to LED properly. I just need an arranger for missing Serial in the bytes. I just searching a solution.

whatever. likely I need new Led strips…

// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);

I see this project and these LEDs are including clock pin. Which ones are useful for me?

PieterP:
Would this be a problem all the time? Or only when the UART's RX buffer is full?

No all the time. Interrupts are off so if you don’t get the byte from the UART before the next one arrives you will loose it. It is the interrupts that transfer it from the UART to the buffer.

I see this project and these LEDs are including clock pin. Which ones are useful for me?

You can use any of them but you can’t use that libiary because it disables the interrupts.

Write some code that just has LEDs connected directly to some output pins and forget the libiary at the moment. If that works it will prove that the rest of the system can handle the MIDI data.

I think I found some solutions. How can I integrate to my code? Its seems very difficult. Also If I integrate these codes into my code will my Arduino does not make interrupt anymore?

https://github.com/FastLED/FastLED/wiki/Interrupt-problems

I rewrite my code for FastLED.h

#include <MIDI.h>  // Add Midi Library
#include <FastLED.h>

//define FastLED.h Pin and Number of LEDs
#define DATA_PIN 6
#define NUM_LEDS 88

CRGB leds[NUM_LEDS];

//    strip.setPixelColor(4, 120, 255, 40);
//    strip.setPixelColor(Number of LED, RedDensity, GreenDensity, BlueDensity);
#define RedDensity    150
#define GreenDensity  199
#define BlueDensity   88


//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  MIDI.begin(1); // Initialize the Midi Library on channel 1
  Serial.begin(115200);  // Hairless MIDI speed
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function you want to call when a NOTE ON command
  // is received. In this case it's "MyHandleNoteOn".
  MIDI.setHandleNoteOff(MyHandleNoteOff); // This command tells the Midi Library 
  // to call "MyHandleNoteOff" when a NOTE OFF command is received.
}

void loop() { // Main loop
  MIDI.read(); // Continuously check if Midi data has been received.   
}


// MyHandleNoteOn/Off are the functions that will be called by the Midi Library
// when a MIDI Note message is received.
// It will be passed bytes for Channel, Pitch, and Value
// If it is, it lights up the corresponding LED (LEDs 1 thru 16)
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  leds[pitch-21] = CRGB::Red;
  FastLED.show();
  }

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
  leds[pitch-21] = CRGB::Black;
  FastLED.show();
  }

Do yourself a favor and get a Teensy 3.x, as suggested on the FastLED Wiki.

PieterP:
Do yourself a favor and get a Teensy 3.x, as suggested on the FastLED Wiki.

Does Teensy work with MIDI.h and FastLED.h libraries?

My soloution when using an I2C slave was to make an ATtiny85 system that sent the Neopixel data and I talked to it using a two wire SPI like protocol to send the data to the tiny which could be interrupted.

Grumpy_Mike:
My soloution when using an I2C slave was to make an ATtiny85 system that sent the Neopixel data and I talked to it using a two wire SPI like protocol to send the data to the tiny which could be interrupted.

My english can not suffice your explanation. Did you say make your own processor and send data to there?

ozguney:
Does Teensy work with MIDI.h and FastLED.h libraries?

Even better: it supports MIDI over USB, so no Hairless clutter, just plug it in, and it works. It also supports non-blocking WS2812. Non-Blocking WS2812 LED Library

ozguney:
My english can not suffice your explanation. Did you say make your own processor and send data to there?

This is the circuit I used to send data to a Neopixel strip without disabling the Arduino’s interrupts. If you stick with MIDI on an Arduino Uno this is a solution for you.
ATtiny WS2812 driver.jpg

However:-

Even better: it supports MIDI over USB,

By removing the serial input data and going over to USB it removes the interrupt problem anyway. Yes the USB interface uses interrupts to transfer data but the protocol makes it try again if there is no response.

this code is works perfectly. but i need 88 output :d

#include <MIDI.h>

#define led7 7
#define led6 6
#define led5 5
#define led4 4
#define led3 3

MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode(led7, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led3, OUTPUT);
  MIDI.begin(1);
  Serial.begin(115200);
  MIDI.setHandleNoteOn(MyHandleNoteOn);
  MIDI.setHandleNoteOff(MyHandleNoteOff);
}

void loop() {
  MIDI.read();
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  switch (pitch) {
    case 60:
      digitalWrite(led7, HIGH);
        break;
    case 62:
      digitalWrite(led6, HIGH);
        break;
    case 64:
      digitalWrite(led5, HIGH);
        break;
    case 65:
      digitalWrite(led4, HIGH);
        break;
    case 67:
      digitalWrite(led3, HIGH);
        break;
  }
}

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
  switch (pitch) {
    case 60:
      digitalWrite(led7, LOW);
        break;
    case 62:
      digitalWrite(led6, LOW);
        break;
    case 64:
      digitalWrite(led5, LOW);
        break;
    case 65:
      digitalWrite(led4, LOW);
        break;
    case 67:
      digitalWrite(led3, LOW);
        break;
  }
}

I think you should re-read this thread.

PieterP:
I think you should re-read this thread.

because your shift register project is solving my pin problem am i rite?

Does <Control_Surface.h> compatible with <FastLED.h> or <Adafruit_Neopixel.h> ?

because your shift register project is solving my pin problem am i rite?

No because the thread describes your problem and also describes the many solutions open to you.

ozguney:
Does <Control_Surface.h> compatible with <FastLED.h> or <Adafruit_Neopixel.h> ?

You cannot use FastLED on an UNO if you need MIDI communication.
Not using WS2812 is one solution. Not using an UNO is another.

I’d recommend using a different microcontroller, like the Teensy, because it supports MIDI over USB and it can drive WS2812 strips without losing MIDI data.

Another solution would be to use normal LEDs instead of the WS2812, or addressable LEDs that don’t have a tight timing. Shift registers are one of the possibilities to drive many LEDs with very few microcontroller pins.
You can easily drive 88 LEDs using 11 8-bit shift registers and only 3 pins.