Go Down

Topic: Pots to midi with hairless (Read 2831 times) previous topic - next topic

debbio

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 ;)

Thank you so much


UKHeliBob

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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

debbio

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?

UKHeliBob

Quote
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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

debbio

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

UKHeliBob

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

Quote
how can I make the pots communicate with serial in a MIDI code?
Quote
I cannot understand how the grammar of these messages has to be..
Quote
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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

debbio

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..

UKHeliBob

Quote
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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

debbio

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 http://little-scale.blogspot.it/2011/08/simple-examples-of-sending-midi-data.html 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?

debbio

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

Code: [Select]
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
}
}

UKHeliBob

The page you linked to is very old and the Arduino code is out of data because
Code: [Select]
Serial.print(something, BYTE);
has been replaced by
Code: [Select]
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

debbio

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

Code: [Select]
#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
 
}

UKHeliBob

Quote
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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

debbio

Improving... but no results...

Code: [Select]
#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

UKHeliBob

How is the MIDI device connected to the Arduino ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up