simple midi contoller

Status
Not open for further replies.

eross

Member
I'm building a very basic midi controller. It is 3 faders, 3 pots, and 3 arcade buttons. is there a code sketch floating around here i can copy and paste, and just modify the input numbers? also, how can i program the 3 arcade buttons to send out specific midi notes. like C, ....A# ....F.... etc? thanks
 
If no one else points to an existing good example I can write a very basic one with you...

I've been wanting to try the newly available responsiveAnalogRead library in a MIDI controller to see if it eliminates potentiometer noise issues which tend to complicate beginner MIDI controller projects.

how can i program the 3 arcade buttons to send out specific midi notes. like C, ....A# ....F.... etc? thanks
https://www.pjrc.com/teensy/td_midi.html

The code under 'Transmit example' does exactly this...
 
I'd love to include a few more examples in File > Examples > Teensy > USB_MIDI, if you're willing to contribute something showing a simple and perhaps a more advanced use of ResponsiveAnalogRead.
 
if i do this one (http://www.instructables.com/id/Arca...DI-Controller/). it with work with teensy? ...
Teensy usbMIDI works without device drivers or tricky workarounds and has for a very long time...

Read the opening paragraph from this page: https://www.pjrc.com/teensy/td_midi.html

The hardware sections on that project would be exactly the same with just some pin-out adjustments for where the comparable pins are on whichever Teensy you use.

I have not reviewed the code in its entirety but it clearly is meant to allow the code to work with Teensy as well as with stock Arduino boards by using the usbMIDI calls when the Teensy is detected by the #if/#elif section.

This could be expanded to match other Teensy boards but since the usbMIDI calls work on any Teensy it may be enough to just define it as TEENSY_2 (with no '#if...') and be done with it...

But this code is massively more complex than what is needed for a Teensy only solution.

Also what appears to me to be a naive stabilization method is used where the extra resolution of the analog-to-digital-converter (ADC) is discarded instead of being utilized.

Something using conventional dead-band hysteresis or the new ResponsiveAnalogRead library should be superior and there is altogether too much stuff in there that has no purpose in a Teensy usbMIDI controller.
 
Code:
 #include <ResponsiveAnalogRead.h>

[COLOR="#FF0000"]// define the pin you want to use[/COLOR]
const int ANALOG_PIN = A0;
[COLOR="#FF0000"]// variable to store MIDI data byte (sometimes called D2 where D1 is the note or cc)[/COLOR]
byte d2;
[COLOR="#FF0000"]//variable to store a lagged value for d2 for comparison - updated when changed[/COLOR]
byte d2L;
[COLOR="#FF0000"]// default values only for now![/COLOR]
ResponsiveAnalogRead analog(ANALOG_PIN);


void setup() {
[COLOR="#FF0000"]  // begin serial so we can see analog read values through the serial monitor[/COLOR]
  Serial.begin(9600);
}

void loop() {
[COLOR="#FF0000"]  // update the ResponsiveAnalogRead object every loop[/COLOR]
  analog.update();

[COLOR="#FF0000"]  // if changed at 10 bit level[/COLOR]
  if(analog.hasChanged()) {
    d2 = analog.getValue()>>3; [COLOR="#FF0000"]// get value and bit shift 10 to 7 bits.[/COLOR].. 
[COLOR="#FF0000"]    // ...and if changed enough to warrant a new MIDI value[/COLOR]
    if (d2 != d2L){
      d2L = d2;
      Serial.println(d2);
    }
  }

}
Put this together starting with the example code on the gitHUB page.... only took a few minutes

It outputs a seven bit number (as used in single 'byte' MIDI messages).

I'm running it on a mini-breadboard with a poorly connected pot and between the algorithm's effect and my dropping 3 bits the thing is rock solid... you need four bits of noise and for long enough to break the sleep mode before the thing moves again... should work lovely with my expression pedals (which have long cables attached and several point-sources for noise including scratchy wiper connections).

Just need to put usbMIDI.sendControlChange(CC, d2, ch) in there and it's a one-pot controller...


Should be no problem to extend to N pots < M analog pins and then put some de-bounced buttons in there too...
 
Last edited:
having trouble. i have a teensy 3.5.i just got it hooked up. i selected usb midi from the arduinio tools. and wired1 analog, and one digital input. i loaded the code.
http://djtechtools.com/2015/08/25/how-to-make-your-own-diy-midi-controller
when i do. My DAW (abelton live) see that there is midi coming in, but it make no sense and when i click a knob within abelton to midi learn . it has a constant uncontrollable midi signal coming in ( see videohttps://www.dropbox.com/s/ibzaxinca1d24vk/teensy3.5%20problems.MOV?dl=0
what can i do to fix this? or is my board junk?
 
Last edited:
That code needs to be altered to work on newer Teensies... but I don't think it's worth it.

...stay tuned
 
...it also occurs to me you may have left analog pins floating unconnected to a stable voltage that are still read by your code....

If you hook up only one pot you can't have code looking for six...

If you do garbage midi results...
 
ok,thanks for the tips. do you have any suggestions on where I can find a simple code?
All I need is for 3 momentary-on buttons, 3linear faders, and 3 rotary potentiometers. for a 3.5 teensy. I think if i saw this simple code, I could see start understanding better how the code is working and the bare minimum of what needs to be there for a simple controller like this. thanks again for all your help.
 
If you have a look at the code I posted you'll find its most of the way there...

The biggest problem on an analog-based MIDI controller project is getting a stable data signal and limiting midi messages appropriately.

ResponsiveAnalogRead is only recently available for Teensy so the are no beginner examples on how to use it ...but it's so simple I got it working in the sketch above in minutes.... but I didn't post a midi version... just a serial monitor test.

From here the rest should be easy... but turning it into a tutorial so you can learn how I got there will take a bit of time.
 
Last edited:
I tried that code you posted last night, but it had an error, i can remember exactly but it showed an error it highlighted it in red ResponseAnologRead. is that because it is looking for a serial out? where can i see more information on that response analog read. you say it is easy to setup?
 
I just noticed you are looking at a different tutorial than in you earlier posts... that one is Teensy specific and looks like it gets you to alter included example code.... you should post the code as you have congigured it (and with hardware notes or photo) if you want help with that... perhaps as a new thread in the support forum.

EDIT - I guess it's not from the loaded example files but one they guy 'wrote' himself (I see my lag variables in there from my changes to the Paul Cunningham code of yesteryear ...it's also missing the 'ignore incoming midi' handler)

Code:
  // MIDI Controllers should discard incoming MIDI messages.
  while (usbMIDI.read()) {
    // ignore incoming messages
  }

The code also assumes you will read analog inputs from A0 to A5 (in your case of six inputs).

If you need to read an arbitrary list of analog inputs you would need an array to store them.

Do you want help with this code or can you wait for me to write a new one with the ResponsiveAnalogRead?
 
Last edited:
I tried that code you posted last night, but it had an error, i can remember exactly but it showed an error it highlighted it in red ResponseAnologRead. is that because it is looking for a serial out? where can i see more information on that response analog read. you say it is easy to setup?
You need a very recent Teensyduino install (=>1.32)
 
Last edited:
lol now i'm kinda confused. where is the serviceable sketch? so if i install teensyduino version 1.32 the code you loaded should work? is that what your saying? sorry I'm very new to this coding stuff, i feel like i am making this harder
than it has to be hahaha
 
your saying you can do a ResponsiveAnalogRead for my setup? yeah that would be awesome. yes thank you. in the mean time, maybe i'll try to figure out a code for one digital pin input.
 
Yeah.... sorry for the confusion... I misread your posts twice...
The first example (Arduino based with T2.x added) is not ideal...
The second one is better but also has problems.

I could help you get the second one working... I'm not sure why it's not (assuming you set the number of analog inputs to 1 if you only had one pot connected).

NB: That sketch also requires the analog pins be used in order A0, A1, A2...

If you're not in too big a hurry I can definitely get you running with the ResponsiveAnalogRead for six-pots and BOUNCE with 3 buttons.

But definitely do some learning of basics on your own...
https://www.pjrc.com/teensy/tutorial3.html
https://www.pjrc.com/teensy/tutorial4.html
https://www.pjrc.com/teensy/td_digital.html
https://www.pjrc.com/teensy/td_libs_Bounce.html
 
Last edited:
yeah definatly i'm ready to get running with that ResponsiveAnalogRead code for 6 pots and 3 buttons. i'd really appreciate it. keep me up to date.
which second one are you talking about? I will set the analog inputs to one, and
I'll check the pin order.
 
ok, i've had a tiny crumb of success. i made sure i put the wires on the correct pins, and just looked through the code, and anywhere i saw that looked like it referred the number of analog inputs, I changed to 1 and it seems to be working with 1 linear pot. but the push button switch does nothing. Gonna try to get some time when the kids are asleep, and try to deconstruct the code and see if I can figure out anymore. i'm starting to get excited about it now. ! thanks for the help so far, and keep me up to date on that ResponsiveAnalogRead
 
adding buttons should be (relatively) easy...

Is your switch connected to ground on one side and pin 0 (next to the GND pin) on the other.

Bounce uses active-LOW wiring where the pull to ground is seen to be the active state. If you have it go Vcc or 3.3v it won't change state as it was already pulled high by the internal pull up which that code uses.

(Read the digital IO primer)

It should work if you have it connected to any of the first 3 digital pins as the code is set up for 3 bounce objects.
 
i have the Momentary on switch hooked to ground and pin 1. do i need to modify the code to high or low ?
 
also. is there any ios apps that i can edit code on my phone, and compile it, and email the saved sketch to myself and open it up on my computer?
 
i have the Momentary on switch hooked to ground and pin 1. do i need to modify the code to high or low ?
That should work... not sure why it doesn't...

Meantime... this works for me on the analog side:
Code:
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>

const int A_PINS = 6; // number of Analog PINS
// define the pins you want to use and the CC ID numbers on which to send them..
const int ANALOG_PINS[A_PINS] = {A0,A1,A2,A3,A4,A5};
const int CCID[A_PINS] = {21,22,23,24,25,26};

// a data array and a lagged copy to tell when MIDI changes are required
byte data[A_PINS];
byte dataLag[A_PINS];
// ititialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead analog[]{
  {ANALOG_PINS[0],true},
  {ANALOG_PINS[1],true},
  {ANALOG_PINS[2],true},
  {ANALOG_PINS[3],true},
  {ANALOG_PINS[4],true},
  {ANALOG_PINS[5],true},
  {ANALOG_PINS[6],true}//,
  //{ANALOG_PINS[7],true},
  //{ANALOG_PINS[8],true},
}; // not sure if there is a better way... some way run a setup loop on global array??
void setup() {
  // begin serial so we can see analog read values through the serial monitor
  //Serial.begin(9600);
}

void loop() {
  // update the ResponsiveAnalogRead object every loop
  for (int i=0;i<A_PINS;i++){
    analog[i].update(); 
    // if the repsonsive value has change, print out 'changed'
    if(analog[i].hasChanged()) {
      data[i] = analog[i].getValue()>>3;
      if (data[i] != dataLag[i]){
        dataLag[i] = data[i];
        usbMIDI.sendControlChange(CCID[i], data[i], 1);
      }
    }
  }
}
Initializing the ResponsiveAnalogRead objects is a bit tricky as you can't do it in the set up loop (or they are not available in the main loop) and you can't run a loop outside setup() call. One of the C gurus here may be able to sort me out on this... but I think this is a reasonable start...

Here's the 'hardware' I'm running on:
20170305_122544.jpg
I will add three buttons and get that part working next...
 
Last edited:
this code worked perfectly. it's very smooth.my linear faders worked perfectly.( they are 10k) had trouble with my rotary style pots( Not sure what size they where. do they have to be a certain ohm?)
let me know when you get the code for the 3 buttons added. it will be awesome!!
 
Status
Not open for further replies.
Back
Top