Rotary Encoder - MIDI Serial

Hello, I want to use 2 rotary encoders as jogwheels and one as a browser in my Dj mixer arduino based.

I used the code from 'notes and volts' (#include <MIDI.h>#include "Controller.h"/********************************* - Pastebin.com) and it works/i understand it.

I do not use it through MIDI jack, I use it with a virtual midi port and Hairless midi.

I want to add rotary encoders and the library used doesn't have that option.

I already explored another encoder libraries (encoder.h for example) and its examples and i could make the encoder work, but i don't know how to link the encoder to midi since i don't find that function in the library used in the notes and volts code. (http://arduinomidilib.fortyseveneffects.com/)

What can I do to 'integrate' the encoder to my already existent midi code? Thank you very much!!

Send the relative movement as the value of a Control Change message. Either encode it as 7-bit two’s complement, 7-bit signed magnitude, or add an offset of 64 to the signed value.

Then select the right sign mode in your software as well.

For example, if your encoder turned 4 steps backwards, the relative movement is -4, so you could send 0b01111100 (two’s complement), 0b01000100 (signed magnitude) or 0b00111100 (offset).

Pieter

Hi Pieter, thank you for your answer. I also tried to integrate the rotary encoder part from your midi controller in instructables, but i couldn't apply it because i'm using 3 rotary encoders and i'm using pins that are not interruptors.

I'm a beginner in programming, how can I send those relative movements as CC in terms of syntaxis? Do you have an example that I can learn from? Should I modify the library that i'm using (MIDI.h)? Thank you very much!

Rymehar:
Hi Pieter, thank you for your answer. I also tried to integrate the rotary encoder part from your midi controller in instructables, but i couldn't apply it because i'm using 3 rotary encoders and i'm using pins that are not interruptors.

Then open the source code to see how it's done:
https://github.com/tttapa/MIDI_controller/blob/master/src/RotaryEncoder.cpp

You don't have to change the MIDI libraries, just use the send functions to send your CC messages.

Pieter

I can't find the code

https://github.com/tttapa/MIDI_controller/blob/master/src/MIDI_Outputs/RotaryEncoder.cpp

link is not available. I have been reading, testing for many days and I cannot do what the colleague said. I need to add rotary encoders to the notes and volt sketch in the MIDI.h library.

I replied to your post here: https://forum.arduino.cc/index.php?topic=499233.msg4593699#msg4593699

The MIDI controller library has been replaced by the Control Surface library:
https://tttapa.github.io/Control-Surface-doc/Doxygen/d2/d1f/RotaryEncoder_8ino-example.html

Pieter

PieterP:
I replied to your post here: https://forum.arduino.cc/index.php?topic=499233.msg4593699#msg4593699

The MIDI controller library has been replaced by the Control Surface library:
Control Surface: RotaryEncoder.ino

Pieter

I was reviewing the codes, I was doing some tests but I could not do what I need. My knowledge of arduino is very little and recent and I apologize for the inconvenience that I may experience.
I’m still using the arduino for hairless, the only thing I get there is the following error:

“warning: got a status byte when we expecting 1 more data bytes, sending possibly incomplete MIDI message.
got unexpected data byte”

This is using the following code (I tried both options):

#include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;

// Instantiate a CCAbsoluteEncoder object
//CCAbsoluteEncoder enc = {
//{2, 3}, // pins
//MIDI_CC::Pan, // MIDI address (CC number + optional channel)
//1, // optional multiplier if the control isn’t fast enough
//};

// Similarly, for Pitch Bend
PBAbsoluteEncoder enc = {
{2, 3}, // pins
CHANNEL_1, // MIDI channel
127, // large multiplier because Pitch Bend has high resolution
};

void setup() {
Control_Surface.begin(); // Initialize Control Surface

}

void loop() {
Control_Surface.loop(); // Update the Control Surface
}

I have a midi driver (NanoKontrolStudio) whose encoder returns 2 notes, one for each side, and it’s just what I need. As if each pulse was a pulse of a button. ej:

CW CC Number: 28
CCW CC Number: 29

jorgech:
I'm still using the arduino for hairless, the only thing I get there is the following error:

"warning: got a status byte when we expecting 1 more data bytes, sending possibly incomplete MIDI message.
got unexpected data byte"

If you want to use Hairless MIDI, you have to use the HairlessMIDI_Interface instead of the USBMIDI interface.

Please see this section of the Getting Started guide: Control Surface: Getting Started

jorgech:
I have a midi driver (NanoKontrolStudio) whose encoder returns 2 notes, one for each side, and it's just what I need. As if each pulse was a pulse of a button.

Are you sure it sends notes? Most controllers use Control Change for rotary encoder.

Either way, AbsoluteEncoders are not what you're after, what you describe is a relative encoder. See the original CCRotaryEncoder example I referred to.

"Either way, AbsoluteEncoders are not what you're after, what you describe is a relative encoder. See the original CCRotaryEncoder example I referred to.
[/quote]

there I added an image so you can see what I am talking about, I am going to check the code that you are telling me.

I was reviewing and testing the CCRotaryEncoder code but I remain the same, without understanding and unable to solve my problem. As you say the midi controller I mention works with control change, and what the encoder does is generate a control change for CW and another control change for CCW. And it's what I can't do.

jorgech:
I was reviewing and testing the CCRotaryEncoder code but I remain the same, without understanding and unable to solve my problem. As you say the midi controller I mention works with control change, and what the encoder does is generate a control change for CW and another control change for CCW. And it's what I can't do.

What remains the same? Please post the exact code you're using (use code tags).
What software are you trying to control? What doesn't work?

Reading the Korg manual, it seems like the inc/dec mode is some kind of hack to make the encoder work with push button controls. I've never come across this before, and the manual doesn't provide enough information for me to implement it, so you'll have to post more info if you want help with that specific mode.
Most MIDI controllers use sign magnitude or two's complement representation, most DAWs should support it. Have you tried these modes? What were the results?

Thank you very much for your patience, and sorry if I don't express myself in the best way. I am new at this. At this moment I am at work and I do not have all the elements, tomorrow I will send you all the data I can, with captures, codes, etc. so you can understand better. Apologies.

Hi, I start at the beginning. The project is a midi controller that replaces a lighting console called Comand Wing of the Ma Lighting brand. Mapping in the Ma on Pc software is easy as it lets me map all the buttons or faders at ease. (Image Proyecto1)

Currently I use my NanoKontrolStudio, through MidiOx and LoopMidi. Everything that is faders and buttons, I have everything solved, I only need the encoders. As there are many buttons and faders (I updated the project to 16 faders) I used the downloaded library of a “Notes And Volts” tutorial with the following code.

I have attached the code so you can see it better as it has 2 tabs of controller.h and controller.cpp.
the idea is to be able to add the encoders in this code.

I send the editor of the NanokontrolStudio to you to see how it is configured (image editor nanokontrolStudio) and I send you a capture of the signal sent by the encoder of the Nano (Image midiox in-out nanokontrolstudio), that is, the input to midiOx, I think it is more important since from there they are all configurations in the other software that are already resolved.

I hope that this time, you have a much more detailed description and it is easier to understand what I am needing. Once again, thank you very much for your help !!!

MIDI_Controller_v1-2CHMUX.zip (4.04 KB)

I added the inc/dec 1 mode to the Control Surface library: Add NEXT_ADDRESS relative CC mode · tttapa/Control-Surface@28ed279 · GitHub

I left the code I was using and went back to the surface control code. I replaced USBmidi with HairlessMIDI_Interface and select the midi cc mode KORG_KONTROL_INC_DEC_1 and it doesn’t work, is there something I’m missing? I leave capture of the hairless so that it sees what appears.
I still don’t understand what V_POT_1 is and no CC number appears?

#include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
HairlessMIDI_Interface midi;

// Instantiate a CCRotaryEncoder object
CCRotaryEncoder enc = {
  {2, 3},       // pins
  MCU::V_POT_1, // MIDI address (CC number + optional channel)
  1,            // optional multiplier if the control isn't fast enough
};

void setup() {
  // Select the correct relative MIDI CC mode.
  // Options:
  //   - TWOS_COMPLEMENT (default)
  //   - BINARY_OFFSET
  //   - SIGN_MAGNITUDE
  //   - NEXT_ADDRESS
  // Aliases:
  //   - REAPER_RELATIVE_1
  //   - REAPER_RELATIVE_2
  //   - REAPER_RELATIVE_3
  //   - TRACKTION_RELATIVE
  //   - MACKIE_CONTROL_RELATIVE
  //   - KORG_KONTROL_INC_DEC_1
  RelativeCCSender::setMode(relativeCCmode::KORG_KONTROL_INC_DEC_1);
  Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
  Control_Surface.loop(); // Update the Control Surface
}

haireeles error.JPG

That looks like a baud rate issue. Did you change Hairless' default baud rate?

Control Surface expects 115200 baud.

The exact same code works fine for me (tested with Hairless).

brilliant!!! the encoder was finally able to run. Now I have another challenge, in the code I was using I already had all the buttons and faders configured, now I have to assemble everything in its control surface code. I found the code for the faders with a multiplexer, but in the buttons I saw that there is an array made but it is not enough for me since I have many buttons to put (120 buttons) is it possible to make a code with multiplexers for buttons? I use the 16 channel 74hc4067 multiplexer.

You can use multiplexers with buttons in the exact same way as with the potentiometers:

[b][color=#d35400]CD74HC4067[/color][/b] [color=#000000]mux[/color] [color=#434f54]=[/color] [color=#000000]{[/color]
  [color=#000000]2[/color][color=#434f54],[/color]           [color=#434f54]// Digital input pin[/color]
  [color=#000000]{[/color][color=#000000]3[/color][color=#434f54],[/color] [color=#000000]4[/color][color=#434f54],[/color] [color=#000000]5[/color][color=#434f54],[/color] [color=#000000]6[/color][color=#000000]}[/color] [color=#434f54]// Address pins S0, S1, S2, S3[/color]
[color=#000000]}[/color][color=#000000];[/color]

[b][color=#d35400]CCButton[/color][/b] [color=#000000]buttons[/color][color=#000000][[/color][color=#000000]][/color] [color=#434f54]=[/color] [color=#000000]{[/color]
    [color=#000000]{[/color] [color=#000000]mux[/color][color=#434f54].[/color][color=#d35400]pin[/color][color=#000000]([/color][color=#000000]0[/color][color=#000000])[/color][color=#434f54],[/color] [color=#000000]{[/color][b][color=#d35400]MIDI_CC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Damper_Pedal[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_1[/color][color=#000000]}[/color] [color=#000000]}[/color][color=#434f54],[/color]
    [color=#000000]{[/color] [color=#000000]mux[/color][color=#434f54].[/color][color=#d35400]pin[/color][color=#000000]([/color][color=#000000]1[/color][color=#000000])[/color][color=#434f54],[/color] [color=#000000]{[/color][b][color=#d35400]MIDI_CC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Damper_Pedal[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_2[/color][color=#000000]}[/color] [color=#000000]}[/color][color=#434f54],[/color]
    [color=#000000]{[/color] [color=#000000]mux[/color][color=#434f54].[/color][color=#d35400]pin[/color][color=#000000]([/color][color=#000000]2[/color][color=#000000])[/color][color=#434f54],[/color] [color=#000000]{[/color][b][color=#d35400]MIDI_CC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Damper_Pedal[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_3[/color][color=#000000]}[/color] [color=#000000]}[/color][color=#434f54],[/color]
    [color=#000000]{[/color] [color=#000000]mux[/color][color=#434f54].[/color][color=#d35400]pin[/color][color=#000000]([/color][color=#000000]3[/color][color=#000000])[/color][color=#434f54],[/color] [color=#000000]{[/color][b][color=#d35400]MIDI_CC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Damper_Pedal[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_4[/color][color=#000000]}[/color] [color=#000000]}[/color][color=#434f54],[/color]
    [color=#95a5a6]/* ... */[/color]
    [color=#000000]{[/color] [color=#000000]mux[/color][color=#434f54].[/color][color=#d35400]pin[/color][color=#000000]([/color][color=#000000]15[/color][color=#000000])[/color][color=#434f54],[/color] [color=#000000]{[/color][b][color=#d35400]MIDI_CC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Damper_Pedal[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_16[/color][color=#000000]}[/color] [color=#000000]}[/color][color=#434f54],[/color]
[color=#000000]}[/color][color=#000000];[/color]