Pots to midi with hairless

Hi all! I'm new in the forum and I'm a noob in Arduino but I'm here to learn the possible! ;))
I'm trying to create a MIDI simple controller with only two pots that have to control a program on my computer.. I want to launch hairless in background so that I can use the serial mode on Arduino.. But here are the problems: how can I make the pots communicate with serial in a MIDI code? I can only show one pot at time and I see the values on serial.. But how can traslate them in a MIDI language so that the program can read it?
I've an Arduino Due and I use archlinux :wink:

Thank you so much

Let's have some examples of values read from the pots and the MIDI messages to be output.

The values input from the pots will vary between 0 and 1023 so you could use different ranges to generate different messages if that is what you have in mind.

Yes it's clear but I cannot understand how the grammar of these messages has to be... What kind of MIDI message has to be sent for a specific pot's value?

but I cannot understand how the grammar of these messages has to be

That is a different question. A Google search for "midi message format" returns over 67,000 results of which is the first MIDI messages

Which ones do you want to send ?

Yes I'm using google too :wink:
But I can't found out how to set up the code in Arduino IDE..

I wish you would make your mind up what your problem is.

how can I make the pots communicate with serial in a MIDI code?

I cannot understand how the grammar of these messages has to be..

I can't found out how to set up the code in Arduino IDE..

Before you can write the Arduino program you must know what MIDI messages you want to send. Actually sending the messages should be easy. Did you come across http://www.arduino.cc/en/Tutorial/Midi in your search ?

I want to send some data from the pots to my serial port and in the sketch create something to let this value to be seen as midi values (or something that the program can see). I can't figure out what kind of code I've to create..

I want to send some data from the pots to my serial port and in the sketch create something to let this value to be seen as midi values (or something that the program can see). I can't figure out what kind of code I've to create

I have underlined the things you don't seem to know. As you can see it is difficult to provide help when there are so many unknowns.

What is it exactly you want to do ? Suppose the user changes the position of one of the pots attached to the Arduino, what should happen ? Should the volume or pitch of the note change, for instance ? If not, what should happen ?

You're right.. I don't know exactly what kind of message I've to send to be seen from the program on PC.. I think it's not important which one is.. maybe volume change? By reading here little-scale: Simple Examples of Sending MIDI Data from Arduino to Computer I've seen I've to send a CONTROL CHANGE (defined by B in a midi message), but the data can be volume or somithing different... Am I wrong?

This probably should work.. In the next days I'will try

byte val = 0;

void setup() {
Serial.begin(57600); // open serial port
}

void loop() {
for(int i = 0; i < 3; i ++) {
val = analogRead(i) / 8; // read value of a potentiometer
// (which is analog input 0 - 1)
// depending on which for() loop we are at

// let's send a control change message

Serial.print(0xB0 + i, BYTE); // MIDI control change; channel number
// the channel number depends on which for() loop we ar at
Serial.print(1, BYTE); // MIDI controller #1
Serial.print(val, BYTE); // MIDI controller value from the potentiometer
delay(1); // delay for a brief moment
}
}

The page you linked to is very old and the Arduino code is out of data because

Serial.print(something, BYTE);

has been replaced by

Serial.write(something);

since version 1.0.0 of the IDE but that is easy to change in the code.

If you want to control a MIDI device you absolutely must know what you want the MIDI device to do otherwise the exercise is pointless.

Improving my code.. but on SerialMonitor I can't see nothing...

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();
// Variables:
int cc = 0;
int AnalogValue = 0; // define variables for the controller data
int lastAnalogValue = 0; // define the "lastValue" variables

void setup() {
 
   
  //  launch MIDI
  MIDI.begin(4);
   Serial.begin(9600);
}

void loop() {
  
AnalogValue = analogRead(0);
  //  convert to a range from 0 to 127:
  cc = AnalogValue/8;
  // check if analog input has changed
  if (lastAnalogValue != cc) {
    MIDI.sendControlChange(0xB0,cc,1);
    // update lastAnalogValue variable
    lastAnalogValue = cc;
  }   //  endif
 
}

but on SerialMonitor I can't see nothing...

I am not surprised as you are not printing anything to Serial. What were you expecting to see ?

Improving... but no results...

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();
// Variables:
int cc = 0;
int AnalogValue = 0; // define variables for the controller data
int lastAnalogValue = 0; // define the "lastValue" variables

void setup() {
 
   
  //  launch MIDI
  MIDI.begin(4);
   Serial.begin(9600);
}

void loop() {
 
AnalogValue = analogRead(0);
  //  convert to a range from 0 to 127:
  cc = AnalogValue/8;
  // check if analog input has changed
  if (lastAnalogValue != cc) {
    MIDI.sendControlChange(0xB0,cc,1);
    // update lastAnalogValue variable
    lastAnalogValue = cc;
  }
 Serial.print("0xB0,");

 Serial.print(cc);

 Serial.print(",1,");
  
delay(20);
}   //  endif

How is the MIDI device connected to the Arduino ?

It's a potentiometer 10kohm.. The arduino Due is connected through Programming port to pc

PS: it was written in the first post

A potentiometer is not a MIDI device, whatever its value.

If I understand correctly you want to read the value of the potentiometer then, depending on the value, send different MIDI commands to the PC serial interface to be read an interpreted by the Hairless MIDI to serial bridge ? Is that right ?

What speed is the Hairless interface running at and what serial port is it using ?

Yes! Values are 6400 both serial and hairless

debbio:
Yes! Values are 6400 both serial and hairless

I am not sure what you mean by this. Can you please explain ?

Sorry.. The serial monitor is set to a speed rate of 9600 and so hairless on my PC.. The port used by hairless is /dev/ttyACM0