tttapa / MIDI_controller

This is a library for creating a MIDI controller using an Arduino or Teensy board.
GNU General Public License v3.0
402 stars 70 forks source link

MIDI signals non-stop #47

Closed rabbiccu closed 6 years ago

rabbiccu commented 6 years ago

I have sporadic behavior when I go to tinker daily on this project. My faders (10k fader pots) have stopped working all together, although at one time I was able to get a logarithmic response from them.

I have ordered a multimeter and will be testing my hardware, but is there any reason for this that could be software related? The following screenshot shows the flow of midi signals, never stopping.

capture_midi

I am using code mentioned in other issues I've opened:


/*
This is an example of the "Analog" class of the MIDI_controller library.
Connect a potentiometer to analog pin A0. This will be the MIDI channel volume of channel 1.
Map it in your DAW or DJ software.
Set 'minimumValue' to the analog value read when the potentiometer is in the minimum position.
Set 'maximumValue' to the analog value read when the potentiometer is in the maximum position.
Written by Pieter P, 20-09-2017
https://github.com/tttapa/MIDI_controller
*/

#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A0, 
// that sends MIDI messages with controller 7 (channel volume) on channel 1
Analog potentiometer_A(A0, MIDI_CC::Sound_Controller_1, 1);
Analog potentiometer_B(A1, MIDI_CC::Sound_Controller_2, 1);
Analog potentiometer_C(A2, MIDI_CC::Sound_Controller_3, 1);
Analog potentiometer_D(A3, MIDI_CC::Sound_Controller_4, 1);
Analog potentiometer_E(A4, MIDI_CC::Sound_Controller_5, 1);

void setup() {

}

void loop() {
  // Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)
  MIDI_Controller.refresh();
}

Update

I wired all inputs to the same pot (position 1 on my breadboard). All 5 messages were being received by MIDI-OX just fine. When I took the input for the second channel and put it to the second pot, the diarrhea began for that channel only. Same for the 3rd 4th and 5th. Any channel peeled off the first pot and put on its own pot become non-sense.

So I thought maybe I only have one good pot, since all the inputs on the arduino are fine. So I took the pot from position 2 and put it in position 1. I wired all the inputs to the output of this fader 2 in position 1 and they worked. I went down the line and they all worked in position 1.

I hope this makes sense. So this leads me believe 2 things. Unlikely, but is the code getting confused by having 5 unique inputs? Surely not. Another thing is maybe the wiring on my breadboard is wrong. There must be a configuration issue because each pot and each input on the arduino has proven it can work.

I have a 5v going straight to the +bus bar and GND going to the negative and have each pot's pins jumping directly to that busbar. This really has me baffled - because the wiring works but only on a seemingly arbitrary place on the breadboard! Can distance from the 5v terminal cause a problem?

Update 2

I took everything off the breadboard and rewired the 5 pots to their own channels. Pots 1 2 & 3 were able to control their values but 4 and 5 (A3 and A4) were doing the diarrhea thing. I took a jumper and went from the corner where the initial 5v jump point is on the breadboard over to the other side near 4 and 5 and the diarrhea stopped, however they do not control their inputs, but have gone silent. I am totally baffled.

Could the power supply be an issue? I can reliably operate the first three inputs, 4 and 5 are sporadic but if I gang them onto pot 1 I can control their inputs that way.

tttapa commented 6 years ago

All inputs are independent objects in software, so that shouldn't be an issue.
Make sure all wires make good connection, even when wiggling them around. You could try soldering wires to everything, and use male header pins to plug them into the Arduino.
The outer terminals of the potentiometer go to ground and 5V respectively, the center pin (wiper) goes to the analog input. If you experience noise (values fluctuating up and down 1 or 2 values), you could try the master version, which has improved filtering.

Other than that, I don't know what could cause it. I would suspect a hardware issue, though.

TechJA commented 6 years ago

Another tip: could you connect just one pot to A3 and after to A4 to check these input ports? Maybe they are damaged

rabbiccu commented 6 years ago

The breadboard has an interupted power rail which I didn't realize was a thing. First project. Sadly though when I figured this out I was bridging them and the board fried. I had an external 12V power supply, which I the leonardo is supposed to handle.

There's no other way this could have fried using just the 5v, gnd, inputs and a bunch of pots and faders, right?

tttapa commented 6 years ago

You could have shorted out 5V to ground, which would probably destroy the 5V regulator when powering it from a 12V source.

What exactly fried? The MCU or some other part?

rabbiccu commented 6 years ago

The ATmega32u4 is incredibly hot now, so I think that burned asking with some other things.

I'm sure I sorted the 5v to gnd because I wasn't cautious to avoid that and tried a million configurations during troubleshooting. I guess I just thought the gnd could handle it. Oh well 10 bucks.

So my pots are linear but my faders are logarithmic but there is code for mapping log sliders IIRC.

tttapa commented 6 years ago

You can use the map function, together with the formula discussed here: https://github.com/tttapa/MIDI_controller/issues/43#issuecomment-396056679.

rabbiccu commented 6 years ago

So would the

value = (value < y_knee) ? (value * x_knee / y_knee) : ((value - y_knee) * (1023 - x_knee) / (1023 - y_knee) + x_knee); 

come after the mapping function for that input? Will you do a sample code please?

tttapa commented 6 years ago
#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A0, 
// that sends MIDI messages with controller 7 (channel volume) on channel 1
Analog potentiometer(A0, MIDI_CC::Channel_Volume, 1);

const int x_knee = 512;
const int y_knee = 102;

int mapCalibrated(int value) {
  value = (value < y_knee) ? (value * x_knee / y_knee) : ((value - y_knee) * (1023 - x_knee) / (1023 - y_knee) + x_knee); 
  return value;
}

void setup() {
  potentiometer.map(mapCalibrated); // apply the 'mapCalibrated' function on the analog input of 'potentiometer'
}

void loop() {
  // Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)
  MIDI_Controller.refresh();
}
rabbiccu commented 6 years ago

And to add linear would they be added at the end of map calibration aka

#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A0, 
// that sends MIDI messages with controller 7 (channel volume) on channel 1
Analog potentiometer(A0, MIDI_CC::Channel_Volume, 1);
Analog potentiometer(A2, MIDI_CC::Channel_Volume, 3);

const int x_knee = 512;
const int y_knee = 102;

int mapCalibrated(int value) {
  value = (value < y_knee) ? (value * x_knee / y_knee) : ((value - y_knee) * (1023 - x_knee) / (1023 - y_knee) + x_knee); 
  return value;
}

Analog potentiometer(A1, MIDI_CC::Channel_Volume, 2);

void setup() {
  potentiometer.map(mapCalibrated); // apply the 'mapCalibrated' function on the analog input of 'potentiometer'
}

void loop() {
  // Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)
  MIDI_Controller.refresh();
}

Gives you log pots on 1 and 3 and linear on 2?

tttapa commented 6 years ago

No, for the linear ones, you just don't use potentiometer.map(mapCalibrated) at all. The position in the code doesn't matter.

tttapa commented 6 years ago

For example:

#include <MIDI_Controller.h> // Include the library

Analog linearPots[] = {
  {A0, MIDI_CC::Channel_Volume, 1},
  {A1, MIDI_CC::Channel_Volume, 2},
  {A2, MIDI_CC::Channel_Volume, 3},
  {A3, MIDI_CC::Channel_Volume, 4},
};

Analog logPots[] = {
  {A4, MIDI_CC::Channel_Volume, 5},
  {A5, MIDI_CC::Channel_Volume, 6},
  {A6, MIDI_CC::Channel_Volume, 7},
  {A7, MIDI_CC::Channel_Volume, 8},
};

const int x_knee = 512;
const int y_knee = 102;

int mapLog(int value) {
  value = (value < y_knee) ? (value * x_knee / y_knee) : ((value - y_knee) * (1023 - x_knee) / (1023 - y_knee) + x_knee); 
  return value;
}

void setup() {
  for (Analog &potentiometer : logPots)
    potentiometer.map(mapLog); // apply the 'mapLog' function on the analog input of this potentiometer
}

void loop() {
  // Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)
  MIDI_Controller.refresh();
}
rabbiccu commented 6 years ago

Wow amazing, and it all makes sense.