Go Down

Topic: MIDI cc sending constant stream of values to Ableton (Read 216 times) previous topic - next topic

liamorourke

Hi... I'm sending MIDI cc data to Ableton via Hiduino on an UNO r3. It's sort of working but I have a problem: It seems to be constantly sending values as opposed just when I turn the potentiometer. I've attempted to use an 'if' statement so that it should only 'MIDI.sendControlChange' when the value of 'lastAnalogueValue' is different to the value of 'cc' (please see my code)... but it doesn't seem to be working as both Ableton and MIDIox still seem to be reading values constantly. Although... saying that... I also noticed that the values stop when they reach either 0 or 127 which is odd.

Anyway... here's my code: -
Code: [Select]

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();

//variables
int cc = 0;
int analogValue = 0;
int lastAnalogValue = 0;

void setup() {
  MIDI.begin(4);
}

void loop() {
  analogValue = analogRead(0);
   
  cc = analogValue / 8;
 
  if (lastAnalogValue != cc) {
    MIDI.sendControlChange(16,cc,1);
  }
  lastAnalogValue = cc;
 
}



Thanks in advance for any help

Grumpy_Mike

Use
Code: [Select]

if( abs(lastAnalogValue - cc) > 2) {

Or better yet do the comparison before you divide by 8
Make that 2 bigger for more noise immunity.

liamorourke

#2
Apr 24, 2015, 11:01 am Last Edit: Apr 24, 2015, 11:31 am by liamorourke
Hi thanks for that... I tried your suggestion but it's still sending MIDI data to ableton and MIDIox all the time. The only difference it makes is now it doesn't even stop when it gets to 0 or 127. I've pasted my new code with your suggestion included below. Can you see if I've replaced the right line with the right line. I also tried replacing the '< 2' with '< 4' and even '< 10' But for some reason, no difference. Thanks again

Code: [Select]

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();

//variables
int cc = 0;
int analogValue = 0;
int lastAnalogValue = 0;

void setup() {
  MIDI.begin(4);
}

void loop() {
  analogValue = analogRead(0);
   
  cc = analogValue / 8;
 
  if( abs(lastAnalogValue - cc) > 2) {
    MIDI.sendControlChange(16,cc,1);
  }
  lastAnalogValue = cc;
}

Grumpy_Mike

As I said try doing it on the raw value not the scaled value, like this:-
Code: [Select]


#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();

//variables
int analogValue = 0;
int lastAnalogValue = 0;

void setup() {
  MIDI.begin(4);
}

void loop() {
  analogValue = analogRead(0);
 
  if( abs(analogValue - lastAnalogValue) > 8) {
    MIDI.sendControlChange(16, analogValue>> 3 ,1);
  }
  lastAnalogValue = analogValue;
}


If that still does not cure things you need to put a 0.1uF cap between the wiper of the pot and ground.

Note the >> is a shift to the right and >> 3 is much quicker than a divide by 8 but does the same thing.

liamorourke

thanks again... I'm just away from home for the weekend but as soon as I'm back I'll give that a go. By the way, the wiper from the pot is already connected to A0 and you said i need to put a cap between the wiper and ground. Did you mean between the wiper and A0 or do I have to connect the wiper to both A0 and ground (via a cap)?

Grumpy_Mike

Quote
Did you mean between the wiper and A0
Yes

wabbitguy

Have you got the MIDI output to the Hiduino disabled in Live? Just thinking that you have have MIDI Thru on and when you send a value, Live is echoing it back to you and round and round she goes.

liamorourke

#7
May 21, 2015, 08:35 am Last Edit: May 21, 2015, 08:56 am by liamorourke
Hi sorry about the late reply. Working far too much recently :(
 
Grumpy_Mike... Thank you that seems to have worked pretty well. I'm still getting the noise feeding through when I move the potentiometer but it's such a small amount in comparison to the actual movement that it's basically unnoticeable. I would say that after the serial - MIDI division it equates to a maximum fluctuation of 1 MIDI value. Which is pretty decent to be fair. I couldn't however seem to get any difference with the capacitor on the wiper idea. I used a 0.1uF electrolyte radial cap which I think had a rating of 63 volts. Is this correct? Also... I am wondering if I was to use some sort of shielded cabling to hook up the pot would this help with noise reduction even further? The cable I am currently using is possibly not shielded at all.

Wabbitguy... Thank you for you input. I tried disabling the output in Ableton but this didn't change anything. Plus I'd like to have the output enabled anyway so that I can send on/ off voltages to LED's on the controller when certain things are enabled/ disabled in Ableton.

Thanks again to both of you for your help

Grumpy_Mike

A value of 0.1uF for an electrolytic sounds very low and 65V working is a bit overkill as it will only ever see 5V. Still it will be effective. The noise on altering the pot is probbly the fact that it is being read several times during your turning of it, or it could be a noisy pot. Try a 10uF cap instead of 0.1 to increase your smoothing.

liamorourke

Thanks again Mike... you've been very helpful. I'll give that 10uF cap a go later and reply here with how i get along.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy