Go Down

Topic: MIDI react LED using Arduino. (but im really stuck) (Read 1 time) previous topic - next topic

ozguney

Take a look at the code I posted, understand it, and change your code to get rid of the gigantic switches.
I try to analyze the code you wrote, but I have some confusion,

I use WS2812b its directly connect to Arduino via DataPin and there is no clockpin and latch pin. I dont have any components like shield or etc.
I use Arduino Uno and when I try to load the arduino i get "exit status 1 Error compiling for board Arduino/Genuino Uno." error. I think I got this error because I dont have 74HC595.

Thank you PieterP and Mike for attend to me :) I started programming arduino for 2 weeks. You guys gave me a lot of things more than 2 weeks.

ozguney

The source of the problem is timing. When I press more then one note at the same time(i mean chord) Arduino lighting only 1 LED.

ozguney

Code: [Select]
#include <MIDI.h>  // Add Midi Library
#include <Adafruit_NeoPixel.h> // Add Led Library

//define NeoPixel Pin and Number of LEDs
#define PIN 6
#define NUM_LEDS 88

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

//create a NeoPixel strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

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

void setup() {
 
  strip.begin(); // start the strip and blank it out
  strip.show();
 
  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
// It checks if the MIDI Note Pitch is within the Note Range 36 (C1) to 51 (D#2)
// If it is, it lights up the corresponding LED (LEDs 1 thru 16)
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
    strip.setPixelColor(pitch-20, RedDensity, GreenDensity, BlueDensity);
    strip.show();

  }

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
      strip.setPixelColor(pitch-20, 0, 0, 0);
      strip.show();
  }


I really shortened the code. But its still stucking when i press chords.


i tried that,

Synthesia output is connected to HairlessMIDI's input and when synthesia press chord(working too    symmetrical) only one Led is lighting.

PieterP

What if pitch is less than 20 or greater than 107?

Do all the MIDI notes of the chord show up in the Hairless log? You might be missing notes because the Neopixel library turns off interrupts, as Mike predicted.

ozguney

#19
Jul 14, 2018, 05:03 pm Last Edit: Jul 14, 2018, 05:04 pm by ozguney
What if pitch is less than 20 or greater than 107?

Do all the MIDI notes of the chord show up in the Hairless log? You might be missing notes because the Neopixel library turns off interrupts, as Mike predicted.
HairlessMIDI "Serial in" problem.

ozguney

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"?

PieterP

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.

ozguney

No, you need a different kind of LED strip.
pffff, im researching about it. i found a multiplex. does it fix my problem?

PieterP

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

ozguney

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?

Grumpy_Mike

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.

Grumpy_Mike

Quote
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.

ozguney

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

http://www.instructables.com/id/Arduino-Timer-Interrupts/


I rewrite my code for FastLED.h

Code: [Select]
#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();
  }



PieterP

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

ozguney

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?

Go Up