Question about midi data smooth on Pots with Teensy 3.2 with Midi Elements Libery

Status
Not open for further replies.

polysix

Member
A warm hello in the round,

i´m Axel and i´m verry new on microcontroller and i have fineshed my first Project. I have build a small Mdi controller with 7 Pots and a led for showing the status of Power on/off. It works verry well but i have a Problem on a special point and i hope for a little help on this place :)

It seems that my Potiometers sending every time midi singnals. This is if i solder (or test on breadboard) more than 2 Pots. After a time my PC DAW tells my that to many Midi data is incoming. You can see that the signals a flicker and not constant. The informations i found in the net are that all componets are sending signals. More Components more Signals :) I have found that i do must make a smoothing on my code that smooth the Potiometers. But i do not found some code examples. So... can you help my please?

Thats my Code based on Midi Elements libery by TomashG HZ:
Code:
// MIDI Elements empty template
// by Tomash Ghz
// www.tomashg.com
// ghz.tomash@gmail.com

#include <MIDIElements.h>

const int ledPinDig = 13;
boolean debug = false; // print to serial instead of midi
boolean secondary = true; // enable secondary midi messages
int midiChannel = 1; // midi channel number

// pins used in this exapmle are ones in corner of board, so:
// 11 & 12 for Teensy 3.x
// 16 & 17 for Teensy 2.0++
//int butPin1 = 11; // digital pin for reading first button
//int butPin2 = 12; // digital pin for reading second button

int potPin = A0; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int potPin1 = A1; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int potPin2 = A2; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int potPin3 = A3; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int potPin4 = A4; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int potPin5 = A5; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int potPin6 = A6; // analog pin A7 for Teensy 3.x, for Teensy 2.0++ change this to 45
int ledPin = 3; // PWM pin 3 for Teensy 3.x, for Teensy 2.0++ change this to 15



// declare all your components here
//Button but(butPin1, midiChannel, 1, secondary, debug); // button 1 on pin 17
//Button but2(butPin2, midiChannel, 2, secondary, debug); // button 2 on pin 16
Potentiometer pot(potPin, midiChannel, 20, secondary, debug); // knob on pin 45 (A7)
Potentiometer pot1(potPin1, midiChannel, 21, secondary, debug); // knob on pin 45 (A7)
Potentiometer pot2(potPin2, midiChannel, 22, secondary, debug); // knob on pin 45 (A7)
Potentiometer pot3(potPin3, midiChannel, 23, secondary, debug); // knob on pin 45 (A7)
Potentiometer pot4(potPin4, midiChannel, 24, secondary, debug); // knob on pin 45 (A7)
Potentiometer pot5(potPin5, midiChannel, 25, secondary, debug); // knob on pin 45 (A7)
Potentiometer pot6(potPin6, midiChannel, 26, secondary, debug); // knob on pin 45 (A7)
Led led(ledPin, midiChannel, 3, true); // led on pin 15 with PWM enabled, triggered on the same CC number as pot

void setup()
{
  pinMode(ledPinDig, OUTPUT);
  usbMIDI.setHandleNoteOff(OnNoteOff); //set event handler for note off
  usbMIDI.setHandleNoteOn(OnNoteOn); //set event handler for note on
  usbMIDI.setHandleControlChange(OnControlChange); // set event handler for CC
}

void loop()
{

  // add here all the input component reads
  digitalWrite(ledPinDig, HIGH);
  pot.read(); // read knob and send midi messages
  pot1.read(); // read knob and send midi messages
  pot2.read(); // read knob and send midi messages
  pot3.read(); // read knob and send midi messages
  pot4.read(); // read knob and send midi messages
  pot5.read(); // read knob and send midi messages
  pot6.read(); // read knob and send midi messages
  
  //but.read(); // read buttons and send midi messages
  //but2.read();

  usbMIDI.read(); // read all the incoming midi messages
}

//====================================================================
// event handlers
void OnNoteOn(byte channel, byte note, byte velocity)
{
  // add all your output component sets that will trigger with note ons
  led.setOn(channel, note, velocity);
}

void OnNoteOff(byte channel, byte note, byte velocity)
{
  // add all your output component sets that will trigger with note ons
  led.setOff(channel, note, velocity);
}

void OnControlChange(byte channel, byte control, byte value)
{
  // add all your output component sets that will trigger with cc
  led.setOn(channel, control, value);
}

I use a Teensy 3.2. Soldering is dirctliy from Teensy 3.2 to Poti. And than from GRND, Data, +from Poti to Poti :)
Software was used the last Arduino Soft on Win10.

Thanks a lot and sorry for my rough english !

Greats
Axel
 

Attachments

  • Basimilus_1_feritig_mit_Led.ino
    3.5 KB · Views: 60
You might want to consider whether the 'wrapper' library you are using is bringing you anything worthwhile? I've never heard of it before and there are no recent example of it's use on the forum.

I took a quick look but became discouraged by the documentation.

Does it really not support signal smoothing in the potentiometer object??

If you have to add RaR in anyway you might just try merging a MIDI-encoder example with the pots-and-buttons one that already has RaR built in.
 
You might want to consider whether the 'wrapper' library you are using is bringing you anything worthwhile? I've never heard of it before and there are no recent example of it's use on the forum.

I took a quick look but became discouraged by the documentation.

Does it really not support signal smoothing in the potentiometer object??

If you have to add RaR in anyway you might just try merging a MIDI-encoder example with the pots-and-buttons one that already has RaR built in.

Thanks a lot for your support and help ...it seems that this forum is a friedly place with lot of help for beginners like me :)
I send today Tomash the developer of the code a mail. I hope he gives me a answer if it a support for smoothing for the pots.
I hope he give me a answer. In the github i see that 2 years ago someone upload a Potiometers.h. And he write that this gives a better suppport. At the weakend i will take a look :)

Greats
Axel
 
You might want to consider whether the 'wrapper' library you are using is bringing you anything worthwhile? I've never heard of it before and there are no recent example of it's use on the forum.

I took a quick look but became discouraged by the documentation.

Does it really not support signal smoothing in the potentiometer object??

If you have to add RaR in anyway you might just try merging a MIDI-encoder example with the pots-and-buttons one that already has RaR built in.

Hi Oddson,

Yeah.. I think i will change from the wrapper libery. I found after a search your Code in This forum under:

https://forum.pjrc.com/threads/45376-Example-code-for-MIDI-controllers-with-Pots-and-Buttons

And it looks like for that, that i'm on search :)
I let you know on this place if all works fine. And i take a picture of my Controler.
 
Hi Oddson,

Yeah.. I think i will change from the wrapper libery. I found after a search your Code in This forum under:

https://forum.pjrc.com/threads/45376-Example-code-for-MIDI-controllers-with-Pots-and-Buttons

And it looks like for that, that i'm on search :)
I let you know on this place if all works fine. And i take a picture of my Controler.

Hello Oddson,

i use your code and it works out of the box. No jittering, a perfect smooth on the Pots. Thank you so much for sharing this it helps me sooo much.
 
Was it not you looking for pots and encoder together? I guess I mixed you up with someone else in my first reply.
 
Was it not you looking for pots and encoder together? I guess I mixed you up with someone else in my first reply.

If So? I `m verry happy ! :D your code hepls me so much. My Controler works with Potiometers so great. No jitter no noises. Perfect ! Thank you so much.

Oddson, i have a Question to your code. Is it possible that a button send only CC commands? Or is it coupled on a Keyboard Command Note ON / OFF?

As a example (sorry my english is verry rough i hope it is not incomprehensible) i will do a changing on my Plugin do i press the button on my controler and it send only a CC Command like the Potiometers doing. is this Possible to switch e.g Targets on my Plugin? As example steps by button pressing the OSC Waves in my Plugin????? Or switch other things? Or is this not possible between the communication Teensy and DAW?

Thanks a lot !!
Axel
 
The only trick to CC buttons is adding 'toggle' behavior because you have to store the current state of each button and reverse it when called. Typically you also change to only responding to the switch being pulled LOW (pressed button pulls the PIN to ground) so the risingEdge can be ignored. On my tablet ATM... looking for a good thread on the subject.


... code in this post but says untested....
https://forum.pjrc.com/threads/5250...p-writing-code?p=180440&viewfull=1#post180440

You would copy the digital section to replace the same code in the stock sketch as this one has pots section stripped out.

Plus a few changes in the declaration section that the compiler will point out if you miss them. Specifically you need to add

int state[D_PINS] ;

....to the variable declarations
 
Last edited:
The only trick to CC buttons is adding 'toggle' behavior because you have to store the current state of each button and reverse it when called. Typically you also change to only responding to the switch being pulled LOW (pressed button pulls the PIN to ground) so the risingEdge can be ignored. On my tablet ATM... looking for a good thread on the subject.


... code in this post but says untested....
https://forum.pjrc.com/threads/5250...p-writing-code?p=180440&viewfull=1#post180440

You would copy the digital section to replace the same code in the stock sketch as this one has pots section stripped out.

Plus a few changes in the declaration section that the compiler will point out if you miss them. Specifically you need to add

int state[D_PINS] ;

....to the variable declarations

Wow. I´m speechless. A Question and immediately comes help ! Thanks you so much. At the weakend I will experiment. I do some chnages by myself but it sends only on cc0 . Thank you Oddson for this great and frindly support !

I do some pictures of my first work on the Propplerhead Reason Forum with a credit for you :) it is verry simple at the moment (only with 7 Pots) but it works !

https://forum.reasontalk.com/viewtopic.php?f=12&t=7507664
 
So you are still having problems integrating or you've got it working already?

You would also have to add this declaration:

const int CCnumber[D_PINS] = {20,31,22,23,24,25};

(With whatever CC numbers you want for each button in that array element's spot.)

I'd be happy to do the merge myself but I'm not going to be around a compiler and a Teensy with time to kill anytime soon... but if you run into a wall I'll post a working sketch eventually.
 
So you are still having problems integrating or you've got it working already?

You would also have to add this declaration:

const int CCnumber[D_PINS] = {20,31,22,23,24,25};

(With whatever CC numbers you want for each button in that array element's spot.)

I'd be happy to do the merge myself but I'm not going to be around a compiler and a Teensy with time to kill anytime soon... but if you run into a wall I'll post a working sketch eventually.

Sorry I wrote it misleading i make some tests to send CC values (not Note on off) over the button at the past days...my english. I do this experiments with your first posted code "many pots and buttons". http://https://forum.pjrc.com/threads/45376-Example-code-for-MIDI-controllers-with-Pots-and-Buttons I tried to change him there but with no great or working success. I still have to learn more than a beginner :)

Last night I tried the new code https://forum.pjrc.com/threads/52507...l=1#post180440 with one button for the beginning. It worked immediately perfect. I can switch over CC 20 somthing ON / OFF (Value 0 / 127). Great ! On the next coming weakend i will take a look how it works that I always go one step further quilt. E.g. Press Once it sends a CC 20 with Value of e.g. 30 , in my plugin is LFO Sine selctet, press once again it sends the same CC20 with Value of e.g. 60 the LFO Pulse is selectet and pressing once agien the next parameter selectet and last to press is going to value 0 back.

that would be so nice if you finished your sketch ! many beginners like me certainly fail already at the beginning because it is not as easy as it often in youtube videos or other contributing how build yourself a controller in one day :) I hope the walls will fall :)
 
Last edited:
DIY also applies to coding...

The problem with offering full-feature code is that the complexity becomes a barrier to learning.

***

So you want to be able to send different values rather than an arbitrary OFF=0 and ON=127 (or any other constant more than 63)?

This is exactly the kind of flexibility that building your own controller and knowing some basic coding allows you to do with Teensy.

I will post a toggle extension to my code sometime soon.

If you need help with the coding on your three-state (multi-state?) switch let me know and I'd be happy to help.

(The behaviour is fairly similar to 'toggle' and the variable to hold the current state will work for this too but the conditional logic would have to include multiple cases instead of a simple TRUE/FALSE.
 
Last edited:
DIY also applies to coding...

The problem with offering full-feature code is that the complexity becomes a barrier to learning.

***

So you want to be able to send different values rather than an arbitrary OFF=0 and ON=127 (or any other constant more than 63)?

This is exactly the kind of flexibility that building your own controller and knowing some basic coding allows you to do with Teensy.

I will post a toggle extension to my code sometime soon.

If you need help with the coding on your three-state (multi-state?) switch let me know and I'd be happy to help.

(The behaviour is fairly similar to 'toggle' and the variable to hold the current state will work for this too but the conditional logic would have to include multiple cases instead of a simple TRUE/FALSE.

Thank you Oddson for the offer of help :). I was able to finish the code with much help of a friend. We have it was a array and a incremt what the states by turns and then return to zero. And it works fin.
Thanks again for your help! Next I wanted to try a mux we'll definitely meet here again :)
 
Status
Not open for further replies.
Back
Top