Advanced Midi questions

Status
Not open for further replies.

j_dunavin

Well-known member
To start off I should say that I have successfully used code from this project to make my own midi controller using the Teensy LC:
http://www.instructables.com/id/Custom-Arduino-MIDI-Controller/

I am planning on building a bigger midi controller and would like to know if i can utilize a few different examples.

The following example shows how to use the 74HC4051 to hook up a lot of buttons and potentiometers:
https://www.pjrc.com/teensy/td_midi.html

If i wanted a physical shift switch, so that I could have the same eight buttons perform different functions, could i run several Enable lines from the 74HC4051's through a switch to move the enable line to a different input? Or would it be possible to simply run a single toggle switch into a dedicated input pin and through code, define weather or not those eight buttons are in condition one or two?
I hope that makes sense, the software i want to control, does not have a shift button to command via midi. I'm hopping that through the Teensy I can use a shift button to change the function of several buttons.

The above example also gives some insight on receiving midi.
The software i am wanting to control can send midi signals back to the controller to run LEDS, like a VU meter for example.
This is further down the wish list, but any examples of how this is done would be nice.
I understand that i would need to define some LED would light via note A for example, then go into the midi scripting of the software and say i want to send out note A to light some LED.

I have also been thinking it would be nice to implement some capacitive touch buttons.
https://www.pjrc.com/teensy/td_libs_CapacitiveSensor.html
I assume it would just be better / easier to wire direct to the Teensy, but would this break out board help at all?
https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial/overview

Now.... can all these things be used together? Or am i asking for some kind of coding nightmare?
 
for the shift element, you can have an independent button that toggles on/off and in code you use this to determine what each of the eight other buttons do. There are a couple of ways. one is to use a push connection switch which latches and is High or Low. you read this value on the pin and then use the if statement to determine what you buttons should do. Or you can use a momentary button and use some latching code.

For momentary, if you have a search for button state change detection you will see some examples. You can then use this to have the same buttons do many things, but with a simple toggle approach you can have two sets of actions for each button. You can use a momentary switch you can use given number of button pushes to create more than two actions per button by scrolling through incremented states by assigning a variable that just counts up one each time the button is pushed to the number of button options you want and then resets to zero.

The midi messages associate with these two states are just set up in your code using the if statement (or case)
 
Awesome, that will open a few things up for me then. Though I think I'll only need two states, and a toggle switch may help me see visually which state I'm in on the fly. I guess an LED would work too... Hum
 
The capacitive touch, what if I wanted many inputs? In there a way to multiplex them like the midi button example?
 
In this example:
https://www.pjrc.com/teensy/td_midi.html

If I also wanted to connect a few rotory encoders, would I run the encoders right into the teensy (interrupt pins) then multiplex the other buttons and potentiometers?
Also, if I wanted to connect a strip on addressable LEDs, I assume I would be able to run that code along side the midi code?

I'm not interested in anything too fancy, I just want to backlight something, but have the ability to change the color with an external switch.
 
yes, it is possible. You can run some ws2811 at the same time as usbmidi and rotary encoders an more besides. I did not use interrupts for my rotary encoders, but stuck with polling in the loop as I was having issues with the port expanders (mcp23s17 - SPI port expander) and I did not have to worry too much about using clocks to poll in the loop. I used ws2811 as these are not SPI addressable leds, as I wanted to reduce the number of SPI peripherals (the port expanders and the lcd are both SPI)

I was using a T3.5, and am now using a T3.6 without trouble. You can see it working here: https://www.youtube.com/watch?v=FGz8AApP5wo
 
again looking here for reference:
https://www.pjrc.com/teensy/td_midi.html

I would like to use the read midi function along side the sending midi notes to light up some led status indicators.
There may be a few indicators, would I need a dedicated output for each LED, or would it be possible to multiplex them, like the inputs can be?
 
Would it be simpler to have a string of addressable LED's ( neopixles for example) And just define which led in the string I want to light?

WS2812 / NeoPixel is much simpler in terms of wiring.

In terms of software, those LEDs require tight timing for their communication. That's not simple at all, but usually you would use a library that does it for you. If you use WS2812Serial, you can control the LEDs without slowing down reception of incoming MIDI messages. WS2812Serial is restricted to only certain pins, and uses more memory than the other libs. The FastLED (with its built in WS2812 driver) and Adafruit_NeoPixel libraries disable interrupts, which delays reception of USB MIDI data and can cause data loss is using regular serial (5 pin DIN) MIDI.
 
good to know!

So, as long as I follow this example: ( with the appropriate pins )
https://www.pjrc.com/non-blocking-ws2812-led-library/

I should be able to use the midi usb example, still using encoders, multiple buttons, potentiometers, etc, while reading midi and lighting up a few leds?

I didn't see the Teensy 3.1 listed on the GitHub page. I assume pin 1 and 5 would both still work?
 
Last edited:
Another option is using Apa102 leds (Adafruit call them DotStar) as they do not require interrupt disabling when using with the FastLED library and they offer a much higher refresh rate.

For VU led meters where you have a long series of Led strips / rings making up all your VU meter elements, a higher refresh rate will give you lower latency in updating the VU meters.
 
Status
Not open for further replies.
Back
Top