Can't get Teensy 3.2 to work reliably as a midi cc controller.

Status
Not open for further replies.

augustfay

New member
So I've been working on this project for about a week and a half straight, it's pretty simple but my first DIY and so it's taken me a while... but I've also went through maybe 6 breadboards re soldering and doing the wiring from scratch every time because I couldn't get the thing to work and I thought maybe that was the problem. After about 30 hours wasted I've now concluded that it's not my wiring so I come here asking for help. It's a simple faderbox using 8 linear potentiometers, each connected to the A0-7, using this wiring minus the LED and resistors:
Qi36fcg.jpg.

There are a few issues. First off I can't get it to output any sort of midi information into an app like MIDI Monitor. But I don't really mind that since I want it for the CCs and I have been able to get my DAW, Logic Pro X, to recognize the 0-127 information in its transport window. So the thing is pretty sporadic. It works maybe 15% of the times I plug it in, I suspected it was because of my own micro usb to usbB connector but I removed that and just connected the teensy using the built in port and the problem seems to remain. I believe I've come to the conclusion that the thing only works when it's the only thing plugged into my computer. And even then it seems like sometimes it just doesn't. As soon as I plug it into a powered USB 3 hub, it ceases to function. Logic still detects the teensy in the midi setup, but no CC information appears in the transport. If I unplug everything from my computer and plug the faderbox back in, I can get it to work, but even if I plug in the USB hub into a different USB port on the computer, Logic will rescan and the faderbox will cease to show any CC information in Logic. I obviously need the hub and everything else that is attached to it, keyboard, mouse, other controllers, etc. I just want this thing to be plug and play already.

This is incredibly frustrating, if anybody has any sort of help I would really appreciate it, I'm about 30 hours and $300.00 into this project now with little success. Thank you in advance.

Here is the code I've been using, a variation of something I originally found on Gearslutz, along with the wiring diagram:


Code:
#include <Bounce.h>

///////////////////////////////////////////////////////////////////////////
// define how many pots are active up to number of available analog inputs
#define analogInputs 8
//////////////////////////////////////////////////////////////////////////


// define arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// define array of cc values
int ccValue[analogInputs];
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>


///////////////////////////////////////////////////////////////////////////
// define pins and cc codes
const int A_PINS = 8;
const int ANALOG_PINS[A_PINS] = {A0, A1, A2, A3, A4, A5, A6, A7};
const int CCID[A_PINS] = {11, 1, 21, 7, 2, 12, 13, 16};
///////////////////////////////////////////////////////////////////////////


// 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},
           
  ///////////////////////////////////////////////////////////////////////////
}; 

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
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);
      }
    }
  }
}
 
Last edited:
The code is set up for eight analog voltage dividers.

All the unused pins it reads will 'float' as they build up stay voltage because they are not electricly connected to any stable voltage source between each read.

This will pump out a flood of garbage CC messages and cause issues for listening applications on the PC.
 
Thank you for the reply, unfortunately I am a bit of a newbie when it comes to the code and I don't really know what I should change. :( How would I revise it to properly work for my purpose?

Also I actually got it to work using the current code by changing the USB type (in the menu bar under Arduino > tools > USB type) from "MIDI" to "Serial and MIDI" and then reuploading the code. I don't know why it works now and it was a totally random decision to try this different midi type, but now I can use it not only with the hub and all my other peripherals, but I'm also getting midi information in the midi monitoring app, which I had never got to work before. I'm not doing anything wrong or damaging am I? Thanks again for the help.
 
Do similar USB communication issues happen (especially with that USB3 hub) if you run a program that just prints stuff to the serial monitor? How about after you upload using RawHID from Tools > USB Type? Would really help to know if the problem is MIDI specific, or happens similarly with Serial, HID and MIDI.

I have a Macbook Air here with 10.14.3. I have only 1 USB3 hub handy, and it's an unpowered type. Serial and HID seem to work fine. I don't have Logic or other MIDI software on that Mac, nor do I have much Mac experience with MIDI.

If the problem seems to happen with all USB types, maybe I could trying buying that same hub and test it here? Or if it's only with MIDI, maybe I could install some Mac software? But I'm not a musician, so when it comes to MIDI testing I really need to keep it simple and might need pretty specific instructions on how to test.
 
Thank you for the reply, unfortunately I am a bit of a newbie when it comes to the code and I don't really know what I should change. :( How would I revise it to properly work for my purpose?...

Code:
#include <Bounce.h>

///////////////////////////////////////////////////////////////////////////
// define how many pots are active up to number of available analog inputs
#define analogInputs [COLOR="#FF0000"]3[/COLOR]
//////////////////////////////////////////////////////////////////////////


// define arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// define array of cc values
int ccValue[analogInputs];
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>


///////////////////////////////////////////////////////////////////////////
// define pins and cc codes
const int A_PINS = [COLOR="#FF0000"]3[/COLOR];
const int ANALOG_PINS[A_PINS] = {A0, A1, [COLOR="#FF0000"]A2};[/COLOR]
const int CCID[A_PINS] = {11, 1, [COLOR="#FF0000"][COLOR="#FF0000"]21};[/COLOR][/COLOR]
///////////////////////////////////////////////////////////////////////////


// 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}
           
  ///////////////////////////////////////////////////////////////////////////
}; 

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
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);
      }
    }
  }
}

Minimally the stuff in red should do the trick but I didn't test or even compile....

Or you can pull all the unused pins it's checking to ground and there will be no extraneous MIDI, but it will keep harmlessly reading them anyway.
 
USB3 doesn’t always work with older USB devices even though it’s “backwards compatible”, I’ve had problems with other USB devices not working correctly on USB3 even though they show up in the OS they aren’t usable like they are supposed to be. As soon as I plug it into USB2 it works like it’s supposed to, it’s weird but something else is going on beyond the scope of the Teensy as far as I can tell since other devices experience the same problem with USB3.
 
Code:
#include <Bounce.h>

///////////////////////////////////////////////////////////////////////////
// define how many pots are active up to number of available analog inputs
#define analogInputs [COLOR="#FF0000"]3[/COLOR]
//////////////////////////////////////////////////////////////////////////


// define arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// define array of cc values
int ccValue[analogInputs];
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>


///////////////////////////////////////////////////////////////////////////
// define pins and cc codes
const int A_PINS = [COLOR="#FF0000"]3[/COLOR];
const int ANALOG_PINS[A_PINS] = {A0, A1, [COLOR="#FF0000"]A2};[/COLOR]
const int CCID[A_PINS] = {11, 1, [COLOR="#FF0000"][COLOR="#FF0000"]21};[/COLOR][/COLOR]
///////////////////////////////////////////////////////////////////////////


// 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}
           
  ///////////////////////////////////////////////////////////////////////////
}; 

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
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);
      }
    }
  }
}

Minimally the stuff in red should do the trick but I didn't test or even compile....

Or you can pull all the unused pins it's checking to ground and there will be no extraneous MIDI, but it will keep harmlessly reading them anyway.

He states that he has 8 faders connected to the specified pins in the original code, so no change is needed.
 
He states that he has 8 faders connected to the specified pins in the original code, so no change is needed.
I have a habit of missing key details.... after reading more carefully it sounds like it has nothing to do with the code or the build so I'll shut up now.
 
Status
Not open for further replies.
Back
Top